Signing URL – Ruby
In order to access the service, you’ll need first to “sign” your URLs.
Variables
| Name | Type | Summary |
|---|---|---|
| url_domain | string (required) | URL of the service (ex: http://uk.shopping.yahooapis.com) |
| url_path | string (required) | Path and query for the service (ex: /V2/search?query=ipod) |
| partner | string (required) | Affiliate Id |
| key | string (required) | Affiliate secret key |
Please note that your query must be encoded if you use characters with accents.
Sample Class
def url_signer (url_domain, url_path, partner, key)
url_sig = "hash"
# replace " " by "+"
url_path.gsub(' ','+')
# format URL
url = url_path + "×tamp=" + Time.now.to_i.to_s + "&aid=" + partner
# URL needed to create the tokken
s = url + key;
md5_str_tokken = Digest::MD5.digest(s)
md5_byte_tokken = md5_str_tokken.unpack('H*')
base64_tokken = Base64.encode64(md5_str_tokken);
base64_tokken.gsub!('+','.')
base64_tokken.gsub!('/','_')
base64_tokken.gsub!('=','-')
url = url_domain + url + "&hash=" + base64_tokken
end
Simply call the function to generate the appropriate URL:
url_signer("http://uk.shopping.yahooapis.com", "/V2/search?query=ipod", "123", "PartnerKey")