Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWS.orders.next don`t clear last request next_token #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/ruby-mws/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def #{name}(params={})
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'
Expand All @@ -47,10 +47,19 @@ def send_request(name, params, options)

query = Query.new params
@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
after_response
@response
end

def after_response
@next.clear # clear last request states
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 next_token
@next[:token]
end

def has_next?
Expand Down
17 changes: 16 additions & 1 deletion spec/ruby-mws/api/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,20 @@ def self.test_params
lambda{ @api.list_fake_objects }.should raise_error TestWorksError
end
end


context "next token should be nil" do

it "first request then no next_token" do
@api.after_response
@api.next_token.should be_nil
end

it "sencond request then no next_token" do
@api.instance_variable_set(:@next, {token: 'last request token'})
@api.after_response
@api.next_token.should be_nil
end

end

end