Skip to content

Instantly share code, notes, and snippets.

@rtekie
Created April 9, 2012 20:37
Show Gist options
  • Select an option

  • Save rtekie/2346434 to your computer and use it in GitHub Desktop.

Select an option

Save rtekie/2346434 to your computer and use it in GitHub Desktop.
LoyaltyPlus API call sample
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