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

- old
+ new

@@ -20,13 +20,12 @@ self.class.base_uri "https://#{connection.host}" end def self.def_request(requests, *options) [requests].flatten.each do |name| - # class variable = a way to store options splat to pass into pseudomethod - self.class_variable_set("@@#{name}_options", options.first) self.class_eval %Q{ + @@#{name}_options = options.first def #{name}(params={}) send_request(:#{name}, params, @@#{name}_options) end } end @@ -45,21 +44,14 @@ params[:lists] ||= {} params[:lists][:marketplace_id] = "MarketplaceId.Id" query = Query.new params - @response = Response.new self.class.send(params[:verb], query.request_uri) - - begin - res = @response.send("#{name}_response").send("#{name}_result") - if @next[:token] = res.next_token # modifying, not comparing - @next[:action] = params[:next_action] || (name.match(/_by_next_token/) ? name : "#{name}_by_next_token") - end - params[:mods].each {|mod| mod.call(res) } if params[:mods] - res - rescue NoMethodError - @response + @response = Response.parse self.class.send(params[:verb], query.request_uri), 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 has_next? not @next[:token].nil? end \ No newline at end of file