Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Forked from urlbox/urlbox.rb
Last active August 29, 2015 13:55
Show Gist options
  • Save ch1ago/8737184 to your computer and use it in GitHub Desktop.
Save ch1ago/8737184 to your computer and use it in GitHub Desktop.
require 'cgi'
require 'openssl'
require 'open-uri'
def urlbox(url, options={})
urlbox_apikey = 'xxx-xxx'
urlbox_secret = 'xxx-xxx'
query = {
:url => url,
:force => options[:force],
:full_page => options[:full_page],
:thumb_width => options[:thumb_width],
:width => options[:width],
:height => options[:height],
}
query_string = query.
sort_by {|s| s[0].to_s }.
select {|s| s[1] }.
map {|s| s.map {|v| CGI::escape(v.to_s) }.join('=') }.
join('&')
# puts query_string
puts URI::encode(query_string)
token = OpenSSL::HMAC.hexdigest('sha1', urlbox_secret, query_string)
"http://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/png/?#{query_string}"
end
puts urlbox "www.google.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment