paapi 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 259e83f7564df1078faa89b5c4c284bb732c4ef4d325bbf5148cac06943469a7
4
- data.tar.gz: 07fd0a94307184a443a86821d40ee3c9e8f9a25c2343e09e321828f90701e50d
3
+ metadata.gz: 108df76951b9a410d040f8da6c7c915262955dce5484328f0f8e8b10cbc65c76
4
+ data.tar.gz: db5c684ded7f43e1451e6ffaa3835b1fe552372a7d1e039f0a7977d108c598a2
5
5
  SHA512:
6
- metadata.gz: e5e1cd4cc02383c8b6b3d6a3da997e847cb103e8e0a4abfaea50300c43a429dec2695269fa5c02ecbcf978c78020b08358c0804db03434f8981de761a30ce548
7
- data.tar.gz: cdf7e41cd53b99b4402348ea17dd32e092d67d05144358dfcc87c8ac1ed79b130133be27a754421b392b8be10ba9dcbbe702571071ee4095aea7b4e6c323fd84
6
+ metadata.gz: 689c4019cfc8cb11577e47427bb165a84fd69db9b5e682c81783e460138cc04cb2f1303a3c582eb04e97f868b8fe72eafd05df57c1cfe6eb68ff541ec221724e
7
+ data.tar.gz: 7def30214ab3c07e19b04cb8213bcc2f2cf46165ec56e0f9960349b5ab899c4fa71683c7b153bea6407303ef6c4457798740b6f58d7af43e0b589d603b4a1c46
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.3
2
+ - Dropped the HTTP gem and moved to Ruby's Net::HTTP
3
+ - Merged a branch which adds the Condtion parameter.
4
+
1
5
  ## 0.1.2
2
6
  - Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
