lib/peddler/request.rb in peddler-0.6.3 vs lib/peddler/request.rb in peddler-0.6.4

- old
+ new

@@ -1,20 +1,13 @@ -require 'forwardable' - require 'peddler/request/parameters' -require 'peddler/response_wrapper' +require 'peddler/response' module Peddler class Request - extend Forwardable - - def_delegator :last_response, :next_token - def_delegator :last_response, :xml_payload, :last_xml_payload - attr :client, :headers - attr_accessor :body, :last_response + attr_accessor :body, :last_parsed_response def initialize(client) @client = client @headers = {} end @@ -23,14 +16,18 @@ @parameters = Parameters.new(action) if action @parameters end def execute - fetch - parse + res = fetch + parse(res) end + def next_token + last_parsed_response.next_token if last_parsed_response + end + def has_next_token? !!next_token end private @@ -38,17 +35,18 @@ def parser @parser ||= Object.const_get(self.class.name.sub('Request', 'Parser')) end def fetch - opts = { query: parameters, headers: headers } + opts = { query: parameters, headers: headers, idempotent: true, expects: 200 } opts.update(body: body) if body res = client.post(opts) - @last_response = ResponseWrapper.new(res) + Response.new(res) end - def parse - parser.new(parser.handle?(:xml) ? last_xml_payload : last_response.body) + def parse(response) + document = parser.xml? ? response.result_node : response.body + @last_parsed_response = parser.new(document) end end end