Created
April 9, 2012 20:37
-
-
Save rtekie/2346434 to your computer and use it in GitHub Desktop.
LoyaltyPlus API call sample
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 'digest' # Not needed if you are using rails. | |
| require 'cgi' # Not needed if you are using rails. | |
| secret_key = "SECRET_KEY" # Your secret | |
| params = { :email => "CUSTOMER_EMAIL", :uuid => "ACCOUNT_ID" } # Your api call parameters | |
| string_to_hash = params.sort{|x,y| x[0].to_s <=> y[0].to_s}.reduce(secret_key){|x,y| x + y.to_s} # Concatenate in alphabetical order of parameter name, prepend with secret_key | |
| params[:sig] = Digest::MD5.hexdigest(string_to_hash) # Compute hash | |
| api_url = "http://loyalty.500friends.com/api/enroll.gif?" + params.map{|x,y| "#{x}=#{CGI::escape(y)}"}.join("&") # Construct the url. | |
| api_url # should be the url of the api call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment