muffin_man 1.0.1 → 1.2.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/CODE_OF_CONDUCT.md +1 -1
- data/README.md +2 -2
- data/lib/muffin_man/authorization/v1.rb +17 -0
- data/lib/muffin_man/finances/v0.rb +28 -0
- data/lib/muffin_man/reports/v20210630.rb +56 -7
- data/lib/muffin_man/sp_api_client.rb +27 -6
- data/lib/muffin_man/version.rb +1 -1
- data/lib/muffin_man.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed4f016d8045bd0f40bfe4e4ca1be2467fac83ff0549674610c20ad3cba9795
|
4
|
+
data.tar.gz: f955bc7597541ed72eeaeb343d42d83a26892acf31fd3041a287697ae05c6828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faed598abf08c41f6e68b627fddaf35e2ccf1a64b95585167827aff7dd996093e6051c2f8caa7e939fe9545b8c91876c8df50bf74f97620b9cb9137934ff5b36
|
7
|
+
data.tar.gz: 0b9a3a286fcd8dc499fc209a276a11f933270f8e430910281f729b817d2f1eebe684d835e0b73250127888550f0f190353c2f84fe51513d65711136e7b7c90a0
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
|
|
39
39
|
|
40
40
|
## Enforcement
|
41
41
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at opensource@pattern.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
43
|
|
44
44
|
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
45
|
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# MuffinMan
|
2
2
|
|
3
|
-

