paapi 0.1.0 → 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: 1199bef4130fde3604df7b3fa82d34e0aeacc121147658250e3428b0331acd6f
4
- data.tar.gz: 91b43cf23d3a67e453d5ab3cd1fea31eeefc80981118e3c0af6307834cdc39de
3
+ metadata.gz: 108df76951b9a410d040f8da6c7c915262955dce5484328f0f8e8b10cbc65c76
4
+ data.tar.gz: db5c684ded7f43e1451e6ffaa3835b1fe552372a7d1e039f0a7977d108c598a2
5
5
  SHA512:
6
- metadata.gz: cc4f7997a3a73fb0758fad48fc28fc3ceb38a60cdd3a60ecb787957368c09165409875fa2bbb84250a13215c899e8e6fbf83ad3a9deca0e735bdceff5ae40c70
7
- data.tar.gz: 4f0bbf80edbff3045f0f68ce6bf65af8cc1ad69745902961d5595bcf29e0d9b9b08c5527a37b794d629b08e23cac9d4623e91ec1afd2aebb707b538af836829c
6
+ metadata.gz: 689c4019cfc8cb11577e47427bb165a84fd69db9b5e682c81783e460138cc04cb2f1303a3c582eb04e97f868b8fe72eafd05df57c1cfe6eb68ff541ec221724e
7
+ data.tar.gz: 7def30214ab3c07e19b04cb8213bcc2f2cf46165ec56e0f9960349b5ab899c4fa71683c7b153bea6407303ef6c4457798740b6f58d7af43e0b589d603b4a1c46
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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
+
5
+ ## 0.1.2
6
+ - Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
7
+
1
8
  ## 0.1.0
2
9
  - Remove Nameable dependancy and return the data as the API returns it.
3
10
 
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  `paapi` is a slim wrapper around [Amazon's Product Advertising API 5.0](https://webservices.amazon.com/paapi5/documentation/).
4
4
 
5
- This gem is under heavy development and currently incomplete.
6
-
7
5
  [![Build Status](https://travis-ci.org/dkam/paapi.svg?branch=master)](https://travis-ci.org/dkam/paapi)
8
6
 
7
+ If this gem doesn't meet your needs, try the [Vacuum gem](https://github.com/hakanensari/vacuum).
8
+
9
9
  ## Installation
10
10
 
11
11
  Add this line to your application's Gemfile:
@@ -36,7 +36,7 @@ Paapi.configure do |config|
36
36
  end
37
37
  ```
38
38
 
39
- Configurable itemes:
39
+ Configurable items:
40
40
  * access_key
41
41
  * secret_key
42
42
  * partner_tag
@@ -67,7 +67,7 @@ client.partner_tag
67
67
 
68
68
  The full list of market keys is `au, br, ca, fr, de, in, it, jp, mx, es, tr, ae, uk, us`
69
69
 
70
- ### Using the Paapi
70
+ ### Using Paapi
71
71
 
72
72
  ```ruby
73
73
  require 'paapi'
@@ -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
@@ -54,32 +54,36 @@ module Paapi
54
54
  end
55
55
 
56
56
  def contributors_of(kind)
57
- kind = kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize }
58
- contributors.select { |e| e['Role'] == kind }&.map { |e| e.dig('Name') }&.reject {|n| n.to_s.empty?}
57
+ kind = kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.downcase }
58
+ contributors.select { |e| e['RoleType'] == kind }&.map { |e| e.dig('Name') }&.reject {|n| n.to_s.empty?}
59
59
  end
60
60
 
61
61
  def actors
62
- contributors_of 'Actor'
62
+ contributors_of 'actor'
63
63
  end
64
64
 
65
65
  def artists
66
- contributors_of 'Artist'
66
+ contributors_of 'artist'
67
67
  end
68
68
 
69
69
  def authors
70
- contributors_of 'Author'
70
+ contributors_of 'author'
71
+ end
72
+
73
+ def director
74
+ contributors_of 'director'
71
75
  end
72
76
 
73
77
  def illustrators
74
- contributors_of 'Illustrator'
78
+ contributors_of 'illustrator'
75
79
  end
76
80
 
77
81
  def narrators
78
- contributors_of 'Narrator'
82
+ contributors_of 'narrator'
79
83
  end
80
84
 
81
85
  def publishers
82
- contributors_of 'Publisher'
86
+ contributors_of 'publisher'
83
87
  end
84
88
 
85
89
  def languages
@@ -124,22 +128,22 @@ module Paapi
124
128
 
125
129
  def height
126
130
  data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
127
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
131
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
128
132
  end
129
133
 
130
134
  def length
131
135
  data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
132
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
136
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
133
137
  end
134
138
 
135
139
  def width
136
140
  data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
137
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
141
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
138
142
  end
139
143
 
140
144
  def weight
141
145
  data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
142
- [data.dig('DisplayValue'), data.dig('Unit')].join(' ')
146
+ [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ')
143
147
  end
144
148
 
145
149
  def kindle?
@@ -10,6 +10,7 @@ module Paapi
10
10
 
11
11
  @items_data = @hash.dig('ItemsResult', 'Items')
12
12
  @items_data ||= @hash.dig('SearchResult', 'Items')
13
+ @items_data ||= @hash.dig('VariationsResult', 'Items')
13
14
  @items_data ||= []
14
15
 
15
16
  @items = @items_data.map {|d| Item.new(d)}
data/lib/paapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Paapi
2
- VERSION = '0.1.0'
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
@@ -26,11 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ['lib']
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 2.0'
29
- spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rake', '>= 12.3.r3'
30
30
  spec.add_development_dependency 'minitest', '~> 5.0'
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.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Milne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-25 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
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.r3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.r3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -108,7 +94,7 @@ dependencies:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '1'
111
- description:
97
+ description:
112
98
  email:
113
99
  - d@nmilne.com
114
100
  executables: []
@@ -137,7 +123,7 @@ licenses:
137
123
  metadata:
138
124
  homepage_uri: https://github.com/dkam/paapi
139
125
  source_code_uri: https://github.com/dkam/paapi
140
- post_install_message:
126
+ post_install_message:
141
127
  rdoc_options: []
142
128
  require_paths:
143
129
  - lib
@@ -152,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
138
  - !ruby/object:Gem::Version
153
139
  version: '0'
154
140
  requirements: []
155
- rubygems_version: 3.0.3
156
- signing_key:
141
+ rubygems_version: 3.3.7
142
+ signing_key:
157
143
  specification_version: 4
158
144
  summary: Client library for Amazon's Product Advertising API v5
159
145
  test_files: []