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:
30
Gemfile.lock
30
Gemfile.lock
@@ -2,27 +2,33 @@ PATH
|
|||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
aws_paa (0.1.0)
|
aws_paa (0.1.0)
|
||||||
rest-client (~> 2.0)
|
aws-sigv4 (~> 1)
|
||||||
|
http (~> 0.1)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
addressable (2.7.0)
|
||||||
|
public_suffix (>= 2.0.2, < 5.0)
|
||||||
|
awesome_print (1.8.0)
|
||||||
|
aws-eventstream (1.0.3)
|
||||||
|
aws-sigv4 (1.1.0)
|
||||||
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
||||||
|
byebug (11.0.1)
|
||||||
domain_name (0.5.20190701)
|
domain_name (0.5.20190701)
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
http-accept (1.7.0)
|
http (0.9.9)
|
||||||
|
addressable (~> 2.3)
|
||||||
|
http-cookie (~> 1.0)
|
||||||
|
http-form_data (~> 1.0.1)
|
||||||
|
http_parser.rb (~> 0.6.0)
|
||||||
http-cookie (1.0.3)
|
http-cookie (1.0.3)
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
mime-types (3.2.2)
|
http-form_data (1.0.3)
|
||||||
mime-types-data (~> 3.2015)
|
http_parser.rb (0.6.0)
|
||||||
mime-types-data (3.2019.0331)
|
|
||||||
minitest (5.11.3)
|
minitest (5.11.3)
|
||||||
netrc (0.11.0)
|
public_suffix (4.0.1)
|
||||||
rake (10.5.0)
|
rake (10.5.0)
|
||||||
rest-client (2.1.0)
|
|
||||||
http-accept (>= 1.7.0, < 2.0)
|
|
||||||
http-cookie (>= 1.0.2, < 2.0)
|
|
||||||
mime-types (>= 1.16, < 4.0)
|
|
||||||
netrc (~> 0.8)
|
|
||||||
unf (0.1.4)
|
unf (0.1.4)
|
||||||
unf_ext
|
unf_ext
|
||||||
unf_ext (0.0.7.6)
|
unf_ext (0.0.7.6)
|
||||||
@@ -31,8 +37,10 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
awesome_print
|
||||||
aws_paa!
|
aws_paa!
|
||||||
bundler (~> 2.0)
|
bundler (~> 2.0)
|
||||||
|
byebug
|
||||||
minitest (~> 5.0)
|
minitest (~> 5.0)
|
||||||
rake (~> 10.0)
|
rake (~> 10.0)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|||||||
spec.authors = ["Dan Milne"]
|
spec.authors = ["Dan Milne"]
|
||||||
spec.email = ["d@nmilne.com"]
|
spec.email = ["d@nmilne.com"]
|
||||||
|
|
||||||
spec.summary = %q{Ruby API for Amazon's Product Advertising API v5}
|
spec.summary = %q{Client library for Amazon's Product Advertising API v5}
|
||||||
spec.homepage = "https://github.com/dkam/aws_paa"
|
spec.homepage = "https://github.com/dkam/aws_paa"
|
||||||
spec.license = "MIT"
|
spec.license = "MIT"
|
||||||
|
|
||||||
@@ -30,6 +30,9 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_development_dependency "bundler", "~> 2.0"
|
spec.add_development_dependency "bundler", "~> 2.0"
|
||||||
spec.add_development_dependency "rake", "~> 10.0"
|
spec.add_development_dependency "rake", "~> 10.0"
|
||||||
spec.add_development_dependency "minitest", "~> 5.0"
|
spec.add_development_dependency "minitest", "~> 5.0"
|
||||||
|
spec.add_development_dependency "byebug"
|
||||||
|
spec.add_development_dependency "awesome_print"
|
||||||
|
|
||||||
spec.add_dependency 'httprb', '~> 0.1'
|
spec.add_dependency 'http', '~> 0.1'
|
||||||
|
spec.add_dependency 'aws-sigv4', '~> 1'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
require "aws_paa/version"
|
require "aws_paa/version"
|
||||||
|
|
||||||
|
require 'aws_paa/locales'
|
||||||
|
require 'aws_paa/aws_request'
|
||||||
require 'aws_paa/client'
|
require 'aws_paa/client'
|
||||||
require 'aws_paa/request'
|
require 'aws_paa/request'
|
||||||
require 'aws_paa/response'
|
require 'aws_paa/response'
|
||||||
@@ -7,5 +9,4 @@ require 'aws_paa/response'
|
|||||||
module AwsPaa
|
module AwsPaa
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
class NotImplemented < StandardError; end
|
class NotImplemented < StandardError; end
|
||||||
# Your code goes here...
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,33 @@
|
|||||||
require 'rest-client'
|
require 'http'
|
||||||
|
|
||||||
module AwsPaa
|
module AwsPaa
|
||||||
class Client
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,43 +1,48 @@
|
|||||||
|
require 'byebug'
|
||||||
|
|
||||||
module AwsPaa
|
module AwsPaa
|
||||||
class Request
|
class Request
|
||||||
def initialize()
|
include AwsRequest
|
||||||
@request_example = {
|
attr_accessor :client, :marketplace, :timestamp, :datestamp, :amzstamp, :resources, :service
|
||||||
"Keywords": "Harry",
|
attr_accessor :headers, :payload
|
||||||
"Marketplace": "www.amazon.com",
|
|
||||||
"PartnerTag": "xyz-20",
|
|
||||||
"PartnerType": "Associates",
|
|
||||||
"Resources": ["Images.Primary.Small","ItemInfo.Title","Offers.Listings.Price"],
|
|
||||||
"SearchIndex": "All"
|
|
||||||
}
|
|
||||||
|
|
||||||
@headers = {
|
def initialize(client:)
|
||||||
'host' => 'webservices.amazon.com',
|
@client = client
|
||||||
'content-type' => 'application/json; charset=utf-8',
|
@marketplace = client.marketplace
|
||||||
'content-encoding' => 'amz-1.0',
|
@partner_tag = client.partner_tag
|
||||||
'x-amz-date' => '20160925T120000Z',
|
@partner_type = 'Associates'
|
||||||
'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;'
|
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
end
|
||||||
|
|
||||||
def get_browse_nodes
|
def get_browse_nodes
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_items
|
|
||||||
raise NotImplemented
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_variations
|
|
||||||
raise NotImplemented
|
|
||||||
end
|
|
||||||
|
|
||||||
def search_items
|
|
||||||
raise NotImplemented
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
||||||
require "aws_paa"
|
require "aws_paa"
|
||||||
|
require 'byebug'
|
||||||
require "minitest/autorun"
|
require "minitest/autorun"
|
||||||
|
|||||||
Reference in New Issue
Block a user