-
-
Save mikegrassotti/2695710 to your computer and use it in GitHub Desktop.
v6 Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' unless defined?(Digest) | |
# Just in case this isn't a rails app | |
class Hash | |
def to_query | |
require 'cgi' unless defined?(CGI) && defined?(CGI::escape) | |
map {|k,v| [k,v].map {|p| CGI::escape(p.to_s) }.join('=') }.join('&') | |
end | |
end | |
def url2png_v6 url, options={} | |
# Get your apikey from http://url2png.com/plans | |
url2png_apikey = ENV['URL2PNG_API_KEY'] | |
url2png_secret = ENV['URL2PNG_PRIVATE_KEY'] | |
query_string = { | |
url: url, | |
force: options[:force] || false, # [false,always,timestamp] Default: false | |
fullpage: options[:fullpage] || false, # [true,false] Default: false | |
thumbnail_max_width: options[:thumbnail_max_width]|| false, # scaled image width in pixels; Default no-scaling. | |
viewport: options[:viewport] || "1280x1024" # Max 5000x5000; Default 1280x1024 | |
}.to_query | |
token = Digest::MD5.hexdigest(query_string + url2png_secret) | |
"http://beta.url2png.com/v6/#{url2png_apikey}/#{token}/png/?#{query_string}" | |
end | |
# usage | |
puts url2png_v6 "http://www.google.com" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment