Created
May 3, 2011 00:38
-
-
Save maddox/952633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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}"` |
What is this? Please add to the thread.
…On May 2, 2011, at 8:42 PM, ***@***.*** wrote:
sig = "app1-#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), default_params["apiKey"], uri.to_s)}"
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/952633
Looks like it was hex in the example posted, use hexdigest() to get the hex output?
Ahh, great. See if that works in my example. Uncomment the curl call and you should get back the correct response. I'm not in a position to try it now. And please take all of this to the issues thread.
Thanks!
…On May 2, 2011, at 8:49 PM, ***@***.*** wrote:
Looks like it was hex in the example posted, use hexdigest() to get the hex output?
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/952633
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sig = "app1-#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), default_params["apiKey"], uri.to_s)}"