muffin_man 1.4.3 → 1.4.4

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: 9ccdb2717d95f3c15ffc8fd456c0d9e27d9dee72d30fbbabaad7fe7aa5d66280
4
- data.tar.gz: 4709f89efadf9965db58241fd7e9a789ef018d7e422f333f356732e68e3aaa8e
3
+ metadata.gz: 33ab3775741e9ae115fdd18683e7632ad1d9f0da5b5c54ee98fbfdc951cacb45
4
+ data.tar.gz: 57629b160dce923145c0d6784cca34b174fdb757f82e95b9d2c18359c6ee137c
5
5
  SHA512:
6
- metadata.gz: 50976cc1999796d9f6728e65327864461f888507d91a9580590ff7edf666af7fba296f2e8543f97b640ee15cc7aa1b9eb73cbc065fa9055b34d0c0970155e991
7
- data.tar.gz: 4089f8a4c9658a4e9d4cb113b3dec9e1e5d4364a630cdcf880573a2931abd2b3ef5e2187974bb2d71112bc206d510b8130e19f5ea9a21f1964f93e5f360d65b7
6
+ metadata.gz: b27ea646bb4beca9038140758b1b0e8082b5beab76ec8c6af8723a5a5459e4466ef1f90bce09799f5adf5794cf71c4ee030734c8a978470ddb0e0d8bc38ff4c4
7
+ data.tar.gz: 15b93790c3f8d6193e0c2fdf13c2f7f90398fbe0771eb57edf6df651573cd973af630a6a4f78fd56297cf98f6119e9730fe3741883ad81ae36519c5dbdad2024
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.4.4
2
+
3
+ - Support for Tokens API [#17](https://github.com/patterninc/muffin_man/pull/17)
4
+
1
5
  # 1.4.3
2
6
 
3
7
  - Support for getOrderAddress [#16](https://github.com/patterninc/muffin_man/pull/16)
@@ -25,8 +25,13 @@ module MuffinMan
25
25
  NextToken
26
26
  ].freeze
27
27
 
28
- def get_orders(marketplace_ids, params = {})
28
+ PII_DATA_ELEMENTS = %w[
29
+ buyerInfo shippingAddress buyerTaxInformation
30
+ ]
31
+
32
+ def get_orders(marketplace_ids, params = {}, pii_data_elements: [])
29
33
  @local_var_path = "/orders/v0/orders"
34
+ @pii_data_elements = pii_data_elements & PII_DATA_ELEMENTS
30
35
  @query_params = params.slice(*GET_ORDERS_PARAMS)
31
36
  @query_params["MarketplaceIds"] = marketplace_ids
32
37
  @request_type = "GET"
@@ -9,7 +9,8 @@ module MuffinMan
9
9
  attr_reader :refresh_token, :client_id, :client_secret, :aws_access_key_id,
10
10
  :aws_secret_access_key, :sts_iam_role_arn, :sandbox, :config,
11
11
  :region, :request_type, :local_var_path, :query_params,
12
- :request_body, :scope, :access_token_cache_key
12
+ :request_body, :scope, :access_token_cache_key, :credentials,
13
+ :pii_data_elements
13
14
 
14
15
  ACCESS_TOKEN_URL = "https://api.amazon.com/auth/o2/token".freeze
15
16
  SERVICE_NAME = "execute-api".freeze
@@ -30,6 +31,8 @@ module MuffinMan
30
31
  @scope = credentials[:scope]
31
32
  @access_token_cache_key = credentials[:access_token_cache_key]
32
33
  @sandbox = sandbox
34
+ @credentials = credentials
35
+ @pii_data_elements = []
33
36
  Typhoeus::Config.user_agent = ""
34
37
  @config = MuffinMan.configuration
35
38
  end
@@ -146,7 +149,11 @@ module MuffinMan
146
149
  end
147
150
 
148
151
  def headers
149
- access_token = scope ? retrieve_grantless_access_token : retrieve_lwa_access_token
152
+ if requires_rdt_token_for_pii?
153
+ access_token = retrieve_rdt_access_token || retrieve_lwa_access_token
154
+ else
155
+ access_token = scope ? retrieve_grantless_access_token : retrieve_lwa_access_token
156
+ end
150
157
  headers = {
151
158
  "x-amz-access-token" => access_token,
152
159
  "user-agent" => "MuffinMan/#{VERSION} (Language=Ruby)",
@@ -155,6 +162,17 @@ module MuffinMan
155
162
  signed_request.headers.merge(headers)
156
163
  end
157
164
 
165
+ def requires_rdt_token_for_pii?
166
+ pii_data_elements.any?
167
+ end
168
+
169
+ def retrieve_rdt_access_token
170
+ rdt_token_response = Tokens::V20210301.new(credentials, sandbox).create_restricted_data_token(
171
+ @local_var_path, @request_type, pii_data_elements
172
+ )
173
+ JSON.parse(rdt_token_response.body)["restrictedDataToken"]
174
+ end
175
+
158
176
  def derive_aws_region
159
177
  @aws_region ||= AWS_REGION_MAP[region]
160
178
  unless @aws_region
@@ -0,0 +1,19 @@
1
+ module MuffinMan
2
+ module Tokens
3
+ class V20210301 < SpApiClient
4
+ def create_restricted_data_token(path, method, data_elements, target_application: nil)
5
+ @local_var_path = "/tokens/2021-03-01/restrictedDataToken"
6
+ @request_body = {}
7
+ @request_body["targetApplication"] = target_application unless target_application.nil?
8
+ restricted_resources = {
9
+ "method" => method,
10
+ "path" => path,
11
+ "dataElements" => data_elements
12
+ }
13
+ @request_body["restrictedResources"] = [restricted_resources]
14
+ @request_type = "POST"
15
+ call_api
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuffinMan
4
- VERSION = "1.4.3"
4
+ VERSION = "1.4.4"
5
5
  end
data/lib/muffin_man.rb CHANGED
@@ -7,6 +7,7 @@ require "muffin_man/reports/v20210630"
7
7
  require "muffin_man/catalog_items/v20201201"
8
8
  require "muffin_man/finances/v0"
9
9
  require "muffin_man/authorization/v1"
10
+ require "muffin_man/tokens/v20210301"
10
11
 
11
12
  module MuffinMan
12
13
  class Error < StandardError; end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muffin_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin
8
8
  - Jason
9
9
  - Nate
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
13
  date: 2022-07-28 00:00:00.000000000 Z
@@ -116,7 +116,7 @@ dependencies:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: 2.4.4
119
- description:
119
+ description:
120
120
  email:
121
121
  - gavin@pattern.com
122
122
  - jason@pattern.com
@@ -146,13 +146,14 @@ files:
146
146
  - lib/muffin_man/reports/v20210630.rb
147
147
  - lib/muffin_man/solicitations/v1.rb
148
148
  - lib/muffin_man/sp_api_client.rb
149
+ - lib/muffin_man/tokens/v20210301.rb
149
150
  - lib/muffin_man/version.rb
150
151
  - muffin_man.gemspec
151
152
  homepage: https://github.com/patterninc/muffin_man
152
153
  licenses:
153
154
  - MIT
154
155
  metadata: {}
155
- post_install_message:
156
+ post_install_message:
156
157
  rdoc_options: []
157
158
  require_paths:
158
159
  - lib
@@ -167,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubygems_version: 3.2.22
171
- signing_key:
171
+ rubygems_version: 3.0.3
172
+ signing_key:
172
173
  specification_version: 4
173
174
  summary: Amazon Selling Partner API client
174
175
  test_files: []