Class: Panda::ApiAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/api_authentication.rb

Class Method Summary collapse

Class Method Details

.generate_signature(verb, request_uri, host, secret_key, params_given = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/panda/api_authentication.rb', line 10

def self.generate_signature(verb, request_uri, host, secret_key, params_given={})
  # Ensure all param keys are strings
  params = {}; params_given.each {|k,v| params[k.to_s] = v }

  query_string = canonical_querystring(params)

  string_to_sign = verb.to_s.upcase + "\n" + 
      host.downcase + "\n" +
      request_uri + "\n" +
      query_string

  hmac = HMAC::SHA256.new( secret_key )
  hmac.update( string_to_sign )
  # chomp is important!  the base64 encoded version will have a newline at the end
  Base64.encode64(hmac.digest).chomp
end