|
3
|
+
[](https://github.com/patterninc/muffin_man/actions)
|
4
4
|
|
5
|
-
MuffinMan is a ruby interface to the Amazon Selling Partner API. For more information on registering to use the Selling Partner API, see [Amazon's documentation](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md)
|
5
|
+
MuffinMan is a ruby interface to the Amazon Selling Partner API. For more information on registering to use the Selling Partner API, see [Amazon's documentation](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md)
|
6
6
|
|
7
7
|
As of now, this gem only supports portions of the following APIs with more to come:
|
8
8
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MuffinMan
|
2
|
+
module Authorization
|
3
|
+
class V1 < SpApiClient
|
4
|
+
def get_authorization_code(selling_partner_id, developer_id, mws_auth_token)
|
5
|
+
@query_params = {
|
6
|
+
"sellingPartnerId" => selling_partner_id,
|
7
|
+
"developerId" => developer_id,
|
8
|
+
"mwsAuthToken" => mws_auth_token
|
9
|
+
}
|
10
|
+
@query_params = {} if sandbox
|
11
|
+
@request_type = "GET"
|
12
|
+
@local_var_path = "/authorization/v1/authorizationCode"
|
13
|
+
call_api
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MuffinMan
|
2
|
+
module Finances
|
3
|
+
class V0 < SpApiClient
|
4
|
+
|
5
|
+
def list_financial_event_groups(max_results_per_page = nil, financial_event_group_started_before = nil, financial_event_group_started_after = nil, next_token = nil)
|
6
|
+
@local_var_path = "/finances/v0/financialEventGroups"
|
7
|
+
@query_params = {}
|
8
|
+
@query_params['MaxResultsPerPage'] = max_results_per_page unless max_results_per_page.nil?
|
9
|
+
@query_params['FinancialEventGroupStartedBefore'] = financial_event_group_started_before unless financial_event_group_started_before.nil?
|
10
|
+
@query_params['FinancialEventGroupStartedAfter'] = financial_event_group_started_after unless financial_event_group_started_after.nil?
|
11
|
+
@query_params['NextToken'] = next_token unless next_token.nil?
|
12
|
+
@request_type = "GET"
|
13
|
+
call_api
|
14
|
+
end
|
15
|
+
|
16
|
+
def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil, posted_after = nil, posted_before = nil, next_token = nil)
|
17
|
+
@local_var_path = "/finances/v0/financialEventGroups/#{event_group_id}/financialEvents"
|
18
|
+
@query_params = {}
|
19
|
+
@query_params['MaxResultsPerPage'] = max_results_per_page unless max_results_per_page.nil?
|
20
|
+
@query_params['PostedAfter'] = posted_after unless posted_after.nil?
|
21
|
+
@query_params['PostedBefore'] = posted_before unless posted_before.nil?
|
22
|
+
@query_params['NextToken'] = next_token unless next_token.nil?
|
23
|
+
@request_type = "GET"
|
24
|
+
call_api
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,12 +1,40 @@
|
|
1
1
|
module MuffinMan
|
2
2
|
module Reports
|
3
3
|
class V20210630 < SpApiClient
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
SANDBOX_REPORT_TYPES = "FEE_DISCOUNTS_REPORT,GET_AFN_INVENTORY_DATA".freeze
|
5
|
+
SANDBOX_PROCESSING_STATUSES = "IN_QUEUE,IN_PROGRESS".freeze
|
6
|
+
SANDBOX_REPORT_TYPE = "GET_MERCHANT_LISTINGS_ALL_DATA".freeze
|
7
|
+
SANDBOX_START_TIME = "2019-12-10T20:11:24.000Z".freeze
|
8
|
+
SANDBOX_CANCEL_REPORT_ID = "ID".freeze
|
9
|
+
SANDBOX_MARKETPLACE_IDS = %w[
|
10
|
+
A1PA6795UKMFR9
|
11
|
+
ATVPDKIKX0DER
|
12
|
+
].freeze
|
13
|
+
SANDBOX_REPORT_ID = "ID323".freeze
|
14
|
+
SANDBOX_REPORT_DOCUMENT_ID = "0356cf79-b8b0-4226-b4b9-0ee058ea5760".freeze
|
15
|
+
|
16
|
+
GET_REPORTS_PARAMS = %w[
|
17
|
+
reportTypes
|
18
|
+
processingStatuses
|
19
|
+
marketplaceIds
|
20
|
+
pageSize
|
21
|
+
createdSince
|
22
|
+
createdUntil
|
23
|
+
nextToken
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
def get_reports(params = {})
|
27
|
+
@local_var_path = "/reports/2021-06-30/reports"
|
28
|
+
if sandbox
|
29
|
+
params = {
|
30
|
+
"reportTypes" => SANDBOX_REPORT_TYPES,
|
31
|
+
"processingStatuses" => SANDBOX_PROCESSING_STATUSES
|
32
|
+
}
|
33
|
+
end
|
34
|
+
@query_params = params.slice(*GET_REPORTS_PARAMS)
|
35
|
+
@request_type = "GET"
|
36
|
+
call_api
|
37
|
+
end
|
10
38
|
|
11
39
|
def create_report(report_type, marketplace_ids, start_time = nil, end_time = nil, report_options = {})
|
12
40
|
report_type = sandbox ? SANDBOX_REPORT_TYPE : report_type
|
@@ -21,7 +49,28 @@ module MuffinMan
|
|
21
49
|
@request_body["dataStartTime"] = start_time unless start_time.nil?
|
22
50
|
@request_body["dataEndTime"] = end_time unless end_time.nil?
|
23
51
|
@request_body["reportOptions"] = report_options unless report_options.empty?
|
24
|
-
@request_type =
|
52
|
+
@request_type = "POST"
|
53
|
+
call_api
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_report(report_id)
|
57
|
+
report_id = sandbox ? SANDBOX_REPORT_ID : report_id
|
58
|
+
@local_var_path = "/reports/2021-06-30/reports/#{report_id}"
|
59
|
+
@request_type = "GET"
|
60
|
+
call_api
|
61
|
+
end
|
62
|
+
|
63
|
+
def cancel_report(report_id)
|
64
|
+
report_id = sandbox ? SANDBOX_CANCEL_REPORT_ID : report_id
|
65
|
+
@local_var_path = "/reports/2021-06-30/reports/#{report_id}"
|
66
|
+
@request_type = "DELETE"
|
67
|
+
call_api
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_report_document(report_document_id)
|
71
|
+
report_document_id = sandbox ? SANDBOX_REPORT_DOCUMENT_ID : report_document_id
|
72
|
+
@local_var_path = "/reports/2021-06-30/documents/#{report_document_id}"
|
73
|
+
@request_type = "GET"
|
25
74
|
call_api
|
26
75
|
end
|
27
76
|
end
|
@@ -8,7 +8,7 @@ module MuffinMan
|
|
8
8
|
class SpApiClient
|
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, :region, :request_type,
|
11
|
-
:local_var_path, :query_params, :request_body
|
11
|
+
:local_var_path, :query_params, :request_body, :scope
|
12
12
|
ACCESS_TOKEN_URL = 'https://api.amazon.com/auth/o2/token'.freeze
|
13
13
|
SERVICE_NAME = 'execute-api'.freeze
|
14
14
|
AWS_REGION_MAP = {
|
@@ -25,6 +25,7 @@ module MuffinMan
|
|
25
25
|
@aws_secret_access_key = credentials[:aws_secret_access_key]
|
26
26
|
@sts_iam_role_arn = credentials[:sts_iam_role_arn]
|
27
27
|
@region = credentials[:region] || 'na'
|
28
|
+
@scope = credentials[:scope]
|
28
29
|
@sandbox = sandbox
|
29
30
|
Typhoeus::Config.user_agent = ''
|
30
31
|
@config = MuffinMan.configuration
|
@@ -59,10 +60,7 @@ module MuffinMan
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def request
|
62
|
-
|
63
|
-
canonical_uri,
|
64
|
-
params: query_params
|
65
|
-
)
|
63
|
+
Typhoeus::Request.new(canonical_uri, params: query_params)
|
66
64
|
end
|
67
65
|
|
68
66
|
def retrieve_lwa_access_token
|
@@ -94,6 +92,28 @@ module MuffinMan
|
|
94
92
|
JSON.parse(response.body)
|
95
93
|
end
|
96
94
|
|
95
|
+
def retrieve_grantless_access_token
|
96
|
+
# No storage of this type for now
|
97
|
+
request_grantless_access_token["access_token"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def request_grantless_access_token
|
101
|
+
body = {
|
102
|
+
grant_type: "client_credentials",
|
103
|
+
scope: scope,
|
104
|
+
client_id: client_id,
|
105
|
+
client_secret: client_secret
|
106
|
+
}
|
107
|
+
response = Typhoeus.post(
|
108
|
+
ACCESS_TOKEN_URL,
|
109
|
+
body: URI.encode_www_form(body),
|
110
|
+
headers: {
|
111
|
+
"Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8"
|
112
|
+
}
|
113
|
+
)
|
114
|
+
JSON.parse(response.body)
|
115
|
+
end
|
116
|
+
|
97
117
|
def request_sts_token
|
98
118
|
client = Aws::STS::Client.new(
|
99
119
|
region: derive_aws_region,
|
@@ -120,8 +140,9 @@ module MuffinMan
|
|
120
140
|
end
|
121
141
|
|
122
142
|
def headers
|
143
|
+
access_token = scope ? retrieve_grantless_access_token : retrieve_lwa_access_token
|
123
144
|
headers = {
|
124
|
-
'x-amz-access-token' =>
|
145
|
+
'x-amz-access-token' => access_token,
|
125
146
|
'user-agent' => "MuffinMan/#{VERSION} (Language=Ruby)",
|
126
147
|
'content-type' => "application/json"
|
127
148
|
}
|
data/lib/muffin_man/version.rb
CHANGED
data/lib/muffin_man.rb
CHANGED
@@ -3,6 +3,8 @@ require "muffin_man/sp_api_client"
|
|
3
3
|
require "muffin_man/solicitations/v1"
|
4
4
|
require "muffin_man/reports/v20210630"
|
5
5
|
require "muffin_man/catalog_items/v20201201"
|
6
|
+
require "muffin_man/finances/v0"
|
7
|
+
require "muffin_man/authorization/v1"
|
6
8
|
|
7
9
|
module MuffinMan
|
8
10
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muffin_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -123,7 +123,9 @@ files:
|
|
123
123
|
- bin/console
|
124
124
|
- bin/setup
|
125
125
|
- lib/muffin_man.rb
|
126
|
+
- lib/muffin_man/authorization/v1.rb
|
126
127
|
- lib/muffin_man/catalog_items/v20201201.rb
|
128
|
+
- lib/muffin_man/finances/v0.rb
|
127
129
|
- lib/muffin_man/reports/v20210630.rb
|
128
130
|
- lib/muffin_man/solicitations/v1.rb
|
129
131
|
- lib/muffin_man/sp_api_client.rb
|