From 1f5809b49833e5f3282d85c5431fb637a92ffad3 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 10:55:56 +0530 Subject: [PATCH 01/22] [DIST-10392] add logging functionality 1) add muffin logger --- lib/muffin_man/muffin_logger.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/muffin_man/muffin_logger.rb diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb new file mode 100644 index 0000000..87ebaa4 --- /dev/null +++ b/lib/muffin_man/muffin_logger.rb @@ -0,0 +1,15 @@ +require 'logger' +module MuffinMan + class MuffinLogger + + def self.logger + defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + end + + [:debug, :info, :warn, :error, :fatal].each do |level| + define_method(level) do |message| + MuffinLogger.logger.send(level, message) + end + end + end +end From ae77b1fbea8e0185ed8e69d00cdebca9b2e9b367 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 14:35:00 +0530 Subject: [PATCH 02/22] [DIST-10392] add logging functionality 1) add request and response logging for finance API call --- lib/muffin_man/finances/v0.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/muffin_man/finances/v0.rb b/lib/muffin_man/finances/v0.rb index b584a4f..5992a61 100644 --- a/lib/muffin_man/finances/v0.rb +++ b/lib/muffin_man/finances/v0.rb @@ -15,7 +15,10 @@ def list_financial_event_groups(max_results_per_page = nil, financial_event_grou end @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" - call_api + res = call_api + level = (res.code == 200) ? :info : :error + log_request_and_response(level, res) + res end def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil, posted_after = nil, posted_before = nil, next_token = nil) @@ -26,7 +29,21 @@ def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil @query_params["PostedBefore"] = posted_before unless posted_before.nil? @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" - call_api + res = call_api + level = (res.code == 200) ? :info : :error + log_request_and_response(level, res) + res + end + + def log_request_and_response(level, res) + log_info = "REQUEST\n + canonical_uri:#{canonical_uri}\n\n + query_params:#{query_params}\n\n + RESPONSE\n + response_headers=#{res.headers}\n\n + response_body=#{res.body}\n\n + " + MuffinLogger.send(level, log_info) end end end From 720c96db7eaf624ff60d6a3892187f76305e97c5 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 14:44:11 +0530 Subject: [PATCH 03/22] [DIST-10392] add logging functionality 1) fix call to logger --- lib/muffin_man/finances/v0.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/muffin_man/finances/v0.rb b/lib/muffin_man/finances/v0.rb index 5992a61..9858d6e 100644 --- a/lib/muffin_man/finances/v0.rb +++ b/lib/muffin_man/finances/v0.rb @@ -1,3 +1,4 @@ +require 'muffin_man/muffin_logger' module MuffinMan module Finances class V0 < SpApiClient @@ -43,7 +44,7 @@ def log_request_and_response(level, res) response_headers=#{res.headers}\n\n response_body=#{res.body}\n\n " - MuffinLogger.send(level, log_info) + MuffinLogger.logger.send(level, log_info) end end end From 5131edc40ef346e6c95136b6d9c131784e91c39b Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 15:01:20 +0530 Subject: [PATCH 04/22] [DIST-10392] add logging functionality 1) rubocop fixes --- lib/muffin_man/finances/v0.rb | 6 +++--- lib/muffin_man/muffin_logger.rb | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/muffin_man/finances/v0.rb b/lib/muffin_man/finances/v0.rb index 9858d6e..48a9a17 100644 --- a/lib/muffin_man/finances/v0.rb +++ b/lib/muffin_man/finances/v0.rb @@ -1,4 +1,4 @@ -require 'muffin_man/muffin_logger' +require "muffin_man/muffin_logger" module MuffinMan module Finances class V0 < SpApiClient @@ -17,7 +17,7 @@ def list_financial_event_groups(max_results_per_page = nil, financial_event_grou @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" res = call_api - level = (res.code == 200) ? :info : :error + level = res.code == 200 ? :info : :error log_request_and_response(level, res) res end @@ -31,7 +31,7 @@ def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" res = call_api - level = (res.code == 200) ? :info : :error + level = res.code == 200 ? :info : :error log_request_and_response(level, res) res end diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb index 87ebaa4..7f8e21b 100644 --- a/lib/muffin_man/muffin_logger.rb +++ b/lib/muffin_man/muffin_logger.rb @@ -1,12 +1,13 @@ -require 'logger' +# frozen_string_literal: true + +require "logger" module MuffinMan class MuffinLogger - def self.logger - defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + defined?(Rails) ? Rails.logger : Logger.new($stdout) end - [:debug, :info, :warn, :error, :fatal].each do |level| + %i[debug info warn error fatal].each do |level| define_method(level) do |message| MuffinLogger.logger.send(level, message) end From a6a55a5266bad2832d879658cc3103c640fb38a2 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 16:29:49 +0530 Subject: [PATCH 05/22] [DIST-10392] add logging functionality 1) add log enabler --- lib/muffin_man/enable_logger.rb | 7 +++++++ lib/muffin_man/finances/v0.rb | 26 ++++++-------------------- lib/muffin_man/sp_api_client.rb | 19 ++++++++++++++++++- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 lib/muffin_man/enable_logger.rb diff --git a/lib/muffin_man/enable_logger.rb b/lib/muffin_man/enable_logger.rb new file mode 100644 index 0000000..797a739 --- /dev/null +++ b/lib/muffin_man/enable_logger.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module MuffinMan + module EnableLogger + LOGGING_ENABLED = true + end +end diff --git a/lib/muffin_man/finances/v0.rb b/lib/muffin_man/finances/v0.rb index 48a9a17..311e0d1 100644 --- a/lib/muffin_man/finances/v0.rb +++ b/lib/muffin_man/finances/v0.rb @@ -1,7 +1,10 @@ -require "muffin_man/muffin_logger" +require "muffin_man/enable_logger" + module MuffinMan module Finances class V0 < SpApiClient + include EnableLogger + 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) @local_var_path = "/finances/v0/financialEventGroups" @query_params = {} @@ -16,10 +19,7 @@ def list_financial_event_groups(max_results_per_page = nil, financial_event_grou end @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" - res = call_api - level = res.code == 200 ? :info : :error - log_request_and_response(level, res) - res + call_api end def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil, posted_after = nil, posted_before = nil, next_token = nil) @@ -30,21 +30,7 @@ def list_financial_events_by_group_id(event_group_id, max_results_per_page = nil @query_params["PostedBefore"] = posted_before unless posted_before.nil? @query_params["NextToken"] = next_token unless next_token.nil? @request_type = "GET" - res = call_api - level = res.code == 200 ? :info : :error - log_request_and_response(level, res) - res - end - - def log_request_and_response(level, res) - log_info = "REQUEST\n - canonical_uri:#{canonical_uri}\n\n - query_params:#{query_params}\n\n - RESPONSE\n - response_headers=#{res.headers}\n\n - response_body=#{res.body}\n\n - " - MuffinLogger.logger.send(level, log_info) + call_api end end end diff --git a/lib/muffin_man/sp_api_client.rb b/lib/muffin_man/sp_api_client.rb index 978db75..bbd5649 100644 --- a/lib/muffin_man/sp_api_client.rb +++ b/lib/muffin_man/sp_api_client.rb @@ -3,6 +3,7 @@ require "aws-sdk-core" require "typhoeus" require "securerandom" +require "muffin_man/muffin_logger" module MuffinMan class SpApiClient @@ -42,7 +43,12 @@ def initialize(credentials, sandbox = false) private def call_api - Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts) + res = Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts) + if self.class.const_defined?('LOGGING_ENABLED') + level = res.code == 200 ? :info : :error + log_request_and_response(level, res) + end + res rescue SpApiAuthError => e e.auth_response end @@ -196,5 +202,16 @@ def unprocessable_entity(errors) def sp_api_params(params) params.to_h.transform_keys { |key| key.to_s.split("_").map.with_index { |x, i| i.positive? ? x.capitalize : x }.join } end + + def log_request_and_response(level, res) + log_info = "REQUEST\n + canonical_uri:#{canonical_uri}\n\n + query_params:#{query_params}\n\n + RESPONSE\n + response_headers=#{res.headers}\n\n + response_body=#{res.body}\n\n + " + MuffinLogger.logger.send(level, log_info) + end end end From b12208c511ea8265b8c00faa0b80a4a417643dd6 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 16:38:23 +0530 Subject: [PATCH 06/22] [DIST-10392] add logging functionality 1) move log_request_and_response to enable_logger --- lib/muffin_man/enable_logger.rb | 11 +++++++++++ lib/muffin_man/sp_api_client.rb | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/muffin_man/enable_logger.rb b/lib/muffin_man/enable_logger.rb index 797a739..b8447b1 100644 --- a/lib/muffin_man/enable_logger.rb +++ b/lib/muffin_man/enable_logger.rb @@ -3,5 +3,16 @@ module MuffinMan module EnableLogger LOGGING_ENABLED = true + + def log_request_and_response(level, res) + log_info = "REQUEST\n + canonical_uri:#{canonical_uri}\n\n + query_params:#{query_params}\n\n + RESPONSE\n + response_headers=#{res.headers}\n\n + response_body=#{res.body}\n\n + " + MuffinLogger.logger.send(level, log_info) + end end end diff --git a/lib/muffin_man/sp_api_client.rb b/lib/muffin_man/sp_api_client.rb index bbd5649..d385e05 100644 --- a/lib/muffin_man/sp_api_client.rb +++ b/lib/muffin_man/sp_api_client.rb @@ -202,16 +202,5 @@ def unprocessable_entity(errors) def sp_api_params(params) params.to_h.transform_keys { |key| key.to_s.split("_").map.with_index { |x, i| i.positive? ? x.capitalize : x }.join } end - - def log_request_and_response(level, res) - log_info = "REQUEST\n - canonical_uri:#{canonical_uri}\n\n - query_params:#{query_params}\n\n - RESPONSE\n - response_headers=#{res.headers}\n\n - response_body=#{res.body}\n\n - " - MuffinLogger.logger.send(level, log_info) - end end end From 2cb291bacbc2f2789f2e268439b10bdd8b0d9f88 Mon Sep 17 00:00:00 2001 From: mukteshd Date: Tue, 8 Aug 2023 16:43:44 +0530 Subject: [PATCH 07/22] [DIST-10392] add logging functionality 1) fix rubocop offence --- lib/muffin_man/sp_api_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/muffin_man/sp_api_client.rb b/lib/muffin_man/sp_api_client.rb index d385e05..dbd5ec3 100644 --- a/lib/muffin_man/sp_api_client.rb +++ b/lib/muffin_man/sp_api_client.rb @@ -44,7 +44,7 @@ def initialize(credentials, sandbox = false) def call_api res = Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts) - if self.class.const_defined?('LOGGING_ENABLED') + if self.class.const_defined?("LOGGING_ENABLED") level = res.code == 200 ? :info : :error log_request_and_response(level, res) end From 90e6e9824e651ced5d900f69692469b132b849d3 Mon Sep 17 00:00:00 2001 From: harishspattern Date: Thu, 31 Aug 2023 20:40:36 +0530 Subject: [PATCH 08/22] DIST-10392 Added logger attribute in MuffinMan module --- lib/muffin_man.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index ccdefef..c5f89cb 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -20,6 +20,7 @@ require "muffin_man/feeds/v20210630" require "muffin_man/notifications/v1" require "muffin_man/merchant_fulfillment/v0" +require "muffin_man/muffin_logger" module MuffinMan class Error < StandardError; end @@ -34,7 +35,7 @@ def initialize(auth_response) end class << self - attr_accessor :configuration + attr_accessor :configuration, :logger end def self.configure From 92170cb482641d6d48ad046e5c38d0a0a591560c Mon Sep 17 00:00:00 2001 From: harishspattern Date: Tue, 5 Sep 2023 16:39:51 +0530 Subject: [PATCH 09/22] DIST-10392 Moved method creation in muffinman module --- lib/muffin_man.rb | 14 ++++++++++++-- lib/muffin_man/enable_logger.rb | 2 +- lib/muffin_man/muffin_logger.rb | 16 ++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index c5f89cb..63ad3b0 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -20,7 +20,7 @@ require "muffin_man/feeds/v20210630" require "muffin_man/notifications/v1" require "muffin_man/merchant_fulfillment/v0" -require "muffin_man/muffin_logger" +require "logger" module MuffinMan class Error < StandardError; end @@ -35,7 +35,7 @@ def initialize(auth_response) end class << self - attr_accessor :configuration, :logger + attr_accessor :configuration, :log end def self.configure @@ -43,6 +43,16 @@ def self.configure yield(configuration) end + def self.logger + self.log ||= Logger.new($stdout) + end + + %i[debug info warn error fatal].each do |level| + define_method(level) do |message| + MuffinLogger.log.send(level, message) + end + end + class Configuration attr_accessor :save_access_token, :get_access_token end diff --git a/lib/muffin_man/enable_logger.rb b/lib/muffin_man/enable_logger.rb index b8447b1..ef9ef4b 100644 --- a/lib/muffin_man/enable_logger.rb +++ b/lib/muffin_man/enable_logger.rb @@ -12,7 +12,7 @@ def log_request_and_response(level, res) response_headers=#{res.headers}\n\n response_body=#{res.body}\n\n " - MuffinLogger.logger.send(level, log_info) + MuffinMan.logger.send(level, log_info) end end end diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb index 7f8e21b..7cab3e5 100644 --- a/lib/muffin_man/muffin_logger.rb +++ b/lib/muffin_man/muffin_logger.rb @@ -3,14 +3,14 @@ require "logger" module MuffinMan class MuffinLogger - def self.logger - defined?(Rails) ? Rails.logger : Logger.new($stdout) - end + # def self.logger + # defined?(Rails) ? Rails.logger : Logger.new($stdout) + # end - %i[debug info warn error fatal].each do |level| - define_method(level) do |message| - MuffinLogger.logger.send(level, message) - end - end + # %i[debug info warn error fatal].each do |level| + # define_method(level) do |message| + # MuffinLogger.logger.send(level, message) + # end + # end end end From d9e8cf43e636e83679ea6f093128dddcdb84f0e3 Mon Sep 17 00:00:00 2001 From: harishspattern Date: Tue, 5 Sep 2023 19:30:04 +0530 Subject: [PATCH 10/22] DIST-10392 Added configuration for logger --- lib/muffin_man.rb | 14 ++++---------- lib/muffin_man/muffin_logger.rb | 17 +++++++++-------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index 63ad3b0..72bfdce 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -20,7 +20,7 @@ require "muffin_man/feeds/v20210630" require "muffin_man/notifications/v1" require "muffin_man/merchant_fulfillment/v0" -require "logger" +require "muffin_man/muffin_logger" module MuffinMan class Error < StandardError; end @@ -35,7 +35,7 @@ def initialize(auth_response) end class << self - attr_accessor :configuration, :log + attr_accessor :configuration, :logger end def self.configure @@ -44,16 +44,10 @@ def self.configure end def self.logger - self.log ||= Logger.new($stdout) - end - - %i[debug info warn error fatal].each do |level| - define_method(level) do |message| - MuffinLogger.log.send(level, message) - end + MuffinMan::MuffinLogger.logger end class Configuration - attr_accessor :save_access_token, :get_access_token + attr_accessor :save_access_token, :get_access_token, :log_with end end diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb index 7cab3e5..e236871 100644 --- a/lib/muffin_man/muffin_logger.rb +++ b/lib/muffin_man/muffin_logger.rb @@ -3,14 +3,15 @@ require "logger" module MuffinMan class MuffinLogger - # def self.logger - # defined?(Rails) ? Rails.logger : Logger.new($stdout) - # end - # %i[debug info warn error fatal].each do |level| - # define_method(level) do |message| - # MuffinLogger.logger.send(level, message) - # end - # end + def self.logger + MuffinMan.configuration.log_with || Logger.new($stdout) + end + + %i[debug info warn error fatal].each do |level| + define_method(level) do |message| + MuffinLogger.logger.send(level, message) + end + end end end From 8aa2fb57d61fe9be197af0253b13ebd6dfd4807e Mon Sep 17 00:00:00 2001 From: harishspattern Date: Wed, 6 Sep 2023 09:42:02 +0530 Subject: [PATCH 11/22] DIST-10392 FIX test cases --- lib/muffin_man.rb | 2 +- lib/muffin_man/muffin_logger.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index 72bfdce..f8a01ee 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -35,7 +35,7 @@ def initialize(auth_response) end class << self - attr_accessor :configuration, :logger + attr_accessor :configuration end def self.configure diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb index e236871..fc90188 100644 --- a/lib/muffin_man/muffin_logger.rb +++ b/lib/muffin_man/muffin_logger.rb @@ -5,7 +5,7 @@ module MuffinMan class MuffinLogger def self.logger - MuffinMan.configuration.log_with || Logger.new($stdout) + MuffinMan.configuration&.log_with || Logger.new($stdout) end %i[debug info warn error fatal].each do |level| From e4b399cb53cb100a2e75ff1ed672ba92255bec47 Mon Sep 17 00:00:00 2001 From: harishspattern Date: Wed, 6 Sep 2023 09:58:47 +0530 Subject: [PATCH 12/22] DIST-10392 Rubocop Fixes --- lib/muffin_man/muffin_logger.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb index fc90188..418c477 100644 --- a/lib/muffin_man/muffin_logger.rb +++ b/lib/muffin_man/muffin_logger.rb @@ -3,7 +3,6 @@ require "logger" module MuffinMan class MuffinLogger - def self.logger MuffinMan.configuration&.log_with || Logger.new($stdout) end From dc767ca81bc168487510615be25cc7ed18e0a3ff Mon Sep 17 00:00:00 2001 From: Nate Salisbury Date: Sun, 10 Sep 2023 23:55:11 -0600 Subject: [PATCH 13/22] Reorganize Logging Setup (#57) * Reorganize MuffinMan logging setup * Support using Typheous verbose mode with ENV variable --- README.md | 14 ++++++++++++++ lib/muffin_man.rb | 13 ++++++------- lib/muffin_man/muffin_logger.rb | 16 ---------------- lib/muffin_man/sp_api_client.rb | 4 ++-- 4 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 lib/muffin_man/muffin_logger.rb diff --git a/README.md b/README.md index 7154bc5..7588a5a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,16 @@ JSON.parse(response.body) You can optionally use Amazon's sandbox environment by specifying `client = MuffinMan::Solicitations.new(credentials, sandbox = true)` +### Set Custom Logger + +By default MuffinMan will log to standard out. To customize the logger used: + +```ruby +MuffinMan.configure do |config| + config.logger = Logger.new('log/sp-api.log') +end +``` + ### Access Token Caching 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'] refresh_token = MuffinMan::Lwa::AuthHelper.get_refresh_token(CLIENT_ID, CLIENT_SECRET, auth_code) ``` +### Debugging + +To use Typheous' verbose mode set env variable `MUFFIN_MAN_DEBUG=true` + ## Contributing 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). diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index f8a01ee..22aadcb 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -20,7 +20,6 @@ require "muffin_man/feeds/v20210630" require "muffin_man/notifications/v1" require "muffin_man/merchant_fulfillment/v0" -require "muffin_man/muffin_logger" module MuffinMan class Error < StandardError; end @@ -35,19 +34,19 @@ def initialize(auth_response) end class << self - attr_accessor :configuration + attr_accessor :configuration, :logger end def self.configure self.configuration ||= Configuration.new yield(configuration) - end - - def self.logger - MuffinMan::MuffinLogger.logger + self.logger = configuration.logger if configuration.logger end class Configuration - attr_accessor :save_access_token, :get_access_token, :log_with + attr_accessor :save_access_token, :get_access_token, :logger end end + +# Set default logger +MuffinMan.logger = Logger.new($stdout) diff --git a/lib/muffin_man/muffin_logger.rb b/lib/muffin_man/muffin_logger.rb deleted file mode 100644 index 418c477..0000000 --- a/lib/muffin_man/muffin_logger.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require "logger" -module MuffinMan - class MuffinLogger - def self.logger - MuffinMan.configuration&.log_with || Logger.new($stdout) - end - - %i[debug info warn error fatal].each do |level| - define_method(level) do |message| - MuffinLogger.logger.send(level, message) - end - end - end -end diff --git a/lib/muffin_man/sp_api_client.rb b/lib/muffin_man/sp_api_client.rb index dbd5ec3..c0f4a25 100644 --- a/lib/muffin_man/sp_api_client.rb +++ b/lib/muffin_man/sp_api_client.rb @@ -3,7 +3,6 @@ require "aws-sdk-core" require "typhoeus" require "securerandom" -require "muffin_man/muffin_logger" module MuffinMan class SpApiClient @@ -45,7 +44,7 @@ def initialize(credentials, sandbox = false) def call_api res = Typhoeus.send(request_type.downcase.to_sym, request.url, request_opts) if self.class.const_defined?("LOGGING_ENABLED") - level = res.code == 200 ? :info : :error + level = res.code.to_s.match?(/2\d{2}/) ? :info : :error log_request_and_response(level, res) end res @@ -56,6 +55,7 @@ def call_api def request_opts opts = { headers: headers } opts[:body] = request_body.to_json if request_body + opts[:verbose] = true if ENV.fetch("MUFFIN_MAN_DEBUG", nil) == "true" opts end From 5dc146e0ac1df3ae69f94a1e684677a1bf57a666 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Thu, 21 Sep 2023 17:16:44 +0530 Subject: [PATCH 14/22] INT-3882: add product-type-definition --- lib/muffin_man.rb | 1 + lib/muffin_man/listings/v20200901.rb | 44 +++++ lib/muffin_man/version.rb | 2 +- spec/muffin_man/listings/v20200901_spec.rb | 31 ++++ .../v20210801_spec.rb} | 0 .../support/get_definitions_product_type.json | 152 ++++++++++++++++++ .../search_definitions_product_types.json | 10 ++ spec/support/sp_api_helpers.rb | 11 ++ 8 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 lib/muffin_man/listings/v20200901.rb create mode 100644 spec/muffin_man/listings/v20200901_spec.rb rename spec/muffin_man/{listings_spec.rb => listings/v20210801_spec.rb} (100%) create mode 100644 spec/support/get_definitions_product_type.json create mode 100644 spec/support/search_definitions_product_types.json diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index 22aadcb..9c93a79 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -12,6 +12,7 @@ require "muffin_man/tokens/v20210301" require "muffin_man/product_pricing/v0" require "muffin_man/listings/v20210801" +require "muffin_man/listings/V20200901" require "muffin_man/fulfillment_inbound/v0" require "muffin_man/fulfillment_inbound/v1" require "muffin_man/fulfillment_outbound/v20200701" diff --git a/lib/muffin_man/listings/v20200901.rb b/lib/muffin_man/listings/v20200901.rb new file mode 100644 index 0000000..01a49dd --- /dev/null +++ b/lib/muffin_man/listings/v20200901.rb @@ -0,0 +1,44 @@ +module MuffinMan + module Listings + class V20200901 < SpApiClient + + REQUIREMENTS = %w(LISTING LISTING_PRODUCT_ONLY LISTING_OFFER_ONLY).freeze + REQUIREMENTS_ENFORCED = %w(ENFORCED NOT_ENFORCED).freeze + 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 + 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).freeze + + def search_definitions_product_types(marketplace_ids, keywords = nil) + @local_var_path = "/definitions/2020-09-01/productTypes" + @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] + @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } + @query_params["keywords"] = keywords if keywords.present? + @request_type = "GET" + call_api + end + + def get_definitions_product_type(product_type, marketplace_ids, options = {}) + options = options.with_indifferent_access + @local_var_path = "/definitions/2020-09-01/productTypes/#{product_type}" + @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] + @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } + @query_params["sellerId"] = options["sellerId"] if options["sellerId"] + @query_params["productTypeVersion"] = options["productTypeVersion"].upcase if options["productTypeVersion"] + if REQUIREMENTS.include?(options["requirements"]&.upcase) + @query_params["requirements"] = options["requirements"].upcase + end + + if REQUIREMENTS_ENFORCED.include?(options["requirementsEnforced"]&.upcase) + @query_params["requirementsEnforced"] = options["requirementsEnforced"].upcase + end + + if LOCALE.include?(options["locale"]) + @query_params["locale"] = options["locale"] + end + + @request_type = "GET" + call_api + end + end + end +end + \ No newline at end of file diff --git a/lib/muffin_man/version.rb b/lib/muffin_man/version.rb index e83c580..9a1e01a 100644 --- a/lib/muffin_man/version.rb +++ b/lib/muffin_man/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MuffinMan - VERSION = "2.0.6" + VERSION = "2.0.7" end diff --git a/spec/muffin_man/listings/v20200901_spec.rb b/spec/muffin_man/listings/v20200901_spec.rb new file mode 100644 index 0000000..6c8c82c --- /dev/null +++ b/spec/muffin_man/listings/v20200901_spec.rb @@ -0,0 +1,31 @@ +RSpec.describe MuffinMan::Listings::V20200901 do + before do + stub_request_access_token + end + + let(:keyword) { "LUGGAGE" } + let(:product_type) { "YARN" } + let(:amazon_marketplace_id) { "DRURYLANE" } + + subject(:listings_client) { described_class.new(credentials) } + + describe "search_definitions_product_types" do + before { stub_search_definitions_product_types } + it "makes a request to search definitions product types" do + response = listings_client.search_definitions_product_types(amazon_marketplace_id, keyword) + expect(response.response_code).to eq(200) + expect(JSON.parse(response.body).dig("productTypes").first["name"]).to eq(keyword) + end + end + + describe "get_definitions_product_type" do + before { stub_get_definitions_product_type } + it "makes a request to get definitions product type" do + options = { requirementsEnforced: "ENFORCED", locale: "en_US" } + response = listings_client.get_definitions_product_type(product_type, amazon_marketplace_id, options) + expect(response.response_code).to eq(200) + expect(JSON.parse(response.body).dig("productType")).to eq(product_type) + end + end +end + \ No newline at end of file diff --git a/spec/muffin_man/listings_spec.rb b/spec/muffin_man/listings/v20210801_spec.rb similarity index 100% rename from spec/muffin_man/listings_spec.rb rename to spec/muffin_man/listings/v20210801_spec.rb diff --git a/spec/support/get_definitions_product_type.json b/spec/support/get_definitions_product_type.json new file mode 100644 index 0000000..c6e1f6b --- /dev/null +++ b/spec/support/get_definitions_product_type.json @@ -0,0 +1,152 @@ +{ + "metaSchema": { + "link": { + "resource": "https://...", + "verb": "GET" + }, + "checksum": "QFQDmPwMARO7vwMEyLhOtw==" + }, + "schema": { + "link": { + "resource": "https://...", + "verb": "GET" + }, + "checksum": "TBr8ubaxXrUyay9hmxUXUw==" + }, + "requirements": "LISTING", + "requirementsEnforced": "ENFORCED", + "propertyGroups": { + "offer": { + "title": "Offer", + "description": "Product Offer", + "propertyNames": [ + "fulfillment_channel_availability", + "purchasable_offer", + "condition_type", + "condition_note", + "list_price", + "product_tax_code", + "merchant_release_date", + "merchant_shipping_group", + "max_order_quantity", + "gift_options", + "main_offer_image_locator", + "other_offer_image_locator_1", + "other_offer_image_locator_2", + "other_offer_image_locator_3", + "other_offer_image_locator_4", + "other_offer_image_locator_5" + ] + }, + "images": { + "title": "Images", + "description": "Physical imagess or URL's", + "propertyNames": [ + "main_product_image_locator", + "other_product_image_locator_1", + "other_product_image_locator_2", + "other_product_image_locator_3", + "other_product_image_locator_4", + "other_product_image_locator_5", + "other_product_image_locator_6", + "other_product_image_locator_7", + "other_product_image_locator_8", + "swatch_product_image_locator" + ] + }, + "shipping": { + "title": "Shipping", + "description": "Information to determine shipping and storage of your product (e.g., package dimensions, weight, volume)", + "propertyNames": [ + "item_dimensions", + "item_package_dimensions", + "item_package_weight" + ] + }, + "variations": { + "title": "Variations", + "description": "Variations that product will use", + "propertyNames": [ + "parentage_level", + "child_parent_sku_relationship", + "variation_theme" + ] + }, + "safety_and_compliance": { + "title": "Safety & Compliance", + "description": "Information to indicate product compliance, hazardous materials, and legal and safety warnings (e.g., lithium batteries, choking hazards, Consumer Product Safety Information Act (CPSIA))", + "propertyNames": [ + "country_of_origin", + "warranty_description", + "batteries_required", + "batteries_included", + "battery", + "num_batteries", + "number_of_lithium_metal_cells", + "number_of_lithium_ion_cells", + "lithium_battery", + "supplier_declared_dg_hz_regulation", + "hazmat", + "safety_data_sheet_url", + "item_weight", + "ghs", + "supplier_declared_material_regulation", + "california_proposition_65", + "pesticide_marking" + ] + }, + "product_identity": { + "title": "Product Identity", + "description": "Information to uniquely identify your product (e.g., UPC, EAN, GTIN, Product Type, Brand)", + "propertyNames": [ + "item_name", + "brand", + "supplier_declared_has_product_identifier_exemption", + "externally_assigned_product_identifier", + "merchant_suggested_asin", + "item_type_keyword", + "item_type_name", + "model_number", + "manufacturer" + ] + }, + "product_details": { + "title": "Product Details", + "description": "Information and characteristics to describe the product to support search, browse and detail page content (e.g., bullets, product features, model, style name)", + "propertyNames": [ + "product_description", + "bullet_point", + "generic_keyword", + "special_feature", + "style", + "department", + "target_gender", + "age_range_description", + "material", + "outer", + "fabric_type", + "lining_description", + "number_of_items", + "number_of_wheels", + "wheel", + "model_name", + "color", + "size", + "size_map", + "part_number", + "compliance_media" + ] + } + }, + "locale": "en_US", + "marketplaceIds": [ + "DRURYLANE" + ], + "productType": "YARN", + "productTypeVersion": { + "version": "U8L4z4Ud95N16tZlR7rsmbQ==", + "latest": true, + "releaseCandidate": false + } + } + \ No newline at end of file diff --git a/spec/support/search_definitions_product_types.json b/spec/support/search_definitions_product_types.json new file mode 100644 index 0000000..263ed6a --- /dev/null +++ b/spec/support/search_definitions_product_types.json @@ -0,0 +1,10 @@ +{ + "productTypes": [ + { + "name": "LUGGAGE", + "marketplaceIds": [ + "DRURYLANE" + ] + } + ] +} \ No newline at end of file diff --git a/spec/support/sp_api_helpers.rb b/spec/support/sp_api_helpers.rb index f92023b..6ec41fc 100644 --- a/spec/support/sp_api_helpers.rb +++ b/spec/support/sp_api_helpers.rb @@ -212,6 +212,17 @@ def stub_delete_listings_item_wrong_sku .to_return(status: 404, body: "", headers: {}) end + def stub_search_definitions_product_types + stub_request(:get, "https://#{hostname}/definitions/2020-09-01/productTypes?keywords=#{keyword}&marketplaceIds=#{amazon_marketplace_id}") + .to_return(status: 200, body: File.read("./spec/support/search_definitions_product_types.json"), headers: {}) + end + + def stub_get_definitions_product_type + stub_request(:get, + "https://#{hostname}/definitions/2020-09-01/productTypes/#{product_type}?locale=en_US&marketplaceIds=#{amazon_marketplace_id}&requirementsEnforced=ENFORCED") + .to_return(status: 200, body: File.read("./spec/support/get_definitions_product_type.json"), headers: {}) + end + def stub_get_prep_instructions stub_request(:get, "https://#{hostname}/fba/inbound/v0/prepInstructions?ShipToCountryCode=#{country_code}&SellerSKUList=#{sku_list.join(",")}") .to_return(status: 200, body: File.read("./spec/support/get_prep_instructions.json"), headers: {}) From 11281a411dc60300612ef709e18cdff8102db465 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Thu, 21 Sep 2023 17:27:53 +0530 Subject: [PATCH 15/22] added changelog --- CHANGELOG.md | 4 ++++ lib/muffin_man.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99c3fd9..d6f420c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 2.0.6 [#54](https://github.com/patterninc/muffin_man/pull/54) +- Support for Product Type Definitions + +# 2.0.6 [#54](https://github.com/patterninc/muffin_man/pull/54) + - Support for getOrder # 2.0.5 [#53](https://github.com/patterninc/muffin_man/pull/53) diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index 9c93a79..730c9a2 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -12,7 +12,7 @@ require "muffin_man/tokens/v20210301" require "muffin_man/product_pricing/v0" require "muffin_man/listings/v20210801" -require "muffin_man/listings/V20200901" +require "muffin_man/listings/v20200901" require "muffin_man/fulfillment_inbound/v0" require "muffin_man/fulfillment_inbound/v1" require "muffin_man/fulfillment_outbound/v20200701" From 72f9adb4d738af1a6938eafaa23833a34bfaee98 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Thu, 21 Sep 2023 18:43:00 +0530 Subject: [PATCH 16/22] Rubocop changes --- .rubocop_todo.yml | 22 +++++++++++++++--- lib/muffin_man/listings/v20200901.rb | 27 +++++++++++----------- spec/muffin_man/listings/v20200901_spec.rb | 13 ++++++----- spec/muffin_man/listings/v20210801_spec.rb | 20 +++++++++++----- spec/support/sp_api_helpers.rb | 2 +- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bab63df..baab19a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -240,7 +240,7 @@ RSpec/EmptyLineAfterHook: # Offense count: 12 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. # Include: **/*_spec*rb*, **/spec/**/* -RSpec/FilePath: +RSpec/SpecFilePathFormat: Exclude: - 'spec/muffin_man/authorization_spec.rb' - 'spec/muffin_man/catalog_items_spec.rb' @@ -255,6 +255,20 @@ RSpec/FilePath: - 'spec/muffin_man/solicitations_spec.rb' - 'spec/muffin_man/tokens_spec.rb' +RSpec/SpecFilePathSuffix: + Exclude: + - 'spec/muffin_man/authorization_spec.rb' + - 'spec/muffin_man/catalog_items_spec.rb' + - 'spec/muffin_man/catalog_items_v20220401_spec.rb' + - 'spec/muffin_man/finances_spec.rb' + - 'spec/muffin_man/listings_spec.rb' + - 'spec/muffin_man/lwa_spec.rb' + - 'spec/muffin_man/orders_spec.rb' + - 'spec/muffin_man/product_fees_spec.rb' + - 'spec/muffin_man/product_pricing_spec.rb' + - 'spec/muffin_man/reports_spec.rb' + - 'spec/muffin_man/solicitations_spec.rb' + - 'spec/muffin_man/tokens_spec.rb' # Offense count: 15 # This cop supports safe autocorrection (--autocorrect). @@ -346,6 +360,7 @@ Style/FrozenStringLiteralComment: - 'lib/muffin_man/fulfillment_inbound/v0.rb' - 'lib/muffin_man/fulfillment_inbound/v1.rb' - 'lib/muffin_man/listings/v20210801.rb' + - 'lib/muffin_man/listings/v20200901.rb' - 'lib/muffin_man/lwa/auth_helper.rb' - 'lib/muffin_man/orders/v0.rb' - 'lib/muffin_man/reports/v20210630.rb' @@ -363,7 +378,8 @@ Style/FrozenStringLiteralComment: - 'spec/muffin_man/finances_spec.rb' - 'spec/muffin_man/fulfillment_inbound/v0_spec.rb' - 'spec/muffin_man/fulfillment_inbound/v1_spec.rb' - - 'spec/muffin_man/listings_spec.rb' + - 'spec/muffin_man/listings/v20210801_spec.rb' + - 'spec/muffin_man/listings/v20200901_spec.rb' - 'spec/muffin_man/lwa_spec.rb' - 'spec/muffin_man/orders_spec.rb' - 'spec/muffin_man/product_fees_spec.rb' @@ -479,4 +495,4 @@ Layout/LineLength: - 'spec/muffin_man/solicitations_spec.rb' - 'spec/muffin_man/sp_api_client_spec.rb' - 'spec/support/lwa_helpers.rb' - - 'spec/support/sp_api_helpers.rb' + - 'spec/support/sp_api_helpers.rb' \ No newline at end of file diff --git a/lib/muffin_man/listings/v20200901.rb b/lib/muffin_man/listings/v20200901.rb index 01a49dd..75fbdd1 100644 --- a/lib/muffin_man/listings/v20200901.rb +++ b/lib/muffin_man/listings/v20200901.rb @@ -1,44 +1,45 @@ module MuffinMan module Listings class V20200901 < SpApiClient - - REQUIREMENTS = %w(LISTING LISTING_PRODUCT_ONLY LISTING_OFFER_ONLY).freeze - REQUIREMENTS_ENFORCED = %w(ENFORCED NOT_ENFORCED).freeze - 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 - 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).freeze + REQUIREMENTS = %w[LISTING LISTING_PRODUCT_ONLY LISTING_OFFER_ONLY].freeze + REQUIREMENTS_ENFORCED = %w[ENFORCED NOT_ENFORCED].freeze + 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 + 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] + .freeze def search_definitions_product_types(marketplace_ids, keywords = nil) @local_var_path = "/definitions/2020-09-01/productTypes" @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] - @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } + @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } @query_params["keywords"] = keywords if keywords.present? @request_type = "GET" call_api end + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/PerceivedComplexity def get_definitions_product_type(product_type, marketplace_ids, options = {}) options = options.with_indifferent_access @local_var_path = "/definitions/2020-09-01/productTypes/#{product_type}" @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] - @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } + @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } @query_params["sellerId"] = options["sellerId"] if options["sellerId"] @query_params["productTypeVersion"] = options["productTypeVersion"].upcase if options["productTypeVersion"] if REQUIREMENTS.include?(options["requirements"]&.upcase) @query_params["requirements"] = options["requirements"].upcase - end + end if REQUIREMENTS_ENFORCED.include?(options["requirementsEnforced"]&.upcase) @query_params["requirementsEnforced"] = options["requirementsEnforced"].upcase - end - - if LOCALE.include?(options["locale"]) - @query_params["locale"] = options["locale"] end + @query_params["locale"] = options["locale"] if LOCALE.include?(options["locale"]) + @request_type = "GET" call_api end + # rubocop:enable Metrics/CyclomaticComplexity + # rubocop:enable Metrics/PerceivedComplexity end end end - \ No newline at end of file diff --git a/spec/muffin_man/listings/v20200901_spec.rb b/spec/muffin_man/listings/v20200901_spec.rb index 6c8c82c..b93227d 100644 --- a/spec/muffin_man/listings/v20200901_spec.rb +++ b/spec/muffin_man/listings/v20200901_spec.rb @@ -1,31 +1,32 @@ RSpec.describe MuffinMan::Listings::V20200901 do + subject(:listings_client) { described_class.new(credentials) } + before do stub_request_access_token end - + let(:keyword) { "LUGGAGE" } let(:product_type) { "YARN" } let(:amazon_marketplace_id) { "DRURYLANE" } - - subject(:listings_client) { described_class.new(credentials) } describe "search_definitions_product_types" do before { stub_search_definitions_product_types } + it "makes a request to search definitions product types" do response = listings_client.search_definitions_product_types(amazon_marketplace_id, keyword) expect(response.response_code).to eq(200) - expect(JSON.parse(response.body).dig("productTypes").first["name"]).to eq(keyword) + expect(JSON.parse(response.body)["productTypes"].first["name"]).to eq(keyword) end end describe "get_definitions_product_type" do before { stub_get_definitions_product_type } + it "makes a request to get definitions product type" do options = { requirementsEnforced: "ENFORCED", locale: "en_US" } response = listings_client.get_definitions_product_type(product_type, amazon_marketplace_id, options) expect(response.response_code).to eq(200) - expect(JSON.parse(response.body).dig("productType")).to eq(product_type) + expect(JSON.parse(response.body)["productType"]).to eq(product_type) end end end - \ No newline at end of file diff --git a/spec/muffin_man/listings/v20210801_spec.rb b/spec/muffin_man/listings/v20210801_spec.rb index ffec74e..eb5ce37 100644 --- a/spec/muffin_man/listings/v20210801_spec.rb +++ b/spec/muffin_man/listings/v20210801_spec.rb @@ -1,4 +1,6 @@ RSpec.describe MuffinMan::Listings::V20210801 do + subject(:listings_client) { described_class.new(credentials) } + before do stub_request_access_token end @@ -8,18 +10,19 @@ let(:amazon_marketplace_id) { "DRURYLANE" } let(:issue_locale) { "en_US" } - subject(:listings_client) { described_class.new(credentials) } - describe "get_listings_item" do before { stub_get_listings_item } + it "makes a request to get a listings item" do expect(listings_client.get_listings_item(seller_id, sku, amazon_marketplace_id).response_code).to eq(200) - expect(JSON.parse(listings_client.get_listings_item(seller_id, sku, amazon_marketplace_id).body).dig("sku")).to eq(sku) + expect(JSON.parse(listings_client.get_listings_item(seller_id, sku, + amazon_marketplace_id).body)["sku"]).to eq(sku) end end describe "put_listings_item" do before { stub_put_listings_item } + let(:product_type) { "LUGGAGE" } let(:requirements) { "LISTING" } let(:attributes) do @@ -48,7 +51,8 @@ end it "makes a request to create a listings item or update an existing listings item" do - response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, requirements: requirements) + response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, + requirements: requirements) expect(response.response_code).to eq(200) expect(JSON.parse(response.body)).to eq(put_listing_result) end @@ -57,6 +61,7 @@ describe "delete_listings_item" do context "when sku and seller_id combination is correct" do before { stub_delete_listings_item } + let(:delete_listing_result) do { "sku" => "SD-ABC-12345", @@ -67,7 +72,8 @@ end it "makes a request to delete a listings item" do - response = listings_client.delete_listings_item(seller_id, sku, amazon_marketplace_id, issue_locale: issue_locale) + response = listings_client.delete_listings_item(seller_id, sku, amazon_marketplace_id, + issue_locale: issue_locale) expect(response.response_code).to eq(200) expect(JSON.parse(response.body)).to eq(delete_listing_result) end @@ -75,10 +81,12 @@ context "when sku and seller_id combination is not found" do before { stub_delete_listings_item_wrong_sku } + let(:nonexistent_sku) { "SD-XYZ-98765" } it "returns a 'not found' response" do - response = listings_client.delete_listings_item(seller_id, nonexistent_sku, amazon_marketplace_id, issue_locale: issue_locale) + response = listings_client.delete_listings_item(seller_id, nonexistent_sku, amazon_marketplace_id, + issue_locale: issue_locale) expect(response.response_code).to eq(404) end end diff --git a/spec/support/sp_api_helpers.rb b/spec/support/sp_api_helpers.rb index 6ec41fc..6f9454b 100644 --- a/spec/support/sp_api_helpers.rb +++ b/spec/support/sp_api_helpers.rb @@ -219,7 +219,7 @@ def stub_search_definitions_product_types def stub_get_definitions_product_type stub_request(:get, - "https://#{hostname}/definitions/2020-09-01/productTypes/#{product_type}?locale=en_US&marketplaceIds=#{amazon_marketplace_id}&requirementsEnforced=ENFORCED") + "https://#{hostname}/definitions/2020-09-01/productTypes/#{product_type}?locale=en_US&marketplaceIds=#{amazon_marketplace_id}&requirementsEnforced=ENFORCED") .to_return(status: 200, body: File.read("./spec/support/get_definitions_product_type.json"), headers: {}) end From df7fcfcef1cd02f1b0999abe948fef84ebb951ad Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Thu, 21 Sep 2023 19:01:00 +0530 Subject: [PATCH 17/22] downgrade rubocop-rspec --- .rubocop_todo.yml | 17 +---------------- Gemfile | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index baab19a..0373ee4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -240,22 +240,7 @@ RSpec/EmptyLineAfterHook: # Offense count: 12 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. # Include: **/*_spec*rb*, **/spec/**/* -RSpec/SpecFilePathFormat: - Exclude: - - 'spec/muffin_man/authorization_spec.rb' - - 'spec/muffin_man/catalog_items_spec.rb' - - 'spec/muffin_man/catalog_items_v20220401_spec.rb' - - 'spec/muffin_man/finances_spec.rb' - - 'spec/muffin_man/listings_spec.rb' - - 'spec/muffin_man/lwa_spec.rb' - - 'spec/muffin_man/orders_spec.rb' - - 'spec/muffin_man/product_fees_spec.rb' - - 'spec/muffin_man/product_pricing_spec.rb' - - 'spec/muffin_man/reports_spec.rb' - - 'spec/muffin_man/solicitations_spec.rb' - - 'spec/muffin_man/tokens_spec.rb' - -RSpec/SpecFilePathSuffix: +RSpec/FilePath: Exclude: - 'spec/muffin_man/authorization_spec.rb' - 'spec/muffin_man/catalog_items_spec.rb' diff --git a/Gemfile b/Gemfile index bc60e89..1d252f3 100644 --- a/Gemfile +++ b/Gemfile @@ -13,4 +13,4 @@ gem "rubocop", "<= 1.43" gem "rubocop-rake" -gem "rubocop-rspec" +gem "rubocop-rspec", "<=2.20" From 36c63c361c80ff1ce6e51b53309adac1b18a33bf Mon Sep 17 00:00:00 2001 From: Shubham N Khanna <110454114+shubham-n-khanna@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:03:14 +0530 Subject: [PATCH 18/22] Update search_definitions_product_types.json --- spec/support/search_definitions_product_types.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/search_definitions_product_types.json b/spec/support/search_definitions_product_types.json index 263ed6a..e92c4b2 100644 --- a/spec/support/search_definitions_product_types.json +++ b/spec/support/search_definitions_product_types.json @@ -7,4 +7,4 @@ ] } ] -} \ No newline at end of file +} From f1d276298efba9cb064bba85bcb6a30f28c4d731 Mon Sep 17 00:00:00 2001 From: Shubham N Khanna <110454114+shubham-n-khanna@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:03:42 +0530 Subject: [PATCH 19/22] Update get_definitions_product_type.json --- spec/support/get_definitions_product_type.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/support/get_definitions_product_type.json b/spec/support/get_definitions_product_type.json index c6e1f6b..73610e1 100644 --- a/spec/support/get_definitions_product_type.json +++ b/spec/support/get_definitions_product_type.json @@ -149,4 +149,5 @@ "releaseCandidate": false } } - \ No newline at end of file + + From ebc1b40531b926dfa0c89e09b6d65b41b0dfc808 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Thu, 21 Sep 2023 20:44:08 +0530 Subject: [PATCH 20/22] update CHANGELOG --- .rubocop_todo.yml | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0373ee4..7cc8741 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -480,4 +480,4 @@ Layout/LineLength: - 'spec/muffin_man/solicitations_spec.rb' - 'spec/muffin_man/sp_api_client_spec.rb' - 'spec/support/lwa_helpers.rb' - - 'spec/support/sp_api_helpers.rb' \ No newline at end of file + - 'spec/support/sp_api_helpers.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index d6f420c..6d374d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.0.6 [#54](https://github.com/patterninc/muffin_man/pull/54) +# 2.0.7 [#58](https://github.com/patterninc/muffin_man/pull/58) - Support for Product Type Definitions From 3b8707f808c5173b9aa0e34190da3d442362b779 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Tue, 26 Sep 2023 10:22:48 +0530 Subject: [PATCH 21/22] Review changes --- CHANGELOG.md | 2 +- lib/muffin_man/listings/v20200901.rb | 5 +++-- lib/muffin_man/version.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d374d2..27764bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.0.7 [#58](https://github.com/patterninc/muffin_man/pull/58) +# 2.1.0 [#58](https://github.com/patterninc/muffin_man/pull/58) - Support for Product Type Definitions diff --git a/lib/muffin_man/listings/v20200901.rb b/lib/muffin_man/listings/v20200901.rb index 75fbdd1..ad54a4f 100644 --- a/lib/muffin_man/listings/v20200901.rb +++ b/lib/muffin_man/listings/v20200901.rb @@ -6,9 +6,10 @@ class V20200901 < SpApiClient 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 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] .freeze + PRODUCT_TYPES_PATH = "/definitions/2020-09-01/productTypes".freeze def search_definitions_product_types(marketplace_ids, keywords = nil) - @local_var_path = "/definitions/2020-09-01/productTypes" + @local_var_path = PRODUCT_TYPES_PATH @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } @query_params["keywords"] = keywords if keywords.present? @@ -20,7 +21,7 @@ def search_definitions_product_types(marketplace_ids, keywords = nil) # rubocop:disable Metrics/PerceivedComplexity def get_definitions_product_type(product_type, marketplace_ids, options = {}) options = options.with_indifferent_access - @local_var_path = "/definitions/2020-09-01/productTypes/#{product_type}" + @local_var_path = "#{PRODUCT_TYPES_PATH}/#{product_type}" @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } @query_params["sellerId"] = options["sellerId"] if options["sellerId"] diff --git a/lib/muffin_man/version.rb b/lib/muffin_man/version.rb index 9a1e01a..04b7b80 100644 --- a/lib/muffin_man/version.rb +++ b/lib/muffin_man/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MuffinMan - VERSION = "2.0.7" + VERSION = "2.1.0" end From f66682f92f3c4c4080443352ad0974b3ae233201 Mon Sep 17 00:00:00 2001 From: Shubham Khanna Date: Tue, 26 Sep 2023 13:56:37 +0530 Subject: [PATCH 22/22] FrozenStringLiteral: rubocop fix --- .rubocop_todo.yml | 3 --- lib/muffin_man/listings/v20200901.rb | 4 +++- spec/muffin_man/listings/v20200901_spec.rb | 2 ++ spec/muffin_man/listings/v20210801_spec.rb | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7cc8741..e3d5912 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -345,7 +345,6 @@ Style/FrozenStringLiteralComment: - 'lib/muffin_man/fulfillment_inbound/v0.rb' - 'lib/muffin_man/fulfillment_inbound/v1.rb' - 'lib/muffin_man/listings/v20210801.rb' - - 'lib/muffin_man/listings/v20200901.rb' - 'lib/muffin_man/lwa/auth_helper.rb' - 'lib/muffin_man/orders/v0.rb' - 'lib/muffin_man/reports/v20210630.rb' @@ -363,8 +362,6 @@ Style/FrozenStringLiteralComment: - 'spec/muffin_man/finances_spec.rb' - 'spec/muffin_man/fulfillment_inbound/v0_spec.rb' - 'spec/muffin_man/fulfillment_inbound/v1_spec.rb' - - 'spec/muffin_man/listings/v20210801_spec.rb' - - 'spec/muffin_man/listings/v20200901_spec.rb' - 'spec/muffin_man/lwa_spec.rb' - 'spec/muffin_man/orders_spec.rb' - 'spec/muffin_man/product_fees_spec.rb' diff --git a/lib/muffin_man/listings/v20200901.rb b/lib/muffin_man/listings/v20200901.rb index ad54a4f..eb7a749 100644 --- a/lib/muffin_man/listings/v20200901.rb +++ b/lib/muffin_man/listings/v20200901.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MuffinMan module Listings class V20200901 < SpApiClient @@ -6,7 +8,7 @@ class V20200901 < SpApiClient 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 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] .freeze - PRODUCT_TYPES_PATH = "/definitions/2020-09-01/productTypes".freeze + PRODUCT_TYPES_PATH = "/definitions/2020-09-01/productTypes" def search_definitions_product_types(marketplace_ids, keywords = nil) @local_var_path = PRODUCT_TYPES_PATH diff --git a/spec/muffin_man/listings/v20200901_spec.rb b/spec/muffin_man/listings/v20200901_spec.rb index b93227d..4b6fc8f 100644 --- a/spec/muffin_man/listings/v20200901_spec.rb +++ b/spec/muffin_man/listings/v20200901_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe MuffinMan::Listings::V20200901 do subject(:listings_client) { described_class.new(credentials) } diff --git a/spec/muffin_man/listings/v20210801_spec.rb b/spec/muffin_man/listings/v20210801_spec.rb index eb5ce37..b68fee2 100644 --- a/spec/muffin_man/listings/v20210801_spec.rb +++ b/spec/muffin_man/listings/v20210801_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe MuffinMan::Listings::V20210801 do subject(:listings_client) { described_class.new(credentials) }