elyngved / ruby-mws Goto Github PK
View Code? Open in Web Editor NEWA Ruby library that wraps the Amazon MWS API.
License: MIT License
A Ruby library that wraps the Amazon MWS API.
License: MIT License
I get an error when trying to do a mws.orders.next :
mwstestcase.rb:73:in <main>': undefined method
has_key?' for nil:NilClass (NoMethodError)
and if I save the response.next_token and try mws.orders.list_orders_by_next_response, I get another error:
mwstestcase.rb:70:in <main>': undefined method
list_orders_by_next_response' for #MWS::API::Order:8366400 (NoMethodError)
The problem is duplicated if I do multiple mws.orders.list_order_items between the mws.orders.list_orders and the mws.orders.next.
Here is the test case for response.next_token:
require 'rubygems'
require 'ruby-mws'
require 'active_record'
require 'active_support/all'
def get_response # takes a block as a parameter
#amazon requests may be throttled, so we need to check before returning results
throttled = true
while throttled == true
the_response = yield
if the_response.has_key?("error_response") # all error responses should have this key
if the_response.error_response.error.has_key?("code")
if the_response.error_response.error.code == "RequestThrottled"
sleep(10.seconds) # throttle times may vary, so retry after 10 sec
end
else
puts "unknown error"
return nil
end
else
throttled = false
return the_response
end
end
end
mws = MWS.new ({:aws_access_key_id => "",
:secret_access_key => "++",
:seller_id => "",
:marketplace_id => ""})
start_time = Time.utc(2003) # default start date
response = get_response {mws.orders.list_orders :last_updated_after => start_time}
n = 0
while n < 3 do
if mws.orders.has_next? == true
puts "has next"
next_token = response.next_token
else
puts "does not have next"
end
response.orders.each do |r|
order_items = get_response {mws.orders.list_order_items :amazon_order_id => r.amazon_order_id}
if order_items
order_items.order_items.each do |item|
puts r.amazon_order_id, item.title
end
end
end
puts "trying next_token!"
response = get_response {mws.orders.list_orders_by_next_response :next_token => next_token}
n += 1
end
I see that debug_ouput is set here
How can I disable that? I don't want to see the headers / response from the http requests in the rails console ( on my development machine )
Thanks!
Hi,
Thanks for writing this. It's very useful. I am writing to report an error I came across. Not repeatable so far (below).
While I'm at it, I might as well report that mws.orders.next doesn't work for me, so I have to use: mws.orders.list_orders :last_updated_after => start_time
Here's the error message:
C:/Ruby193/lib/ruby/1.9.1/openssl/buffering.rb:174:in sysread_nonblock': end of file reached (EOFError) from C:/Ruby193/lib/ruby/1.9.1/openssl/buffering.rb:174:in
read_nonbloc
k'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:141:in rbuf_fill' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in
readuntil'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in readline' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2562:in
read_status_line'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2551:in read_new' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1319:in
block in transport_r
equest'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in catch' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in
transport_request'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1293:in request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1286:in
block in request'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in start' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1284:in
request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/httparty-0.11.0/lib/httparty/re
quest.rb:92:in perform' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/httparty-0.11.0/lib/httparty.rb :461:in
perform_request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/httparty-0.11.0/lib/httparty.rb
:398:in get' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.0.4/lib/ruby-mws/api /base.rb:49:in
send_request'
from (eval):4:in list_order_items' from mws.rb:103:in
block (2 levels) in
get_response' from mws.rb:103:in
block in 'each' from mws.rb:91:in
'Hi, I just forked the project and I would like to contribute to the feeds api. But first, can you help me understand what I need to do to get the tests to pass? I just ran rspec spec and I get failures like this (I tried looking through the source and tests, I took a look at the ephemeral_response gem and tried adding a credential.yml file afterwards, but I wasn't able to progress much):
....FFFFFFF.......
Failures:
MWS::API::Inventory requests list_inventory_supply should return items based on seller SKUs
Failure/Error: items = @mws.inventory.list_inventory_supply :timestamp => @timestamp,
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:11-04:00
MWS::API::Inventory requests list_inventory_supply should return items with inventory changes since a certain time
Failure/Error: items = @mws.inventory.list_inventory_supply :timestamp => @timestamp,
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:11-04:00
MWS::API::Order requests list_orders should receive a list of orders
Failure/Error: orders = @mws.orders.list_orders :last_updated_after => "2012-01-15T13:07:26-05:00" ,
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:55-04:00
MWS::API::Order requests list_orders_by_next_token should receive a list_orders_by_next_token_result
Failure/Error: orders = @mws.orders.list_orders_by_next_token :timestamp => @timestamp,
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:55-04:00
MWS::API::Order requests get_order should return one order for one order id
Failure/Error: order = @mws.orders.get_order :amazon_order_id => "102-4850183-7065809",
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:55-04:00
MWS::API::Order requests get_order should return multiple orders for multiple order ids
Failure/Error: orders = @mws.orders.get_order :amazon_order_id => ["102-4850183-7065809", "002-3400187-5292203"],
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:55-04:00
MWS::API::Order requests list_order_items should return a list of items for an order
Failure/Error: order = @mws.orders.list_order_items :amazon_order_id => "102-4850183-7065809",
MWS::ErrorResponse:
RequestExpired: Request has expired. Timestamp date: 2012-04-25T21:42:55-04:00
Hello, I was using a previous version of this gem and it was working fine, but I just updated and now I am having problems:
def get_response # takes a block as a parameter
#amazon requests may be throttled, so we need to check before returning results
throttled = true
s = 5
while throttled == true
the_response = yield
if the_response.has_key?("error_response") # all error responses should have this key
if the_response.error_response.error.has_key?("code")
if the_response.error_response.error.code == "RequestThrottled"
sleep(s.seconds) # throttle times may vary, so retry after 10 sec
s = s*1.5
end
else
puts "unknown error"
return nil
end
else
throttled = false
return the_response
end
end
end
Now, I don't even see the throttled response and instead I get a program crash as follows:
-> "<?xml version=\"1.0\"?>\n<ErrorResponse xmlns=\"https://mws.amazonservices.c
om/Orders/2011-01-01\">\n <Error>\n <Type></Type>\n <Code>RequestThrottle
d</Code>\n <Message>Request is throttled</Message>\n </Error>\n <RequestID>
740e1669-dab8-4776-b8dd-ebf1938c958a</RequestID>\n</ErrorResponse>\n"
read 291 bytes
Conn close
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/response.rb:24
:in `handle_error_response': RequestThrottled: Request is throttled (MWS::ErrorR
esponse)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/r
esponse.rb:10:in `parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mws-0.1/lib/ruby-mws/api/b
ase.rb:45:in `send_request'
from (eval):4:in `list_order_items'
from mws.rb:98:in `block (2 levels) in <main>'
from mws.rb:29:in `get_response'
from mws.rb:98:in `block in <main>'
from mws.rb:87:in `each'
from mws.rb:87:in `<main>'
Also:
Thanks very much.
RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.
There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.
I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!
Appendix:
If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies
p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.