Skip to content

Instantly share code, notes, and snippets.

@danvine
Last active December 23, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danvine/6660484 to your computer and use it in GitHub Desktop.
Save danvine/6660484 to your computer and use it in GitHub Desktop.
require 'cgi' unless defined?(CGI)
require 'digest' unless defined?(Digest)
class Url2png
attr_reader :apikey, :secret, :query_string, :token
def initialize options
@apikey = ENV['URL2PNG_APIKEY']
@secret = ENV['URL2PNG_SECRET']
@query_string = options.sort.map { |k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join("&")
@token = Digest::MD5.hexdigest(query_string + secret)
end
def url
"http://api.url2png.com/v6/#{apikey}/#{token}/png/?#{query_string}"
end
end
options = {
url: "http://codepen.io/anon/pen/pJRvvV",
say_cheese: true,
viewport: "1024x1024"
}
puts Url2png.new(options).url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment