amz_sp_api 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -3
- data/amz_sp_api.gemspec +1 -1
- data/lib/amz_sp_api.rb +2 -1
- data/lib/amz_sp_api_version.rb +1 -1
- data/lib/restricted_sp_api_client.rb +56 -0
- data/lib/sp_api_client.rb +16 -16
- metadata +5 -13
- data/amz_sp_api-0.2.0.gem +0 -0
- data/amz_sp_api-0.2.1.gem +0 -0
- data/amz_sp_api-0.2.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af5701c2fe08efdbaa850f795f22fe0a28896bf25d6a9931450000b0e74c215b
|
4
|
+
data.tar.gz: a20507de180c513ffecfe398b7083575dfd9e4afea3fa749e9bf60c7a2d39711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1b9c1df6b1021a6e8764c07e87eade52c150da5a25e5c7b7865496c3c06660ada15837fa4f7036a66869cda7d34df20fe722925098285d8be3a4f24984f437
|
7
|
+
data.tar.gz: ef6fd443e3b8ee3f958ebdf17b5bb497d870d860e0204866ac11b22edccce4487b1c6846e01a47313a8ae530ac87184ef3345b30089ceca915ed0c82c614e981
|
data/README.md
CHANGED
@@ -4,7 +4,9 @@ AmzSpApi - Unofficial Ruby gem for the Amazon Selling Partner API (SP-API)
|
|
4
4
|
|
5
5
|
This SDK is automatically generated by running [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) on each model from https://github.com/amzn/selling-partner-api-models using the [codegen.sh](codegen.sh) script.
|
6
6
|
|
7
|
-
Auto-generated documentation is nested here
|
7
|
+
Auto-generated documentation is nested here: 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
|
8
|
+
|
9
|
+
but https://developer-docs.amazon.com/sp-api is more comprehensive.
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -55,9 +57,40 @@ require 'fulfillment-outbound-api-model'
|
|
55
57
|
end
|
56
58
|
```
|
57
59
|
|
58
|
-
##
|
60
|
+
## Restricted operations
|
61
|
+
|
62
|
+
Configure as per above but also create a new client for each restrictedResources you need, e.g.:
|
59
63
|
|
60
|
-
|
64
|
+
```
|
65
|
+
require 'orders-api-model'
|
66
|
+
|
67
|
+
client = AmzSpApi::RestrictedSpApiClient.new({
|
68
|
+
'restrictedResources' => [
|
69
|
+
{
|
70
|
+
'method' => 'GET',
|
71
|
+
'path' => "/orders/v0/orders",
|
72
|
+
'dataElements' => ['buyerInfo', 'shippingAddress']
|
73
|
+
}
|
74
|
+
]
|
75
|
+
})
|
76
|
+
api_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)
|
77
|
+
api_orders.get_orders(marketplace_ids, created_after: 1.day.ago.iso8601)
|
78
|
+
|
79
|
+
client = AmzSpApi::RestrictedSpApiClient.new({
|
80
|
+
'restrictedResources' => [
|
81
|
+
{
|
82
|
+
'method' => 'GET',
|
83
|
+
'path' => "/orders/v0/orders/#{my_order_id}",
|
84
|
+
'dataElements' => ['buyerInfo', 'shippingAddress']
|
85
|
+
}
|
86
|
+
]
|
87
|
+
})
|
88
|
+
api_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)
|
89
|
+
api_orders.get_order(my_order_id)
|
90
|
+
|
91
|
+
# or you can use models AmzSpApi::RestrictedSpApiClient.new(AmzSpApi::TokensApiModel::CreateRestrictedDataTokenRequest.new(restricted_resources: [
|
92
|
+
AmzSpApi::TokensApiModel::RestrictedResource.new(...
|
93
|
+
```
|
61
94
|
|
62
95
|
## Feeds and reports
|
63
96
|
|
data/amz_sp_api.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.required_ruby_version = ">= 1.9"
|
28
28
|
|
29
29
|
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
30
|
-
s.add_runtime_dependency 'json'
|
30
|
+
s.add_runtime_dependency 'json'
|
31
31
|
s.add_runtime_dependency 'aws-sigv4', '~> 1.2'
|
32
32
|
|
33
33
|
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
data/lib/amz_sp_api.rb
CHANGED
data/lib/amz_sp_api_version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'api_error'
|
2
|
+
require 'api_client'
|
3
|
+
require 'configuration'
|
4
|
+
require 'sp_api_client'
|
5
|
+
|
6
|
+
require 'tokens-api-model'
|
7
|
+
|
8
|
+
module AmzSpApi
|
9
|
+
class RestrictedSpApiClient < ApiClient
|
10
|
+
|
11
|
+
def initialize(create_restricted_data_token_request, config = SpConfiguration.default)
|
12
|
+
super(config)
|
13
|
+
raise "pass create_restricted_data_token_request to RestrictedSpApiClient.new" if create_restricted_data_token_request.kind_of?(Configuration)
|
14
|
+
@wrapped_client = SpApiClient.new(config)
|
15
|
+
@create_restricted_data_token_request = create_restricted_data_token_request
|
16
|
+
@cache_key = config.access_token_key + "-RDT-" + Digest::MD5.hexdigest(create_restricted_data_token_request.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :super_call_api, :call_api
|
20
|
+
def call_api(http_method, path, opts = {})
|
21
|
+
unsigned_request = build_request(http_method, path, opts)
|
22
|
+
aws_headers = auth_headers(http_method, unsigned_request.url, unsigned_request.encoded_body)
|
23
|
+
signed_opts = opts.merge(:header_params => aws_headers.merge(opts[:header_params] || {}))
|
24
|
+
super(http_method, path, signed_opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def retrieve_rdt_access_token
|
30
|
+
return request_rdt_access_token[:access_token] unless config.get_access_token
|
31
|
+
stored_token = config.get_access_token.call(@cache_key)
|
32
|
+
if stored_token.nil?
|
33
|
+
new_token = request_rdt_access_token
|
34
|
+
config.save_access_token.call(@cache_key, new_token) if config.save_access_token
|
35
|
+
return new_token[:access_token]
|
36
|
+
else
|
37
|
+
return stored_token
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def request_rdt_access_token
|
42
|
+
api_tokens = AmzSpApi::TokensApiModel::TokensApi.new(@wrapped_client)
|
43
|
+
response = api_tokens.create_restricted_data_token(@create_restricted_data_token_request)
|
44
|
+
|
45
|
+
{access_token: response.restricted_data_token,
|
46
|
+
expires_in: response.expires_in}
|
47
|
+
end
|
48
|
+
|
49
|
+
def auth_headers(http_method, url, body)
|
50
|
+
SpApiClient.signed_request_headers(config, http_method, url, body).merge({
|
51
|
+
'x-amz-access-token' => retrieve_rdt_access_token
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/sp_api_client.rb
CHANGED
@@ -18,6 +18,21 @@ module AmzSpApi
|
|
18
18
|
super(http_method, path, signed_opts)
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.signed_request_headers(config, http_method, url, body)
|
22
|
+
request_config = {
|
23
|
+
service: 'execute-api',
|
24
|
+
region: config.aws_region
|
25
|
+
}
|
26
|
+
if config.credentials_provider
|
27
|
+
request_config[:credentials_provider] = config.credentials_provider
|
28
|
+
else
|
29
|
+
request_config[:access_key_id] = config.aws_access_key_id
|
30
|
+
request_config[:secret_access_key] = config.aws_secret_access_key
|
31
|
+
end
|
32
|
+
signer = Aws::Sigv4::Signer.new(request_config)
|
33
|
+
signer.sign_request(http_method: http_method.to_s, url: url, body: body).headers
|
34
|
+
end
|
35
|
+
|
21
36
|
private
|
22
37
|
|
23
38
|
def retrieve_lwa_access_token
|
@@ -58,23 +73,8 @@ module AmzSpApi
|
|
58
73
|
data
|
59
74
|
end
|
60
75
|
|
61
|
-
def signed_request_headers(http_method, url, body)
|
62
|
-
request_config = {
|
63
|
-
service: 'execute-api',
|
64
|
-
region: config.aws_region
|
65
|
-
}
|
66
|
-
if config.credentials_provider
|
67
|
-
request_config[:credentials_provider] = config.credentials_provider
|
68
|
-
else
|
69
|
-
request_config[:access_key_id] = config.aws_access_key_id
|
70
|
-
request_config[:secret_access_key] = config.aws_secret_access_key
|
71
|
-
end
|
72
|
-
signer = Aws::Sigv4::Signer.new(request_config)
|
73
|
-
signer.sign_request(http_method: http_method.to_s, url: url, body: body).headers
|
74
|
-
end
|
75
|
-
|
76
76
|
def auth_headers(http_method, url, body)
|
77
|
-
signed_request_headers(http_method, url, body).merge({
|
77
|
+
self.class.signed_request_headers(config, http_method, url, body).merge({
|
78
78
|
'x-amz-access-token' => retrieve_lwa_access_token
|
79
79
|
})
|
80
80
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -36,20 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '2.1'
|
39
|
+
version: '0'
|
43
40
|
type: :runtime
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
46
43
|
requirements:
|
47
44
|
- - ">="
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - "~>"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '2.1'
|
46
|
+
version: '0'
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: aws-sigv4
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,9 +90,6 @@ files:
|
|
96
90
|
- LICENSE
|
97
91
|
- README.md
|
98
92
|
- Rakefile
|
99
|
-
- amz_sp_api-0.2.0.gem
|
100
|
-
- amz_sp_api-0.2.1.gem
|
101
|
-
- amz_sp_api-0.2.2.gem
|
102
93
|
- amz_sp_api.gemspec
|
103
94
|
- codegen.sh
|
104
95
|
- config.json
|
@@ -3129,6 +3120,7 @@ files:
|
|
3129
3120
|
- lib/reports-api-model/spec/models/report_spec.rb
|
3130
3121
|
- lib/reports-api-model/spec/spec_helper.rb
|
3131
3122
|
- lib/reports-api-model/version.rb
|
3123
|
+
- lib/restricted_sp_api_client.rb
|
3132
3124
|
- lib/sales-api-model.rb
|
3133
3125
|
- lib/sales-api-model/.gitignore
|
3134
3126
|
- lib/sales-api-model/.rspec
|
data/amz_sp_api-0.2.0.gem
DELETED
Binary file
|
data/amz_sp_api-0.2.1.gem
DELETED
Binary file
|
data/amz_sp_api-0.2.2.gem
DELETED
Binary file
|