class MWS::MerchantFulfillment::Parser

Public Class Methods

new(response, _encoding) click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 14
def initialize(response, _encoding)
  @response = response
end

Public Instance Methods

body() click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 45
def body
  @response.body
end
headers() click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 37
def headers
  @response.headers
end
parse() click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 18
def parse
  node = find_result_node

  case node.name
  when /GetServiceStatus/
    ServiceStatus.new(node)
  when /GetEligibleShippingServices/
    ShippingServices.new(node)
  when /CreateShipment/
    shipment_node = node.children.find { |node| node.name == 'Shipment' }
    Shipment.new(shipment_node)
  when /CancelShipment/
    shipment_node = node.children.find { |node| node.name == 'Shipment' }
    Shipment.new(shipment_node)
  else
    raise NotImplementedError
  end
end
status_code() click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 41
def status_code
  @response.status
end

Private Instance Methods

find_result_node() click to toggle source
# File lib/mws/merchant_fulfillment/parser.rb, line 51
def find_result_node
  xml = Nokogiri(@response.body)
  root = xml.children.first

  root.children.find { |node| node.name.include?('Result') }
end