Created
January 3, 2010 17:29
-
-
Save dmix/268050 to your computer and use it in GitHub Desktop.
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
def search_food(query) | |
base = "http://platform.fatsecret.com/rest/server.api" | |
key = "339df5xx11e42b3e7x3x1b21e7d12" | |
#added the extra & at the end of the secret | |
secret = "215ba9f90c6e4f41b23a149f322d2s7b1&" | |
timestamp = Time.now.to_i | |
signature_method="HMAC-SHA1" | |
nonce = rand(100) | |
method = "food.search" | |
#normalizing the required parameters | |
required_parameters = Addressable::URI.new | |
required_parameters.query_values = {:oauth_consumer_key => key, :oauth_nonce => nonce.to_s, :oauth_signature_method => signature_method, :oauth_timestamp => timestamp.to_s, :oauth_version => "1.0"} | |
to_encrypt = "POST&#{CGI.escape(base)}&#{CGI::escape(required_parameters.query)}" | |
oauth_signature = Base64.encode64(HMAC::SHA1.digest(to_encrypt, secret)).strip | |
final_url = base + "?method=" + method + "&oauth_signature=" + CGI.escape(oauth_signature) + "&" + required_parameters.query + "&search_expression=" + query.to_s | |
url = open(final_url).read | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment