Sha256: 59d57392b62aae40639764b9877a357251692a30b1b762782b47fd0b3c36b0fc

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

module MWS
  module Orders
    module Request
      class Base
        attr :client
        attr_accessor :last_response

        def initialize(client)
          @client = client
        end

        def next_token
          node = document.at_xpath('//xmlns:NextToken')
          node.text if node
        end

        private

        def execute
          fetch
          parse
        end

        def fetch
          @last_response = client.post(query: parameters)
        end

        def parameters(action = nil)
          @parameters = Helper::Parameters.new(action) if action
          @parameters
        end

        def parse
          parser.new(node)
        end

        def parser
          Parser.const_get(name)
        end

        def node
          document.xpath("//xmlns:#{name}")
        end

        def document
          Nokogiri::XML(last_response.body)
        end

        def name
          self.class.name.split('::').last
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mws-orders-0.0.2 lib/mws/orders/requests/base.rb
mws-orders-0.0.1 lib/mws/orders/requests/base.rb