mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Merge branch 'aws_sig'
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
require "aws_paa/version"
|
||||
|
||||
require 'aws_paa/locales'
|
||||
require 'aws_paa/aws_request'
|
||||
require 'aws_paa/client'
|
||||
require 'aws_paa/request'
|
||||
require 'aws_paa/response'
|
||||
@@ -7,5 +9,4 @@ require 'aws_paa/response'
|
||||
module AwsPaa
|
||||
class Error < StandardError; end
|
||||
class NotImplemented < StandardError; end
|
||||
# Your code goes here...
|
||||
end
|
||||
|
||||
@@ -1,8 +1,33 @@
|
||||
require 'rest-client'
|
||||
require 'http'
|
||||
|
||||
module AwsPaa
|
||||
class Client
|
||||
def initialize(:access_key, :secret_key, :marketplace, partner_tag: nil, partner_type: 'Associates')
|
||||
attr_accessor :marketplace, :partner_tag
|
||||
attr_reader :partner_type, :access_key, :secret_key
|
||||
|
||||
def initialize(access_key:, secret_key:, marketplace:, partner_tag: nil, partner_type: 'Associates')
|
||||
raise ArgumentError unless MARKETPLACES.keys.include?(marketplace.to_sym)
|
||||
@access_key = access_key
|
||||
@secret_key = secret_key
|
||||
@marketplace = MARKETPLACES[marketplace.to_sym]
|
||||
@partner_tag = partner_tag
|
||||
@partner_type = partner_type
|
||||
end
|
||||
|
||||
def get_items(item_ids: )[]
|
||||
Request.new(client: self).get_items(item_ids: item_ids)
|
||||
end
|
||||
|
||||
def get_variations(asin: )
|
||||
Request.new(client: self).get_variations(asin: asin)
|
||||
end
|
||||
|
||||
def search_items(keywords: )
|
||||
Request.new(client: self).search_items(keywords: keywords)
|
||||
end
|
||||
|
||||
def get_browse_nodes
|
||||
Request.new(client: self).get_browse_nodes(keywords: keywords)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,43 +1,48 @@
|
||||
|
||||
require 'byebug'
|
||||
|
||||
module AwsPaa
|
||||
class Request
|
||||
def initialize()
|
||||
@request_example = {
|
||||
"Keywords": "Harry",
|
||||
"Marketplace": "www.amazon.com",
|
||||
"PartnerTag": "xyz-20",
|
||||
"PartnerType": "Associates",
|
||||
"Resources": ["Images.Primary.Small","ItemInfo.Title","Offers.Listings.Price"],
|
||||
"SearchIndex": "All"
|
||||
}
|
||||
include AwsRequest
|
||||
attr_accessor :client, :marketplace, :timestamp, :datestamp, :amzstamp, :resources, :service
|
||||
attr_accessor :headers, :payload
|
||||
|
||||
@headers = {
|
||||
'host' => 'webservices.amazon.com',
|
||||
'content-type' => 'application/json; charset=utf-8',
|
||||
'content-encoding' => 'amz-1.0',
|
||||
'x-amz-date' => '20160925T120000Z',
|
||||
'x-amz-target' => 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems',
|
||||
'Authorization' => 'AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=&5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924a6f2b5d7;'
|
||||
}
|
||||
def initialize(client:)
|
||||
@client = client
|
||||
@marketplace = client.marketplace
|
||||
@partner_tag = client.partner_tag
|
||||
@partner_type = 'Associates'
|
||||
|
||||
@marketplaces = [www.amazon.com]
|
||||
@resources = [
|
||||
"Images.Primary.Large",
|
||||
"ItemInfo.ContentInfo",
|
||||
"ItemInfo.ProductInfo",
|
||||
"ItemInfo.Title",
|
||||
"ItemInfo.ExternalIds",
|
||||
]
|
||||
end
|
||||
|
||||
def get_items(item_ids:, **options)
|
||||
item_ids = Array(item_ids)
|
||||
|
||||
payload = { ItemIds: item_ids, Resources: @resources }
|
||||
|
||||
do_request(op: :get_items, payload: payload)
|
||||
end
|
||||
|
||||
def get_variations(asin:)
|
||||
payload = { ASIN: asin, Resources: @resources }
|
||||
|
||||
do_request(op: :get_variations, payload: payload)
|
||||
end
|
||||
|
||||
def search_items(keywords: )
|
||||
payload = { Keywords: keywords, Resources: @resources }
|
||||
|
||||
do_request(op: :search_items, payload: payload)
|
||||
end
|
||||
|
||||
def get_browse_nodes
|
||||
raise NotImplemented
|
||||
end
|
||||
|
||||
def get_items
|
||||
raise NotImplemented
|
||||
end
|
||||
|
||||
def get_variations
|
||||
raise NotImplemented
|
||||
end
|
||||
|
||||
def search_items
|
||||
raise NotImplemented
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user