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
|
||||
- Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[](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
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
require 'http'
|
||||
require 'net/http'
|
||||
require 'aws-sigv4'
|
||||
require 'byebug'
|
||||
|
||||
module Paapi
|
||||
class Client
|
||||
|
||||
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,
|
||||
secret_key: Paapi.secret_key,
|
||||
@@ -24,6 +25,14 @@ module Paapi
|
||||
@condition = condition
|
||||
self.market = market
|
||||
@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
|
||||
|
||||
def market=(a_market)
|
||||
@@ -44,7 +53,7 @@ module Paapi
|
||||
request(op: :get_variations, payload: payload)
|
||||
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 )
|
||||
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
||||
|
||||
@@ -63,8 +72,9 @@ module Paapi
|
||||
private
|
||||
|
||||
def request(op:, payload:)
|
||||
byebug
|
||||
raise ArguemntError unless Paapi::OPERATIONS.keys.include?(op)
|
||||
|
||||
|
||||
operation = OPERATIONS[op]
|
||||
|
||||
headers = {
|
||||
@@ -99,10 +109,24 @@ module Paapi
|
||||
headers['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
|
||||
headers['Authorization'] = signature.headers['authorization']
|
||||
headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
|
||||
unless @http.nil?
|
||||
Response.new( @http.with_headers(headers).post(endpoint, json: payload ) )
|
||||
else
|
||||
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
|
||||
end
|
||||
|
||||
Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
|
||||
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
|
||||
|
||||
@@ -128,22 +128,22 @@ module Paapi
|
||||
|
||||
def height
|
||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
|
||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
end
|
||||
|
||||
def length
|
||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
|
||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
end
|
||||
|
||||
def width
|
||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
|
||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
end
|
||||
|
||||
def weight
|
||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
|
||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||
end
|
||||
|
||||
def kindle?
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Paapi
|
||||
VERSION = '0.1.2'
|
||||
VERSION = '0.1.4'
|
||||
end
|
||||
|
||||
@@ -31,6 +31,5 @@ Gem::Specification.new do |spec|
|
||||
spec.add_development_dependency 'byebug', '~> 11'
|
||||
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
||||
|
||||
spec.add_dependency 'http', '~> 4'
|
||||
spec.add_dependency 'aws-sigv4', '~> 1'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user