Class: MWS::API::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-mws/api/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

Returns a new instance of Query.


6
7
8
9
10
11
12
13
# File 'lib/ruby-mws/api/query.rb', line 6

def initialize(params)
  @params = params
  params[:lists].each do |field,label|
    [params.delete(field)].compact.flatten.each_with_index do |item,i|
      params["#{label}.#{i+1}"] = item
    end
  end unless params[:lists].nil?
end

Instance Method Details

#canonicalObject


15
16
17
# File 'lib/ruby-mws/api/query.rb', line 15

def canonical
  [@params[:verb].to_s.upcase, @params[:host], @params[:uri], build_sorted_query].join("\n")
end

#request_uriObject


25
26
27
# File 'lib/ruby-mws/api/query.rb', line 25

def request_uri
  "https://" << @params[:host] << @params[:uri] << '?' << build_sorted_query(signature)
end

#signatureObject


19
20
21
22
23
# File 'lib/ruby-mws/api/query.rb', line 19

def signature
  digest = OpenSSL::Digest::Digest.new('sha256')
  key = @params[:secret_access_key]
  Base64.encode64(OpenSSL::HMAC.digest(digest, key, canonical)).chomp
end