lib/peddler/client.rb in peddler-0.15.0 vs lib/peddler/client.rb in peddler-0.16.0
- old
+ new
@@ -6,19 +6,21 @@
module Peddler
# An abstract client
#
# Subclass to implement an MWS API section.
+ #
+ # rubocop:disable ClassLength
class Client
extend Forwardable
include Jeff
# The MWSAuthToken used to access another seller's account
# @return [String]
attr_accessor :auth_token
- attr_writer :merchant_id, :marketplace_id, :path
+ attr_writer :merchant_id, :primary_marketplace_id, :path
# @api private
attr_writer :version
# The body of the HTTP request
@@ -42,16 +44,11 @@
# @api private
def parser
@parser ||= Parser
end
- # A custom parser
- # @!parse attr_writer :parser
- # @return [Object]
- def parser=(parser)
- @parser = parser
- end
+ attr_writer :parser
# @api private
def path(path = nil)
path ? @path = path : @path ||= '/'
end
@@ -59,22 +56,22 @@
# @api private
def version(version = nil)
version ? @version = version : @version
end
- # Sets an error handler
+ # Sets an error handler
# @yieldparam request [Excon::Request]
# @yieldparam response [Excon::Response]
def on_error(&blk)
@error_handler = blk
end
private
def inherited(base)
base.params(params)
- base.on_error &@error_handler if @error_handler
+ base.on_error(&@error_handler) if @error_handler
end
end
# Creates a new client instance
#
@@ -92,16 +89,26 @@
def aws_endpoint
"https://#{host}#{path}"
end
# The merchant's Marketplace ID
- # @!parse attr_reader :marketplace_id
+ # @!parse attr_reader :primary_marketplace_id
# @return [String]
+ def primary_marketplace_id
+ @primary_marketplace_id ||= ENV['MWS_MARKETPLACE_ID']
+ end
+
+ # @deprecated Use {#primary_marketplace_id} instead.
def marketplace_id
- @marketplace_id ||= ENV['MWS_MARKETPLACE_ID']
+ @primary_marketplace_id
end
+ # @deprecated Use {#primary_marketplace_id=} instead.
+ def marketplace_id=(marketplace_id)
+ @primary_marketplace_id = marketplace_id
+ end
+
# The merchant's Seller ID
# @!parse attr_reader :merchant_id
# @return [String]
def merchant_id
@merchant_id ||= ENV['MWS_MERCHANT_ID']
@@ -138,11 +145,11 @@
# @api private
def headers
@headers ||= {}
end
- # Sets an error handler
+ # Sets an error handler
# @yieldparam request [Excon::Request]
# @yieldparam response [Excon::Response]
def on_error(&blk)
@error_handler = blk
end
@@ -156,10 +163,11 @@
def operation(action = nil)
action ? @operation = Operation.new(action) : @operation
end
# @api private
+ # rubocop:disable AbcSize, MethodLength
def run
opts = defaults.merge(query: operation, headers: headers)
opts.store(:body, body) if body
opts.store(:response_block, Proc.new) if block_given?
res = post(opts)
@@ -167,20 +175,21 @@
parser.new(res, encoding)
rescue Excon::Errors::Error => e
handle_error(e) or raise
rescue NoMethodError => e
if e.message == "undefined method `new' for #{parser}"
- warn "[DEPRECATION] `Parser.parse` is deprecated. Please use `Parser.new` instead."
+ warn "[DEPRECATION] `Parser.parse` is deprecated. "\
+ "Please use `Parser.new` instead."
parser.parse(res, encoding)
else
raise
end
end
private
def find_marketplace
- Marketplace.new(marketplace_id)
+ Marketplace.new(primary_marketplace_id)
end
def content_type(str)
if str.start_with?('<?xml')
'text/xml'