muffin_man 2.0.6 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d0cac4283872c9438e32917662f5c85654409bf8cea874a12eefc2b3106908e
4
- data.tar.gz: c2108cb8339b7c7ad472f441c24ba1ad193bc2d73225e48a4b0cb779c122fc8a
3
+ metadata.gz: e76d913a68a8015a4b14b3f91083ffb0995f18f4fcb2a32561ab6ebb54606a06
4
+ data.tar.gz: 8c020662237e128bab18104b1e3283cc9f93f21336c952acc4a19b5741088196
5
5
  SHA512:
6
- metadata.gz: 494fb99a4e25b8519d993a14e2e005e9347497b1a277a5e715f99d3ca5c111f44dc55e492dbb63f7be33873923f797aa7fb5b9ec2ca2db69fcf97d6d94c4be1d
7
- data.tar.gz: f048455b4e557c6fa6a585ab711cb445b9de6927b6e14844aaa9ab9ff005f037524192339db3a773d21645b7aa7cc576e0cb420398af0c81cb086eded59cbe8c
6
+ metadata.gz: 29d252e4e79d7e2c548468b5b941673831ca1ff946b4d14cd9dc8ccabece39d148f76a6578aba8b4d0c3251dd83732c1cb24cf139ff76f61e8107bedd9d1cac6
7
+ data.tar.gz: 131ccf94eda1c1131a6f72ff937f5a2f3437278a8b60a445dca95fec48b787dd72a2110fb10a3f606b5cb386a5b0cde4e84162caf680b0b69bbac203f3f48946
data/.rubocop_todo.yml CHANGED
@@ -255,7 +255,6 @@ RSpec/FilePath:
255
255
  - 'spec/muffin_man/solicitations_spec.rb'
256
256
  - 'spec/muffin_man/tokens_spec.rb'
257
257
 
258
-
259
258
  # Offense count: 15
260
259
  # This cop supports safe autocorrection (--autocorrect).
261
260
  RSpec/LeadingSubject:
@@ -363,7 +362,6 @@ Style/FrozenStringLiteralComment:
363
362
  - 'spec/muffin_man/finances_spec.rb'
364
363
  - 'spec/muffin_man/fulfillment_inbound/v0_spec.rb'
365
364
  - 'spec/muffin_man/fulfillment_inbound/v1_spec.rb'
366
- - 'spec/muffin_man/listings_spec.rb'
367
365
  - 'spec/muffin_man/lwa_spec.rb'
368
366
  - 'spec/muffin_man/orders_spec.rb'
369
367
  - 'spec/muffin_man/product_fees_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 2.1.2 [#63](https://github.com/patterninc/muffin_man/pull/63)
2
+
3
+ - Support for patchListingsItem
4
+
5
+ # 2.1.1 [#62](https://github.com/patterninc/muffin_man/pull/62)
6
+
7
+ - SearchCatalogItems validations on keywords & identifiers
8
+
9
+ # 2.1.0 [#58](https://github.com/patterninc/muffin_man/pull/58)
10
+
11
+ - Support for Product Type Definitions
12
+
1
13
  # 2.0.6 [#54](https://github.com/patterninc/muffin_man/pull/54)
2
14
 
3
15
  - Support for getOrder
data/Gemfile CHANGED
@@ -13,4 +13,4 @@ gem "rubocop", "<= 1.43"
13
13
 
14
14
  gem "rubocop-rake"
15
15
 
16
- gem "rubocop-rspec"
16
+ gem "rubocop-rspec", "<=2.20"
data/README.md CHANGED
@@ -56,6 +56,16 @@ JSON.parse(response.body)
56
56
 
57
57
  You can optionally use Amazon's sandbox environment by specifying `client = MuffinMan::Solicitations.new(credentials, sandbox = true)`
58
58
 
59
+ ### Set Custom Logger
60
+
61
+ By default MuffinMan will log to standard out. To customize the logger used:
62
+
63
+ ```ruby
64
+ MuffinMan.configure do |config|
65
+ config.logger = Logger.new('log/sp-api.log')
66
+ end
67
+ ```
68
+
59
69
  ### Access Token Caching
60
70
 
61
71
  You can save and retrieve the LWA refresh token by defining a lambda in your initializers.
@@ -94,6 +104,10 @@ auth_code = resp['payload']['authorizationCode']
94
104
  refresh_token = MuffinMan::Lwa::AuthHelper.get_refresh_token(CLIENT_ID, CLIENT_SECRET, auth_code)
