mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Compare commits
14 Commits
add_condit
...
bugfix1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
761df379cf | ||
|
|
6105ea621c | ||
|
|
d09be5f131 | ||
|
|
7aebd186a5 | ||
|
|
e04d258b07 | ||
|
|
b66dda8d79 | ||
|
|
02057fb0d0 | ||
|
|
8c4f4337a3 | ||
|
|
ba6a52ce9c | ||
|
|
747e76fe8f | ||
|
|
6115f72119 | ||
|
|
e47add0064 | ||
|
|
a86acb1ef9 | ||
|
|
706a9fb377 |
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.1.3
|
||||||
|
- Dropped the HTTP gem and moved to Ruby's Net::HTTP
|
||||||
|
- Merged a branch which adds the Condtion parameter.
|
||||||
|
|
||||||
## 0.1.2
|
## 0.1.2
|
||||||
- Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
|
- Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/dkam/paapi)
|
[](https://travis-ci.org/dkam/paapi)
|
||||||
|
|
||||||
If this gem doesn't meet your needs, try the [Vacumm gem](https://github.com/hakanensari/vacuum).
|
If this gem doesn't meet your needs, try the [Vacuum gem](https://github.com/hakanensari/vacuum).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
require 'http'
|
require 'net/http'
|
||||||
require 'aws-sigv4'
|
require 'aws-sigv4'
|
||||||
|
require 'byebug'
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Client
|
class Client
|
||||||
|
|
||||||
attr_accessor :partner_tag, :marketplace, :resources, :condition
|
attr_accessor :partner_tag, :marketplace, :resources, :condition
|
||||||
attr_reader :partner_type, :access_key, :secret_key, :market
|
attr_reader :partner_type, :access_key, :secret_key, :market, :http
|
||||||
|
|
||||||
def initialize(access_key: Paapi.access_key,
|
def initialize(access_key: Paapi.access_key,
|
||||||
secret_key: Paapi.secret_key,
|
secret_key: Paapi.secret_key,
|
||||||
@@ -24,6 +25,14 @@ module Paapi
|
|||||||
@condition = condition
|
@condition = condition
|
||||||
self.market = market
|
self.market = market
|
||||||
@partner_tag = partner_tag if !partner_tag.nil?
|
@partner_tag = partner_tag if !partner_tag.nil?
|
||||||
|
|
||||||
|
if defined?(HTTPX)
|
||||||
|
@http = HTTPX.plugin(:persistent)
|
||||||
|
elsif defined?(HTTP)
|
||||||
|
@http = HTTP::Client.new
|
||||||
|
else
|
||||||
|
@http = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def market=(a_market)
|
def market=(a_market)
|
||||||
@@ -44,7 +53,7 @@ module Paapi
|
|||||||
request(op: :get_variations, payload: payload)
|
request(op: :get_variations, payload: payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Currently we assume Keywords, but we need one of the follow: [Keywords Actor Artist Author Brand Title ]
|
# TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ]
|
||||||
def search_items(keywords: nil, **options )
|
def search_items(keywords: nil, **options )
|
||||||
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
||||||
|
|
||||||
@@ -63,6 +72,7 @@ module Paapi
|
|||||||
private
|
private
|
||||||
|
|
||||||
def request(op:, payload:)
|
def request(op:, payload:)
|
||||||
|
byebug
|
||||||
raise ArguemntError unless Paapi::OPERATIONS.keys.include?(op)
|
raise ArguemntError unless Paapi::OPERATIONS.keys.include?(op)
|
||||||
|
|
||||||
operation = OPERATIONS[op]
|
operation = OPERATIONS[op]
|
||||||
@@ -100,9 +110,23 @@ module Paapi
|
|||||||
headers['Authorization'] = signature.headers['authorization']
|
headers['Authorization'] = signature.headers['authorization']
|
||||||
headers['Content-Type'] = 'application/json; charset=utf-8'
|
headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
|
unless @http.nil?
|
||||||
end
|
Response.new( @http.with_headers(headers).post(endpoint, json: payload ) )
|
||||||
|
else
|
||||||
|
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.post(url:, body:, headers:)
|
||||||
|
uri = URI.parse(url)
|
||||||
|
request = Net::HTTP::Post.new(uri)
|
||||||
|
request.content_type = 'application/json; charset=UTF-8'
|
||||||
|
headers.each { |k, v| request[k] = v }
|
||||||
|
request.body = body.to_json
|
||||||
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -128,22 +128,22 @@ module Paapi
|
|||||||
|
|
||||||
def height
|
def height
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def length
|
def length
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def width
|
def width
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def weight
|
def weight
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def kindle?
|
def kindle?
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Paapi
|
module Paapi
|
||||||
VERSION = '0.1.2'
|
VERSION = '0.1.4'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_development_dependency 'byebug', '~> 11'
|
spec.add_development_dependency 'byebug', '~> 11'
|
||||||
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
||||||
|
|
||||||
spec.add_dependency 'http', '~> 4'
|
|
||||||
spec.add_dependency 'aws-sigv4', '~> 1'
|
spec.add_dependency 'aws-sigv4', '~> 1'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user