class Vacuum::Operation
An Amazon Product Advertising API operation
Attributes
locale[R]
@!visibility private
name[R]
@!visibility private
params[R]
@!visibility private
Public Class Methods
new(name, params:, locale:)
click to toggle source
Creates a new operation
@param [String] name @param [Hash] params @param [Locale] locale
# File lib/vacuum/operation.rb, line 18 def initialize(name, params:, locale:) @name = name @params = params @locale = locale end
Public Instance Methods
body()
click to toggle source
@return [String]
# File lib/vacuum/operation.rb, line 35 def body @body ||= build_body end
headers()
click to toggle source
@return [Hash]
# File lib/vacuum/operation.rb, line 25 def headers signature.headers.merge( 'x-amz-target' => "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.#{name}", 'content-encoding' => 'amz-1.0', 'content-type' => 'application/json; charset=utf-8' ) end
url()
click to toggle source
@return [String]
# File lib/vacuum/operation.rb, line 40 def url @url ||= build_url end
Private Instance Methods
build_body()
click to toggle source
# File lib/vacuum/operation.rb, line 46 def build_body hsh = { 'PartnerTag' => locale.partner_tag, 'PartnerType' => locale.partner_type } params.each do |key, val| key = key.to_s.split('_') .map { |word| word == 'asin' ? 'ASIN' : word.capitalize }.join hsh[key] = val end JSON.generate(hsh) end
build_url()
click to toggle source
# File lib/vacuum/operation.rb, line 59 def build_url "https://#{locale.host}/paapi5/#{name.downcase}" end
signature()
click to toggle source
# File lib/vacuum/operation.rb, line 63 def signature signer.sign_request(http_method: 'POST', url: url, body: body) end
signer()
click to toggle source
# File lib/vacuum/operation.rb, line 67 def signer Aws::Sigv4::Signer.new(service: 'ProductAdvertisingAPI', region: locale.region, access_key_id: locale.access_key, secret_access_key: locale.secret_key, http_method: 'POST', endpoint: locale.host) end