Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageruby
themeEclipse
titleRuby
require 'digest/md5'
require "erb"

include ERB::Util

token = "5436gdfdhgfh7b66bgfg4436c28"
puts "Token:\n #{token} \n\n"

secret = "fsdfg43321dsafg"
puts "Secret:\n #{secret} \n\n"

request = "http://site.meridix.se/api/customer/listcustomers"
puts "Request:\n #{request} \n\n"

nonce = Random.new.rand(100000...999999).to_s
puts "Nonce:\n #{nonce} \n\n"

timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S");
puts "Timestamp:\n #{timestamp} \n\n"

parameters = 
[
"auth_nonce=" + nonce,
"auth_timestamp=" + timestamp,
"auth_token=" + token
]
parameters = parameters.sort

requestEncoded = url_encode(request);
puts "RequestEncoded:\n #{requestEncoded} \n\n"

parametersConcated = parameters.join("&")
puts "ParametersConcated:\n #{parametersConcated} \n\n"

parametersConcatedEncoded = url_encode(parametersConcated)
puts "ParametersConcatedEncoded:\n #{parametersConcatedEncoded} \n\n"



# IMPORTANT - The GET&-prefix must be change to POST& etc. when using different HTTP Verbs than GET.
verbRequestQuery = "GET&" + requestEncoded + "&" + parametersConcatedEncoded + "&" + secret;
puts "VerbRequestQuery:\n #{verbRequestQuery} \n\n"

signature = Digest::MD5.hexdigest(verbRequestQuery)
puts "Signature:\n #{signature} \n\n"

signedRequest = request + "?" + parametersConcated + "&auth_signature=" + signature
puts "SignedRequest:\n #{signedRequest} \n\n"