lib/peddler/client.rb in peddler-0.9.1 vs lib/peddler/client.rb in peddler-0.9.2

- old
+ new

@@ -21,17 +21,25 @@ 'A1VC38T7YXB528' => 'mws.amazonservices.jp', 'ATVPDKIKX0DER' => 'mws.amazonservices.com' } attr_accessor :path - attr_writer :merchant_id, :marketplace_id, :parser + attr_writer :merchant_id, :marketplace_id attr_reader :body alias_method :configure, :tap params('SellerId' => -> { merchant_id }) + def self.parser + @parser ||= Parser + end + + def self.parser=(parser) + @parser = parser + end + def self.path(path = nil) path ? @path = path : @path ||= '/' end def self.inherited(base) @@ -52,12 +60,12 @@ def merchant_id @merchant_id ||= ENV['MWS_MERCHANT_ID'] end - def parser - @parser ||= Parser + def defaults + @defaults ||= { expects: 200 } end def headers @headers ||= {} end @@ -70,11 +78,11 @@ def operation(action = nil) action ? @operation = Operation.new(action) : @operation end def run(&blk) - opts = { query: operation, headers: headers, expects: 200 } + opts = defaults.merge(query: operation, headers: headers) opts.store(:body, body) if body opts.store(:response_block, blk) if block_given? res = post(opts) parser.parse(res, host_encoding) @@ -101,13 +109,17 @@ 'ISO-8859-1' end end def host - HOSTS.fetch(marketplace_id) { fail BadMarketplaceId } + HOSTS.fetch(marketplace_id) { raise BadMarketplaceId } end def extract_options(args) args.last.is_a?(Hash) ? args.pop : {} + end + + def parser + self.class.parser end end end