lib/ruby-mws/api/base.rb in ruby-mws-0.0.4 vs lib/ruby-mws/api/base.rb in ruby-mws-0.1

- old
+ new

@@ -4,12 +4,13 @@ module MWS module API class Base include HTTParty - # debug_output $stderr # only in development - format :xml + parser MWS::API::BinaryParser + debug_output $stderr # only in development + #format :xml headers "User-Agent" => "ruby-mws/#{MWS::VERSION} (Language=Ruby/1.9.3-p0)" headers "Content-Type" => "text/xml" attr_accessor :response @@ -29,29 +30,35 @@ end } end end - def send_request(name, params, options) + def send_request(name, params, options={}) # prepare all required params... - params = [params, options, @connection.to_hash].inject :merge - - # default/common params - params[:action] ||= name.to_s.camelize - params[:signature_method] ||= 'HmacSHA256' - params[:signature_version] ||= '2' - params[:timestamp] ||= Time.now.iso8601 - params[:version] ||= '2009-01-01' + params = [default_params(name), params, options, @connection.to_hash].inject :merge params[:lists] ||= {} params[:lists][:marketplace_id] = "MarketplaceId.Id" query = Query.new params - @response = Response.parse self.class.send(params[:verb], query.request_uri), name, params + resp = self.class.send(params[:verb], query.request_uri) + + @response = Response.parse resp, name, params + if @response.respond_to?(:next_token) and @next[:token] = @response.next_token # modifying, not comparing @next[:action] = name.match(/_by_next_token/) ? name : "#{name}_by_next_token" end @response + end + + def default_params(name) + { + :action => name.to_s.camelize, + :signature_method => 'HmacSHA256', + :signature_version => '2', + :timestamp => Time.now.iso8601, + :version => '2009-01-01' + } end def has_next? not @next[:token].nil? end \ No newline at end of file