mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 07:04:53 +00:00
Merge request into client
This commit is contained in:
@@ -37,9 +37,9 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
awesome_print
|
awesome_print (~> 1.8)
|
||||||
bundler (~> 2.0)
|
bundler (~> 2.0)
|
||||||
byebug
|
byebug (~> 11)
|
||||||
minitest (~> 5.0)
|
minitest (~> 5.0)
|
||||||
paapi!
|
paapi!
|
||||||
rake (~> 10.0)
|
rake (~> 10.0)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ require "paapi/version"
|
|||||||
require 'paapi/locales'
|
require 'paapi/locales'
|
||||||
require 'paapi/aws_request'
|
require 'paapi/aws_request'
|
||||||
require 'paapi/client'
|
require 'paapi/client'
|
||||||
require 'paapi/request'
|
|
||||||
require 'paapi/response'
|
require 'paapi/response'
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
|
|||||||
@@ -2,32 +2,67 @@ require 'http'
|
|||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Client
|
class Client
|
||||||
|
include AwsRequest
|
||||||
attr_accessor :marketplace, :partner_tag
|
attr_accessor :marketplace, :partner_tag
|
||||||
attr_reader :partner_type, :access_key, :secret_key
|
attr_reader :partner_type, :access_key, :secret_key
|
||||||
|
|
||||||
def initialize(access_key:, secret_key:, marketplace:, partner_tag: nil, partner_type: 'Associates')
|
def initialize(access_key:, secret_key:, marketplace:, partner_tag: nil, resources: nil, partner_type: 'Associates')
|
||||||
raise ArgumentError unless MARKETPLACES.keys.include?(marketplace.to_sym)
|
raise ArgumentError unless MARKETPLACES.keys.include?(marketplace.to_sym)
|
||||||
@access_key = access_key
|
@access_key = access_key
|
||||||
@secret_key = secret_key
|
@secret_key = secret_key
|
||||||
@marketplace = MARKETPLACES[marketplace.to_sym]
|
@marketplace = MARKETPLACES[marketplace.to_sym]
|
||||||
@partner_tag = partner_tag
|
@partner_tag = partner_tag
|
||||||
@partner_type = partner_type
|
@partner_type = partner_type
|
||||||
|
@resources = resources || [
|
||||||
|
"Images.Primary.Large",
|
||||||
|
"ItemInfo.ContentInfo",
|
||||||
|
"ItemInfo.ProductInfo",
|
||||||
|
"ItemInfo.Title",
|
||||||
|
"ItemInfo.ExternalIds",
|
||||||
|
"Offers.Listings.Availability.Message",
|
||||||
|
"Offers.Listings.Condition",
|
||||||
|
"Offers.Listings.Condition.SubCondition",
|
||||||
|
"Offers.Listings.DeliveryInfo.IsAmazonFulfilled",
|
||||||
|
"Offers.Listings.DeliveryInfo.IsFreeShippingEligible",
|
||||||
|
"Offers.Listings.DeliveryInfo.IsPrimeEligible",
|
||||||
|
"Offers.Listings.MerchantInfo",
|
||||||
|
"Offers.Listings.Price",
|
||||||
|
"Offers.Listings.SavingBasis"
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_items(item_ids:, **options)
|
def get_items(item_ids:, **options)
|
||||||
Response.new(Request.new(client: self).get_items(item_ids: item_ids, **options))
|
item_ids = Array(item_ids)
|
||||||
|
|
||||||
|
payload = { ItemIds: item_ids, Resources: @resources }
|
||||||
|
|
||||||
|
res = do_request(op: :get_items, payload: payload)
|
||||||
|
|
||||||
|
Response.new(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_variations(asin:, **options )
|
def get_variations(asin:, **options )
|
||||||
Response.new(Request.new(client: self).get_variations(asin: asin, **options))
|
payload = { ASIN: asin, Resources: @resources }
|
||||||
|
|
||||||
|
res = do_request(op: :get_variations, payload: payload)
|
||||||
|
Response.new(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_items(keywords:, **options )
|
def search_items(keywords:, **options )
|
||||||
Response.new(Request.new(client: self).search_items(keywords: keywords, **options))
|
search_index = 'All'
|
||||||
|
|
||||||
|
# %i[Keywords Actor Artist Author Brand Title ]
|
||||||
|
|
||||||
|
payload = { Keywords: keywords, Resources: @resources, ItemCount: 10, ItemPage: 1, SearchIndex: search_index }.merge(options)
|
||||||
|
|
||||||
|
res = do_request(op: :search_items, payload: payload)
|
||||||
|
|
||||||
|
Response.new(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_browse_nodes(keywords:, **options)
|
def get_browse_nodes(keywords:, **options)
|
||||||
Response.new(Request.new(client: self).get_browse_nodes(keywords: keywords, **options))
|
raise NotImplemented
|
||||||
|
#Response.new(Request.new(client: self).get_browse_nodes(keywords: keywords, **options))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
require 'byebug'
|
|
||||||
|
|
||||||
module Paapi
|
|
||||||
class Request
|
|
||||||
include AwsRequest
|
|
||||||
attr_accessor :client, :marketplace, :resources, :payload, :service, :partner_type
|
|
||||||
attr_reader :partner_tag
|
|
||||||
|
|
||||||
def initialize(client:, resources: nil)
|
|
||||||
@client = client
|
|
||||||
@marketplace = client.marketplace
|
|
||||||
@partner_tag = client.partner_tag
|
|
||||||
@partner_type = 'Associates'
|
|
||||||
|
|
||||||
@resources = resources || [
|
|
||||||
"Images.Primary.Large",
|
|
||||||
"ItemInfo.ContentInfo",
|
|
||||||
"ItemInfo.ProductInfo",
|
|
||||||
"ItemInfo.Title",
|
|
||||||
"ItemInfo.ExternalIds",
|
|
||||||
"Offers.Listings.Availability.Message",
|
|
||||||
"Offers.Listings.Condition",
|
|
||||||
"Offers.Listings.Condition.SubCondition",
|
|
||||||
"Offers.Listings.DeliveryInfo.IsAmazonFulfilled",
|
|
||||||
"Offers.Listings.DeliveryInfo.IsFreeShippingEligible",
|
|
||||||
"Offers.Listings.DeliveryInfo.IsPrimeEligible",
|
|
||||||
"Offers.Listings.MerchantInfo",
|
|
||||||
"Offers.Listings.Price",
|
|
||||||
"Offers.Listings.SavingBasis"
|
|
||||||
]
|
|
||||||
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:, **options )
|
|
||||||
search_index = 'All'
|
|
||||||
|
|
||||||
# %i[Keywords Actor Artist Author Brand Title ]
|
|
||||||
|
|
||||||
payload = { Keywords: keywords, Resources: @resources, ItemCount: 10, ItemPage: 1, SearchIndex: search_index }.merge(options)
|
|
||||||
|
|
||||||
do_request(op: :search_items, payload: payload)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_browse_nodes
|
|
||||||
raise NotImplemented
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user