amz_sp_api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/amz_sp_api-0.2.1.gem +0 -0
- data/lib/amz_sp_api.rb +29 -22
- data/lib/amz_sp_api_version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1935461ccb847a6cbcde207477ffc65875ffaf6
|
4
|
+
data.tar.gz: c218101c0d50578bd07847e6cd0c277b8e68a12b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39e75fe5e3a4a7ea79b884e57bb723df123b025eb46128d99374d3e96a00b34f422e54757526d53fe7f361cd81f238615fbff16308ca6fdeac0324cd149bc1f1
|
7
|
+
data.tar.gz: 2c23f34bfc73d8c09df0c219b677a7b1ae66901533f4595d22285bd6302f865bd9f6c83daaade2dc4a5e2e20740adc607dfdd7fae50e2a3a569661eef84ed6de
|
data/README.md
CHANGED
@@ -59,9 +59,9 @@ require 'fulfillment-outbound-api-model'
|
|
59
59
|
|
60
60
|
This is a handy way to see all the API model class names and corresponding files you need to require for them, e.g. require 'finances-api-model' to use https://www.rubydoc.info/gems/amz_sp_api/AmzSpApi/FinancesApiModel/DefaultApi
|
61
61
|
|
62
|
-
## Feeds
|
62
|
+
## Feeds and reports
|
63
63
|
|
64
|
-
This gem also offers encrypt/decrypt helper methods for feeds, but actually using that API as per https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide requires the following calls:
|
64
|
+
This gem also offers encrypt/decrypt helper methods for feeds and reports, but actually using that API as per https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide requires the following calls, e.g. for feeds but reports is the same pattern:
|
65
65
|
|
66
66
|
```ruby
|
67
67
|
feeds = AmzSpApi::FeedsApiModel::FeedsApi.new(AmzSpApi::SpApiClient.new)
|
@@ -77,7 +77,7 @@ result_feed_document_id = response&.payload&.dig(:resultFeedDocumentId) # presen
|
|
77
77
|
response = feeds.get_feed_document(result_feed_document_id)
|
78
78
|
url = response&.payload&.dig(:url)
|
79
79
|
# GET response&.payload&.dig(:url) into ciphertext, again it's pre-signed so no authorization needed
|
80
|
-
AmzSpApi.
|
80
|
+
AmzSpApi.decrypt_and_inflate_document(ciphertext, response.payload)
|
81
81
|
```
|
82
82
|
|
83
83
|
## Thanks
|
Binary file
|
data/lib/amz_sp_api.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'amz_sp_api_version'
|
2
|
+
require 'api_error'
|
2
3
|
require 'sp_api_client'
|
3
4
|
require 'sp_configuration'
|
4
5
|
|
@@ -16,37 +17,43 @@ module AmzSpApi
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
def encrypt_feed(feed_content,
|
20
|
-
cipher =
|
20
|
+
def encrypt_feed(feed_content, document_response_payload)
|
21
|
+
cipher = document_cipher(document_response_payload, encrypt: true)
|
21
22
|
cipher.update(feed_content) + cipher.final
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
cipher =
|
25
|
+
def decrypt_and_inflate_document(ciphertext, document_response_payload)
|
26
|
+
body = if cipher = document_cipher(document_response_payload, encrypt: false)
|
27
|
+
cipher.update(ciphertext) + cipher.final
|
28
|
+
else
|
29
|
+
ciphertext
|
30
|
+
end
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
inflate_document(body, document_response_payload)
|
33
|
+
end
|
34
|
+
alias_method :decrypt_and_inflate_feed, :decrypt_and_inflate_document
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
def inflate_document(body, document_response_payload)
|
37
|
+
compression = document_response_payload[:compressionAlgorithm]
|
38
|
+
raise AmzSpApi::ApiError.new("unknown compressionAlgorithm #{compression}") if compression && compression != "GZIP"
|
39
|
+
compression ? Zlib::Inflate.inflate(body) : body
|
33
40
|
end
|
34
41
|
|
35
42
|
# from https://github.com/amzn/selling-partner-api-models/blob/main/clients/sellingpartner-api-documents-helper-java/src/main/java/com/amazon/spapi/documents/impl/AESCryptoStreamFactory.java
|
36
|
-
def
|
37
|
-
key = Base64.decode64(response.dig(:encryptionDetails, :key))
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
def document_cipher(response, encrypt:)
|
44
|
+
if key = Base64.decode64(response.dig(:encryptionDetails, :key))
|
45
|
+
cipher = case response.dig(:encryptionDetails, :standard)
|
46
|
+
when "AES"
|
47
|
+
OpenSSL::Cipher.new("AES-#{key.size * 8}-CBC")
|
48
|
+
else
|
49
|
+
raise AmzSpApi::ApiError.new("unknown encryption standard #{response.inspect}")
|
50
|
+
end
|
51
|
+
|
52
|
+
encrypt ? cipher.encrypt : cipher.decrypt
|
53
|
+
cipher.key = key
|
54
|
+
cipher.iv = Base64.decode64(response.dig(:encryptionDetails, :initializationVector))
|
55
|
+
cipher
|
44
56
|
end
|
45
|
-
|
46
|
-
encrypt ? cipher.encrypt : cipher.decrypt
|
47
|
-
cipher.key = key
|
48
|
-
cipher.iv = Base64.decode64(response.dig(:encryptionDetails, :initializationVector))
|
49
|
-
cipher
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
data/lib/amz_sp_api_version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amz_sp_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
99
|
- amz_sp_api-0.2.0.gem
|
100
|
+
- amz_sp_api-0.2.1.gem
|
100
101
|
- amz_sp_api.gemspec
|
101
102
|
- codegen.sh
|
102
103
|
- config.json
|