This is an awesome gem, though I ran into many errors when I first started to try it out. Here's the code I was trying:
require 'amazon/aws' require 'amazon/aws/search' require 'pp' include Amazon::AWS include Amazon::AWS::Search ASSOCIATES_ID = "removed" KEY_ID = "removed" #req = Request.new(KEY_ID, ASSOCIATES_ID, 'us', false) is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } ) is.response_group = ResponseGroup.new( :Small ) req = Request.new(KEY_ID, ASSOCIATES_ID, 'us', false) resp = req.search( is ) pp(resp.item_search_response) pp(resp)
I first had trouble figuring out that I needed to put my AWS "secret" key in ~/.amazonrc.
I was getting UTF-8 errors, too. I think adding this to my ~/.amazonrc fixed the problem:
encoding = 'UTF-8'
Hmmm. I guess using the cache also causes UTF-8 related errors.
UPDATE: Finally, late last night I figured it out. The example aaws code I was basing my tests on uses ItemLookup.
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } ) is.response_group = ResponseGroup.new( :Small ) req = Request.new(KEY_ID, ASSOCIATES_ID, 'us', true) resp = req.search( is ) item_sets = resp.item_search_response[0].items item_sets[0..3].each do |item_set| item_set.item.each do |item| attribs = item.item_attributes[0] puts attribs end end
The way the secret key is handled seems odd. Maybe there is a better way? The ruby-aaws RDoc says its the only way though.
UPDATE: There are different ways to set where the amazonrc file is. In my case, running unicorn via daemontools caused ENV['HOME'] to be nil, resulting in amazon.rb trying to evaluate ENV['HOMEDRIVE'] + ENV['HOMEPATH'], causing a NoMethodError that was very difficult to decipher (running unicorn with the "-d" option after invoking the Ruby interpreter helped track down the cause).
I had tried setting $AMAZONRCFILE at first, then $AMAZONRCDIR, but that didn't work I noticed in amazon.rb that it was looking for ENV['AMAZONRCDIR'], so I set it in config.ru and voila - functionality!!
UPDATE:
I've send Ian an email:
Hi Ian,Nice work on the ruby-aaws gem. I'm using it with Sinatra and Unicorn, which is run by daemontools. For whatever reason, ENV['HOME'] was resulting in nil, causing it to try ENV['HOMEDRIVE'] + ENV['HOMEPATH'], which for me resulted in a NoMethodError.
Setting ENV['AMAZONRCDIR'] fixed the issue for me, but perhaps you'd consider putting an exception trap there, as the NoMethodError is so vague it was tough to track down.
Thanks for this sweet gem!
- Albert
PS - I've blogged about the gem, too:
http://www.docunext.com/2010/03/ruby-gem-ruby-aaws/
Still not sure what the problem is with UTF-8 and caching....
--
¥