vacuum 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc789e68874474859f4ca103b08ce6c56e7d714eafa76f1f2780efabc232726f
4
- data.tar.gz: 48d6f52b193a912da0ed88845813d6814786ea60fc83ceff2541407c482e4097
3
+ metadata.gz: 0ab3db70bf188be7e645a18cd7faa49836662625763031a72e213af37b246d78
4
+ data.tar.gz: 1558eea1b389f27c029efba19c9dd244d8c594eb056ed944e0016e4dc362dbd8
5
5
  SHA512:
6
- metadata.gz: 7a58ce7a92532ac352ebef589caf42192a958af8203fdf4eae1e0d859b317b13afc8f9b79b635645b92d4bdb756eb9f21e4505ca5c2c091ab1235b32a2dc2dec
7
- data.tar.gz: 538c6c125cf2d3b22622df7ff0ac91ffa76536edcf81ab3d8849968046f016926e64da300301a53fa5757125d16d96dbb67180539b62dc3476de8a248a0efec7
6
+ metadata.gz: b677583ab6f8759042ce9e7805f1646e72af0b307e22b55a433c7f141b9ab4e21a17d4969a9741a503c1e5940fe6c4912abc3bf4b693538d8fa31f01874d7c20
7
+ data.tar.gz: 07fe15c4f43ab1735d0c6cd111cb94f6fb79a1c17ed2f33e1e94ea08e30630d78f52a50193f6945767171aede03d3be6393c3b5b7fa8d2adcf7196569f701e25
data/README.md CHANGED
@@ -33,13 +33,16 @@ response.parse
33
33
 
34
34
  ### Versions and Marketplaces
35
35
 
36
- The `version` determines which authentication endpoint to use:
36
+ The `version` determines which authentication endpoint to use. Versions `2.x` use Amazon Cognito; versions `3.x` use Login with Amazon (LwA).
37
37
 
38
38
  | Version | Region |
39
39
  |---------|--------|
40
40
  | `"2.1"` | North America |
41
41
  | `"2.2"` | Europe |
42
42
  | `"2.3"` | Far East |
43
+ | `"3.1"` | North America |
44
+ | `"3.2"` | Europe |
45
+ | `"3.3"` | Far East |
43
46
 
44
47
  ### Operations
45
48
 
data/lib/vacuum/client.rb CHANGED
@@ -7,16 +7,18 @@ module Vacuum
7
7
  #
8
8
  # Handles authentication automatically and caches access tokens.
9
9
  #
10
- # @example Basic usage
10
+ # @example Basic usage (v2.x)
11
11
  # client = Vacuum::Client.new(
12
12
  # credential_id: "YOUR_CREDENTIAL_ID",
13
13
  # credential_secret: "YOUR_CREDENTIAL_SECRET",
14
14
  # version: "2.1"
15
15
  # )
16
- # response = client.search_items(
17
- # marketplace: "www.amazon.com",
18
- # partner_tag: "yourtag-20",
19
- # keywords: "ruby programming"
16
+ #
17
+ # @example Basic usage (v3.x)
18
+ # client = Vacuum::Client.new(
19
+ # credential_id: "YOUR_CREDENTIAL_ID",
20
+ # credential_secret: "YOUR_CREDENTIAL_SECRET",
21
+ # version: "3.3"
20
22
  # )
21
23
  #
22
24
  # @example With shared cache (for multi-process environments like Rails)
@@ -31,6 +33,9 @@ module Vacuum
31
33
  "2.1" => "https://creatorsapi.auth.us-east-1.amazoncognito.com/oauth2/token",
32
34
  "2.2" => "https://creatorsapi.auth.eu-south-2.amazoncognito.com/oauth2/token",
33
35
  "2.3" => "https://creatorsapi.auth.us-west-2.amazoncognito.com/oauth2/token",
36
+ "3.1" => "https://api.amazon.com/auth/o2/token",
37
+ "3.2" => "https://api.amazon.co.uk/auth/o2/token",
38
+ "3.3" => "https://api.amazon.co.jp/auth/o2/token",
34
39
  }.freeze
35
40
 
36
41
  API_URL = "https://creatorsapi.amazon/catalog/v1"
@@ -41,7 +46,7 @@ module Vacuum
41
46
  #
42
47
  # @param credential_id [String] Your Creators API credential ID
43
48
  # @param credential_secret [String] Your Creators API credential secret
44
- # @param version [String] API version ("2.1", "2.2", or "2.3")
49
+ # @param version [String] API version ("2.1"-"2.3" for Cognito, "3.1"-"3.3" for LwA)
45
50
  # @param cache [#fetch] Optional cache store
46
51
  # @param http [HTTP::Client]
47
52
  def initialize(version:, credential_id:, credential_secret:, cache: nil, http: HTTP)
@@ -99,10 +104,20 @@ module Vacuum
99
104
 
100
105
  private
101
106
 
107
+ def v3?
108
+ @version.start_with?("3.")
109
+ end
110
+
102
111
  def request(operation, marketplace:, partner_tag:, **params)
112
+ auth_header = if v3?
113
+ "Bearer #{access_token}"
114
+ else
115
+ "Bearer #{access_token}, Version #{@version}"
116
+ end
117
+
103
118
  @http
104
119
  .headers(
105
- "Authorization" => "Bearer #{access_token}, Version #{@version}",
120
+ "Authorization" => auth_header,
106
121
  "x-marketplace" => marketplace,
107
122
  )
108
123
  .post("#{API_URL}/#{operation}", json: camelize_keys(marketplace:, partner_tag:, **params))
@@ -130,16 +145,36 @@ module Vacuum
130
145
  end
131
146
 
132
147
  def fetch_token
133
- response = @http
148
+ response = if v3?
149
+ fetch_token_lwa
150
+ else
151
+ fetch_token_cognito
152
+ end
153
+
154
+ data = response.parse
155
+ @token_expires_at = Time.now + TOKEN_TTL
156
+ @access_token = data["access_token"]
157
+ end
158
+
159
+ # v2.x: Cognito with Basic Auth and form-encoded body
160
+ def fetch_token_cognito
161
+ @http
134
162
  .basic_auth(user: @credential_id, pass: @credential_secret)
135
163
  .post(@auth_url, form: {
136
164
  grant_type: "client_credentials",
137
165
  scope: "creatorsapi/default",
138
166
  })
167
+ end
139
168
 
140
- data = response.parse
141
- @token_expires_at = Time.now + TOKEN_TTL
142
- @access_token = data["access_token"]
169
+ # v3.x: Login with Amazon (LwA) with JSON body
170
+ def fetch_token_lwa
171
+ @http
172
+ .post(@auth_url, json: {
173
+ grant_type: "client_credentials",
174
+ client_id: @credential_id,
175
+ client_secret: @credential_secret,
176
+ scope: "creatorsapi::default",
177
+ })
143
178
  end
144
179
  end
145
180
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vacuum
4
- VERSION = "5.0.0"
4
+ VERSION = "5.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacuum
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 4.0.3
59
+ rubygems_version: 4.0.6
60
60
  specification_version: 4
61
61
  summary: Amazon Creators API in Ruby
62
62
  test_files: []