95
105
  ```
96
106
 
107
+ ### Debugging
108
+
109
+ To use Typheous' verbose mode set env variable `MUFFIN_MAN_DEBUG=true`
110
+
97
111
  ## Contributing
98
112
 
99
113
  Bug reports and pull requests are welcome on GitHub at https://github.com/patterninc/muffin_man. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/patterninc/muffin_man/blob/master/CODE_OF_CONDUCT.md).
@@ -30,6 +30,7 @@ module MuffinMan
30
30
  end
31
31
  @keywords = keywords.is_a?(Array) ? keywords : [keywords]
32
32
  @identifiers = params["identifiers"].is_a?(Array) ? params["identifiers"] : [params["identifiers"]]
33
+ validate_keywords_and_identifiers
33
34
  @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
34
35
  @params = params
35
36
  @local_var_path = "/catalog/#{api_version}/items"
@@ -68,6 +69,11 @@ module MuffinMan
68
69
  def search_catalog_items_params
69
70
  BASE_SEARCH_CATALOG_ITEMS_PARAMS + self.class::SEARCH_CATALOG_ITEMS_PARAMS
70
71
  end
72
+
73
+ def validate_keywords_and_identifiers
74
+ raise MuffinMan::Error, "Keywords cannot be used with Identifiers" if @keywords.any? && @identifiers.any?
75
+ raise MuffinMan::Error, "Keywords or Identifiers must be present" if @keywords.none? && @identifiers.none?
76
+ end
71
77
  end
72
78
  end
73
79
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuffinMan
4
+ module EnableLogger
5
+ LOGGING_ENABLED = true
6
+
7
+ def log_request_and_response(level, res)
8
+ log_info = "REQUEST\n
9
+ canonical_uri:#{canonical_uri}\n\n
10
+ query_params:#{query_params}\n\n
11
+ RESPONSE\n
12
+ response_headers=#{res.headers}\n\n
13
+ response_body=#{res.body}\n\n
14
+ "
15
+ MuffinMan.logger.send(level, log_info)
16
+ end
17
+ end
18
+ end
@@ -1,6 +1,10 @@
1
+ require "muffin_man/enable_logger"
2
+
1
3
  module MuffinMan
2
4
  module Finances
3
5
  class V0 < SpApiClient
6
+ include EnableLogger
7
+
4
8
  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)
5
9
  @local_var_path = "/finances/v0/financialEventGroups"
6
10
  @query_params = {}
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuffinMan
4
+ module Listings
5
+ class V20200901 < SpApiClient
6
+ REQUIREMENTS = %w[LISTING LISTING_PRODUCT_ONLY LISTING_OFFER_ONLY].freeze
7
+ REQUIREMENTS_ENFORCED = %w[ENFORCED NOT_ENFORCED].freeze
8
+ LOCALE = %w[DEFAULT ar ar_AE de de_DE en en_AE en_AU en_CA en_GB en_IN en_SG en_US es es_ES es_MX es_US fr
9
+ fr_CA fr_FR it it_IT ja ja_JP nl nl_NL pl pl_PL pt pt_BR pt_PT sv sv_SE tr tr_TR zh zh_CN zh_TW]
10
+ .freeze
11
+ PRODUCT_TYPES_PATH = "/definitions/2020-09-01/productTypes"
12
+
13
+ def search_definitions_product_types(marketplace_ids, keywords = nil)
14
+ @local_var_path = PRODUCT_TYPES_PATH
15
+ @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
16
+ @query_params = { "marketplaceIds" => @marketplace_ids.join(",") }
17
+ @query_params["keywords"] = keywords if keywords.present?
18
+ @request_type = "GET"
19
+ call_api
20
+ end
21
+
22
+ # rubocop:disable Metrics/CyclomaticComplexity
23
+ # rubocop:disable Metrics/PerceivedComplexity
24
+ def get_definitions_product_type(product_type, marketplace_ids, options = {})
25
+ options = options.with_indifferent_access
26
+ @local_var_path = "#{PRODUCT_TYPES_PATH}/#{product_type}"
27
+ @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
28
+ @query_params = { "marketplaceIds" => @marketplace_ids.join(",") }
29
+ @query_params["sellerId"] = options["sellerId"] if options["sellerId"]
30
+ @query_params["productTypeVersion"] = options["productTypeVersion"].upcase if options["productTypeVersion"]
31
+ if REQUIREMENTS.include?(options["requirements"]&.upcase)
32
+ @query_params["requirements"] = options["requirements"].upcase
33
+ end
34
+
35
+ if REQUIREMENTS_ENFORCED.include?(options["requirementsEnforced"]&.upcase)
36
+ @query_params["requirementsEnforced"] = options["requirementsEnforced"].upcase
37
+ end
38
+
39
+ @query_params["locale"] = options["locale"] if LOCALE.include?(options["locale"])
40
+
41
+ @request_type = "GET"
42
+ call_api
43
+ end
44
+ # rubocop:enable Metrics/CyclomaticComplexity
45
+ # rubocop:enable Metrics/PerceivedComplexity
46
+ end
47
+ end
48
+ end
@@ -47,6 +47,24 @@ module MuffinMan
47
47
  @request_type = "DELETE"
48
48
  call_api
49
49
  end
50
+
51
+ def patch_listings_item(seller_id, sku, marketplace_ids, product_type, patches, included_data: [], mode: nil,
52
+ issue_locale: nil)
53
+ @local_var_path = "/listings/2021-08-01/items/#{seller_id}/#{sku}"
54
+ @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
55
+ @query_params = {
56
+ "marketplaceIds" => @marketplace_ids.join(",")
57
+ }
58
+ @query_params["includedData"] = included_data.join(",") if included_data.any?
59
+ @query_params["mode"] = mode if mode
60
+ @query_params["issueLocale"] = issue_locale if issue_locale
61
+ @request_body = {
62
+ "productType" => product_type,
63
+ "patches" => patches
64
+ }
65
+ @request_type = "PATCH"
66
+ call_api
67
+ end
50
68
  end
51
69
  end
52
70
  end
@@ -57,6 +57,7 @@ module MuffinMan
57
57
  report_id = sandbox ? SANDBOX_REPORT_ID : report_id
58
58
  @local_var_path = "/reports/2021-06-30/reports/#{report_id}"
59
59
  @request_type = "GET"
60
+ @request_body = nil
60
61
  call_api
61
62
  end
62
63
 
@@ -42,14 +42,20 @@ module MuffinMan
42
42
  private
43
43
 
44
44
  def call_api
45
- Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts)
45
+ res = Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts)
46
+ if self.class.const_defined?("LOGGING_ENABLED")
47
+ level = res.code.to_s.match?(/2\d{2}/) ? :info : :error
48
+ log_request_and_response(level, res)
49
+ end
50
+ res
46
51
  rescue SpApiAuthError => e
47
52
  e.auth_response
48
53
  end
49
54
 
50
55
  def request_opts
51
56
  opts = { headers: headers }
52
- opts[:body] = request_body.to_json if request_body
57
+ opts[:verbose] = true if ENV.fetch("MUFFIN_MAN_DEBUG", nil) == "true"
58
+ opts[:body] = request_body.to_json if request_body && request_type != "GET" && request_type != "HEAD"
53
59
  opts
54
60
  end
55
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuffinMan
4
- VERSION = "2.0.6"
4
+ VERSION = "2.1.2"
5
5
  end
data/lib/muffin_man.rb CHANGED
@@ -12,6 +12,7 @@ require "muffin_man/authorization/v1"
12
12
  require "muffin_man/tokens/v20210301"
13
13
  require "muffin_man/product_pricing/v0"
14
14
  require "muffin_man/listings/v20210801"
15
+ require "muffin_man/listings/v20200901"
15
16
  require "muffin_man/fulfillment_inbound/v0"
16
17
  require "muffin_man/fulfillment_inbound/v1"
17
18
  require "muffin_man/fulfillment_outbound/v20200701"
@@ -34,15 +35,19 @@ module MuffinMan
34
35
  end
35
36
 
36
37
  class << self
37
- attr_accessor :configuration
38
+ attr_accessor :configuration, :logger
38
39
  end
39
40
 
40
41
  def self.configure
41
42
  self.configuration ||= Configuration.new
42
43
  yield(configuration)
44
+ self.logger = configuration.logger if configuration.logger
43
45
  end
44
46
 
45
47
  class Configuration
46
- attr_accessor :save_access_token, :get_access_token
48
+ attr_accessor :save_access_token, :get_access_token, :logger
47
49
  end
48
50
  end
51
+
52
+ # Set default logger
53
+ MuffinMan.logger = Logger.new($stdout)
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: 2.0.6
4
+ version: 2.1.2
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: 2023-06-28 00:00:00.000000000 Z
13
+ date: 2024-05-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -157,12 +157,14 @@ files:
157
157
  - lib/muffin_man/catalog_items/base_api.rb
158
158
  - lib/muffin_man/catalog_items/v20201201.rb
159
159
  - lib/muffin_man/catalog_items/v20220401.rb
160
+ - lib/muffin_man/enable_logger.rb
160
161
  - lib/muffin_man/fba_inventory/v1.rb
161
162
  - lib/muffin_man/feeds/v20210630.rb
162
163
  - lib/muffin_man/finances/v0.rb
163
164
  - lib/muffin_man/fulfillment_inbound/v0.rb
164
165
  - lib/muffin_man/fulfillment_inbound/v1.rb
165
166
  - lib/muffin_man/fulfillment_outbound/v20200701.rb
167
+ - lib/muffin_man/listings/v20200901.rb
166
168
  - lib/muffin_man/listings/v20210801.rb
167
169
  - lib/muffin_man/lwa/auth_helper.rb
168
170
  - lib/muffin_man/merchant_fulfillment/v0.rb