mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Compare commits
8 Commits
bugfix1
...
persistent
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09e635fc6f | ||
|
|
9297799555 | ||
|
|
5d8fd3ffff | ||
|
|
bba10e75fa | ||
|
|
72b413a40e | ||
|
|
ae3577a9fc | ||
|
|
11694b567e | ||
|
|
a6a5cf45c3 |
@@ -1,3 +1,6 @@
|
|||||||
|
## 0.1.7 ( Unreleased )
|
||||||
|
- Add gem 'net-http-persistent' for connection persistance
|
||||||
|
- Remove the code which would use other http clients if available
|
||||||
## 0.1.3
|
## 0.1.3
|
||||||
- Dropped the HTTP gem and moved to Ruby's Net::HTTP
|
- Dropped the HTTP gem and moved to Ruby's Net::HTTP
|
||||||
- Merged a branch which adds the Condtion parameter.
|
- Merged a branch which adds the Condtion parameter.
|
||||||
|
|||||||
@@ -87,6 +87,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|||||||
|
|
||||||
If you create a file `config.rb`, it will be loaded by `bin/console`, allowing you to configure keys and markets.
|
If you create a file `config.rb`, it will be loaded by `bin/console`, allowing you to configure keys and markets.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Paapi.configure do |config|
|
||||||
|
config.access_key = 'access_key'
|
||||||
|
config.secret_key = 'secret_key'
|
||||||
|
config.partner_market = {au: 'au_tag', us: 'us_tag', uk: 'uk_tag', ca: 'ca_tag_'}
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
require 'paapi'
|
#require 'paapi'
|
||||||
|
require './lib/paapi.rb'
|
||||||
|
|
||||||
# You can add fixtures and/or initialization code here to make experimenting
|
# You can add fixtures and/or initialization code here to make experimenting
|
||||||
# with your gem easier. You can also use a different console, if you like.
|
# with your gem easier. You can also use a different console, if you like.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module Paapi
|
|||||||
|
|
||||||
MARKETPLACES = {
|
MARKETPLACES = {
|
||||||
au: Locale.new(:au, 'Australia', 'webservices.amazon.com.au', 'us-west-2'),
|
au: Locale.new(:au, 'Australia', 'webservices.amazon.com.au', 'us-west-2'),
|
||||||
br: Locale.new(:br, 'Brazil', 'webservices.amazon.com.br' 'us-east-1'),
|
br: Locale.new(:br, 'Brazil', 'webservices.amazon.com.br', 'us-east-1'),
|
||||||
ca: Locale.new(:ca, 'Canada', 'webservices.amazon.ca', 'us-east-1'),
|
ca: Locale.new(:ca, 'Canada', 'webservices.amazon.ca', 'us-east-1'),
|
||||||
fr: Locale.new(:fr, 'France', 'webservices.amazon.fr', 'eu-west-1'),
|
fr: Locale.new(:fr, 'France', 'webservices.amazon.fr', 'eu-west-1'),
|
||||||
de: Locale.new(:de, 'Germany', 'webservices.amazon.de', 'eu-west-1'),
|
de: Locale.new(:de, 'Germany', 'webservices.amazon.de', 'eu-west-1'),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
require 'net/http'
|
require 'net/http/persistent'
|
||||||
require 'aws-sigv4'
|
require 'aws-sigv4'
|
||||||
require 'byebug'
|
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Client
|
class Client
|
||||||
@@ -11,9 +10,9 @@ module Paapi
|
|||||||
def initialize(access_key: Paapi.access_key,
|
def initialize(access_key: Paapi.access_key,
|
||||||
secret_key: Paapi.secret_key,
|
secret_key: Paapi.secret_key,
|
||||||
partner_tag: Paapi.partner_tag,
|
partner_tag: Paapi.partner_tag,
|
||||||
market: Paapi.market || DEFAULT_MARKET,
|
market: Paapi.market || DEFAULT_MARKET,
|
||||||
condition: Paapi.condition || DEFAULT_CONDITION,
|
condition: Paapi.condition || DEFAULT_CONDITION,
|
||||||
resources: Paapi.resources || DEFAULT_RESOURCES,
|
resources: Paapi.resources || DEFAULT_RESOURCES,
|
||||||
partner_type: DEFAULT_PARTNER_TYPE
|
partner_type: DEFAULT_PARTNER_TYPE
|
||||||
)
|
)
|
||||||
raise ArgumentError unless MARKETPLACES.keys.include?(market.to_sym)
|
raise ArgumentError unless MARKETPLACES.keys.include?(market.to_sym)
|
||||||
@@ -26,13 +25,7 @@ module Paapi
|
|||||||
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 = Net::HTTP::Persistent.new name: 'paapi'
|
||||||
@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)
|
||||||
@@ -72,7 +65,6 @@ 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]
|
||||||
@@ -109,24 +101,21 @@ module Paapi
|
|||||||
headers['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
|
headers['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
|
||||||
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'
|
||||||
|
|
||||||
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( post(url: endpoint, body: payload, headers: headers))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.post(url:, body:, headers:)
|
def post(url:, body:, headers:)
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
request = Net::HTTP::Post.new(uri)
|
|
||||||
request.content_type = 'application/json; charset=UTF-8'
|
post_request = Net::HTTP::Post.new(uri.path)
|
||||||
headers.each { |k, v| request[k] = v }
|
post_request.content_type = 'application/json; charset=UTF-8'
|
||||||
request.body = body.to_json
|
|
||||||
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
headers.each { |k, v| post_request[k] = v }
|
||||||
http.request(request)
|
post_request.body = body.to_json
|
||||||
end
|
|
||||||
|
http.request uri, post_request
|
||||||
|
|
||||||
end
|
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.4'
|
VERSION = '0.1.8'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|||||||
|
|
||||||
spec.metadata['homepage_uri'] = spec.homepage
|
spec.metadata['homepage_uri'] = spec.homepage
|
||||||
spec.metadata['source_code_uri'] = spec.homepage
|
spec.metadata['source_code_uri'] = spec.homepage
|
||||||
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
spec.metadata["changelog_uri"] = "https://github.com/dkam/paapi/blob/master/CHANGELOG.md"
|
||||||
|
|
||||||
# Specify which files should be added to the gem when it is released.
|
# Specify which files should be added to the gem when it is released.
|
||||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||||
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
||||||
|
|
||||||
spec.add_dependency 'aws-sigv4', '~> 1'
|
spec.add_dependency 'aws-sigv4', '~> 1'
|
||||||
|
spec.add_dependency 'net-http-persistent', '~> 4.0', '>= 4.0.1'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user