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 +4 -4
- data/README.md +4 -1
- data/lib/vacuum/client.rb +46 -11
- data/lib/vacuum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ab3db70bf188be7e645a18cd7faa49836662625763031a72e213af37b246d78
|
|
4
|
+
data.tar.gz: 1558eea1b389f27c029efba19c9dd244d8c594eb056ed944e0016e4dc362dbd8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
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"
|
|
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" =>
|
|
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 =
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
@
|
|
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
|
data/lib/vacuum/version.rb
CHANGED
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.
|
|
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.
|
|
59
|
+
rubygems_version: 4.0.6
|
|
60
60
|
specification_version: 4
|
|
61
61
|
summary: Amazon Creators API in Ruby
|
|
62
62
|
test_files: []
|