Skip to content

Instantly share code, notes, and snippets.

@maddox
Created May 3, 2011 00:38
Show Gist options
  • Save maddox/952633 to your computer and use it in GitHub Desktop.
Save maddox/952633 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'net/http'
require 'openssl'
default_params = {"api" => "v1", "appid" => "iphone1_1", "apiPolicy" => "app1_1", "apiKey" => "2wex6aeu6a8q9e49k7sfvufd6rhh0n", "locale" => "en_US", "timestamp" => Time.now.to_i}
param_array = []
default_params.each_pair{|key, value| param_array << "#{key}=#{URI.escape(value.to_s)}" }
uri = URI::HTTP.build(:scheme => 'https', :host => "app.imdb.com", :path => "/find", :query => param_array.join("&"))
# var unsignedUrl = apiUrl + $.param(params);
# params.sig = params.sig + '-' + Crypto.HMAC(Crypto.SHA1, unsignedUrl, apiKey);
#
# var signedUrl = apiUrl + $.param(params);
sig = "app1-#{OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), default_params["apiKey"], uri.to_s)}"
param_array << "sig=#{sig}"
puts param_array.inspect
uri = URI::HTTP.build(:scheme => 'https', :host => "app.imdb.com", :path => "/find", :query => param_array.join("&"))
puts uri.to_s
# puts `curl "#{uri.to_s}"`
@wmoore
Copy link

wmoore commented May 3, 2011

sig = "app1-#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), default_params["apiKey"], uri.to_s)}"

@maddox
Copy link
Author

maddox commented May 3, 2011 via email

@wmoore
Copy link

wmoore commented May 3, 2011

Looks like it was hex in the example posted, use hexdigest() to get the hex output?

@maddox
Copy link
Author

maddox commented May 3, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment