Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Forked from urlbox/urlbox.rb
Last active August 29, 2015 13:55

Revisions

  1. ch1ago revised this gist Jan 31, 2014. 1 changed file with 5 additions and 15 deletions.
    20 changes: 5 additions & 15 deletions urlbox.rb
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,15 @@
    # not necessary in Rails
    require 'cgi'
    require 'openssl'
    require 'open-uri'


    # OPTIONS :force, :full_page, :thumb_width, :width, :height
    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('&')
    options.merge!(url: url)
    query_string = options.select { |k,v| v }.to_query

    # puts query_string

  2. @urlbox-io urlbox-io revised this gist Feb 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion urlbox.rb
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ def urlbox(url, options={})

    token = OpenSSL::HMAC.hexdigest('sha1', urlbox_secret, query_string)

    "https://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/png/?#{query_string}"
    "https://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/png?#{query_string}"
    end

    puts urlbox "www.google.com"
  3. @urlbox-io urlbox-io revised this gist Feb 17, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion urlbox.rb
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ def urlbox(url, options={})

    token = OpenSSL::HMAC.hexdigest('sha1', urlbox_secret, query_string)

    "http://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/png/?#{query_string}"
    "https://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/png/?#{query_string}"
    end

    puts urlbox "www.google.com"
  4. @urlbox-io urlbox-io created this gist Feb 17, 2013.
    33 changes: 33 additions & 0 deletions urlbox.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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"