3
7
 
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Build Status](https://travis-ci.org/dkam/paapi.svg?branch=master)](https://travis-ci.org/dkam/paapi)
6
6
 
7
- If this gem doesn't meet your needs, try the [Vacumm gem](https://github.com/hakanensari/vacuum).
7
+ If this gem doesn't meet your needs, try the [Vacuum gem](https://github.com/hakanensari/vacuum).
8
8
 
9
9
  ## Installation
10
10
 
@@ -77,16 +77,27 @@ client = Paapi::Client.new(access_key: ENV['access_key'], secret_key: ENV['secre
77
77
  gi = client.get_items(item_ids: '1857231384')
78
78
 
79
79
  si = client.search_items(keywords: 'Harry Potter')
80
+ si = client.search_items(keywords: 'Harry Potter', SearchIndex)
80
81
 
81
82
  gv = client.get_variations(asin: 'B00422MCUS')
82
83
  ```
83
84
 
85
+ You can access the response as a Hash, or
86
+
84
87
  ## Development
85
88
 
86
89
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
90
 
88
91
  If you create a file `config.rb`, it will be loaded by `bin/console`, allowing you to configure keys and markets.
89
92
 
93
+ ```ruby
94
+ Paapi.configure do |config|
95
+ config.access_key = 'access_key'
96
+ config.secret_key = 'secret_key'
97
+ config.partner_market = {au: 'au_tag', us: 'us_tag', uk: 'uk_tag', ca: 'ca_tag_'}
98
+ end
99
+ ```
100
+
90
101
  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).
91
102
 
92
103
  ## Contributing
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'paapi'
4
+ #require 'paapi'
5
+ require './lib/paapi.rb'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
data/lib/paapi/client.rb CHANGED
@@ -1,16 +1,17 @@
1
- require 'http'
1
+ require 'net/http'
2
2
  require 'aws-sigv4'
3
3
 
4
4
  module Paapi
5
5
  class Client
6
6
 
7
- attr_accessor :partner_tag, :marketplace, :resources
8
- attr_reader :partner_type, :access_key, :secret_key, :market
7
+ attr_accessor :partner_tag, :marketplace, :resources, :condition
8
+ attr_reader :partner_type, :access_key, :secret_key, :market, :http
9
9
 
10
10
  def initialize(access_key: Paapi.access_key,
11
11
  secret_key: Paapi.secret_key,
12
12
  partner_tag: Paapi.partner_tag,
13
13
  market: Paapi.market || DEFAULT_MARKET,
14
+ condition: Paapi.condition || DEFAULT_CONDITION,
14
15
  resources: Paapi.resources || DEFAULT_RESOURCES,
15
16
  partner_type: DEFAULT_PARTNER_TYPE
16
17
  )
@@ -20,9 +21,17 @@ module Paapi
20
21
  @secret_key = secret_key
21
22
  @partner_type = partner_type
22
23
  @resources = resources unless resources.nil?
23
-
24
+ @condition = condition
24
25
  self.market = market
25
26
  @partner_tag = partner_tag if !partner_tag.nil?
27
+
28
+ if defined?(HTTPX)
29
+ @http = HTTPX.plugin(:persistent)
30
+ elsif defined?(HTTP)
31
+ @http = HTTP::Client.new
32
+ else
33
+ @http = nil
34
+ end
26
35
  end
27
36
 
28
37
  def market=(a_market)
@@ -43,7 +52,7 @@ module Paapi
43
52
  request(op: :get_variations, payload: payload)
44
53
  end
45
54
 
46
- # TODO: Currently we assume Keywords, but we need one of the follow: [Keywords Actor Artist Author Brand Title ]
55
+ # TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ]
47
56
  def search_items(keywords: nil, **options )
48
57
  raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
49
58
 
@@ -63,7 +72,7 @@ module Paapi
63
72
 
64
73
  def request(op:, payload:)
65
74
  raise ArguemntError unless Paapi::OPERATIONS.keys.include?(op)
66
-
75
+
67
76
  operation = OPERATIONS[op]
68
77
 
69
78
  headers = {
@@ -72,6 +81,7 @@ module Paapi
72
81
  }
73
82
 
74
83
  default_payload = {
84
+ 'Condition' => condition,
75
85
  'PartnerTag' => partner_tag,
76
86
  'PartnerType' => partner_type,
77
87
  'Marketplace' => marketplace.site
@@ -97,10 +107,24 @@ module Paapi
97
107
  headers['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
98
108
  headers['Authorization'] = signature.headers['authorization']
99
109
  headers['Content-Type'] = 'application/json; charset=utf-8'
110
+
111
+ unless @http.nil?
112
+ Response.new( @http.with_headers(headers).post(endpoint, json: payload ) )
113
+ else
114
+ Response.new( Client.post(url: endpoint, body: payload, headers: headers))
115
+ end
116
+
117
+ end
100
118
 
101
- Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
119
+ def self.post(url:, body:, headers:)
120
+ uri = URI.parse(url)
121
+ request = Net::HTTP::Post.new(uri)
122
+ request.content_type = 'application/json; charset=UTF-8'
123
+ headers.each { |k, v| request[k] = v }
124
+ request.body = body.to_json
125
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
126
+ http.request(request)
127
+ end
102
128
  end
103
129
  end
104
-
105
-
106
130
  end
data/lib/paapi/item.rb CHANGED
@@ -128,22 +128,22 @@ module Paapi
128
128
 
129
129
  def height
130
130
  data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
131
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
131
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
132
132
  end
133
133
 
134
134
  def length
135
135
  data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
136
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
136
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
137
137
  end
138
138
 
139
139
  def width
140
140
  data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
141
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
141
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
142
142
  end
143
143
 
144
144
  def weight
145
145
  data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
146
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
146
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
147
147
  end
148
148
 
149
149
  def kindle?
data/lib/paapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Paapi
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.5'
3
3
  end
data/lib/paapi.rb CHANGED
@@ -11,6 +11,7 @@ module Paapi
11
11
  SEARCH_PARAMS = %i[keywords actor, artist, author, brand title].freeze
12
12
  DEFAULT_PARTNER_TYPE = 'Associates'
13
13
  DEFAULT_MARKET = :us
14
+ DEFAULT_CONDITION = 'Any'
14
15
  DEFAULT_RESOURCES = [
15
16
  'Images.Primary.Large',
16
17
  'ItemInfo.ByLineInfo',
@@ -72,6 +73,7 @@ module Paapi
72
73
  :partner_type,
73
74
  :market,
74
75
  :partner_market,
76
+ :condition,
75
77
  :resources,
76
78
  :test_mode
77
79
 
data/paapi.gemspec CHANGED
@@ -31,6 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'byebug', '~> 11'
32
32
  spec.add_development_dependency 'awesome_print', '~> 1.8'
33
33
 
34
- spec.add_dependency 'http', '~> 4'
35
34
  spec.add_dependency 'aws-sigv4', '~> 1'
36
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Milne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.8'
83
- - !ruby/object:Gem::Dependency
84
- name: http
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '4'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '4'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: aws-sigv4
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
138
  - !ruby/object:Gem::Version
153
139
  version: '0'
154
140
  requirements: []
155
- rubygems_version: 3.1.2
141
+ rubygems_version: 3.3.7
156
142
  signing_key:
157
143
  specification_version: 4
158
144
  summary: Client library for Amazon's Product Advertising API v5