module TopDMC::Resources::Utils

Public Instance Methods

hmac_sha1_signature(key, signature_string) click to toggle source
# File lib/topdmc/resources/utils.rb, line 8
def hmac_sha1_signature(key, signature_string)
  digest = OpenSSL::Digest::Digest.new('sha1')
  hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
  Base64.encode64(hmac).chomp.gsub(/\n/, '')
end
nonce() click to toggle source
# File lib/topdmc/resources/utils.rb, line 14
def nonce
  rand(10 ** 30).to_s.rjust(30, '0')
end
sign(method, path, params, key) click to toggle source
# File lib/topdmc/resources/utils.rb, line 18
def sign(method, path, params, key)

  normalized = params.map { |key, value|
    [key, URI.encode_www_form_component(value.to_s)]
  }.sort.map { |item| item.join('=') }

  sign_str = [method,
              URI.encode_www_form_component(path),
              URI.encode_www_form_component(normalized.join('&'))
  ].join('&')

  #return sign string
  hmac_sha1_signature(key, sign_str)
end