module HashkeyGenerator
Public Instance Methods
concat_params(params)
click to toggle source
create a string representation of passed hash, which can be encoded in a URL
# File lib/hashkey_generator.rb, line 5 def concat_params(params) result = "" return result if params.empty? params.map{|key,val| result += "#{key}=#{val}&" unless val.nil? or val == ''} result.chomp!('&') end
generate_hashkey_for(params, api_key)
click to toggle source
Generate a hashkey using SHA1 for a provided API key List of parameters *params : a list of parameters as a hash, that needs to be used for hashkey generation *api_key: a unique API key provided to you for authenticating the API calls
# File lib/hashkey_generator.rb, line 21 def generate_hashkey_for(params, api_key) sorted_params = sort_params(params) params_string = concat_params(sorted_params) Digest::SHA1.hexdigest "#{params_string}&#{api_key}" end
sort_params(params)
click to toggle source
sort the parameters in alphabetical order of keys
# File lib/hashkey_generator.rb, line 13 def sort_params(params) Hash[params.sort] end