paapi 0.1.1 → 0.1.6

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: ac9634d240fe32902142162f6e582bb97e408b2ba57f6170de9b4381eed0b9a3
4
- data.tar.gz: 50fe91ed557e4f1afc052ec56805cb8975889da8340c69bef0ad2aa7e3eca3e0
3
+ metadata.gz: fb2f6fd64063b62cac4f8df9476bae33248eaa6afd7d199b9b31c253251c6d63
4
+ data.tar.gz: 82ce9d560957cfc8d7debcd2ef63cd779b3d38297318e3473598babf6d40067f
5
5
  SHA512:
6
- metadata.gz: 5d464a9fe20bf19d209f8161fbd5b76111d3f8c10dc4993ad98110c2dc9236d658ebf0fca9f8d47a0aa359b408dcc543ace65b2e2d4ce01f61465fe6756b30ef
7
- data.tar.gz: '08ad01e0bc82c144169699e753ad204a7afe2fb010ececcad97309aeb4b6e6f6bfedff41ae2b44281d4957fc8f1f2acf12bd0977ce56f3f9f07d3148e8e14043'
6
+ metadata.gz: 1ee31952cbbb2abde7fed09af057b24604fd3c04c1c563b8b152872b301ab269a4a71817e530da4f462d7b0dec13bf445345a2d3941ed8bafa0291304cda5f07
7
+ data.tar.gz: 696893b64fbff30a569edfdee84df5e3601f02957ef455a11937697197a9866b79dbe15858246faac8f19811dc2abf5bf39d2e7cb5a19a2ab65b925418c2a56c
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
@@ -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
@@ -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?
data/lib/paapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Paapi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.6'
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',
@@ -41,7 +42,7 @@ module Paapi
41
42
 
42
43
  MARKETPLACES = {
43
44
  au: Locale.new(:au, 'Australia', 'webservices.amazon.com.au', 'us-west-2'),
44
- br: Locale.new(:br, 'Brazil', 'webservices.amazon.com.br' 'us-east-1'),
45
+ br: Locale.new(:br, 'Brazil', 'webservices.amazon.com.br', 'us-east-1'),
45
46
  ca: Locale.new(:ca, 'Canada', 'webservices.amazon.ca', 'us-east-1'),
46
47
  fr: Locale.new(:fr, 'France', 'webservices.amazon.fr', 'eu-west-1'),
47
48
  de: Locale.new(:de, 'Germany', 'webservices.amazon.de', 'eu-west-1'),
@@ -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.1
4
+ version: 0.1.6
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: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2022-09-04 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
@@ -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.1.2
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: []