This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Searching For Books on
require 'amazon/search'
$AWS_KEY = 'Your AWS key goes here' # See below.
def price_books(keyword)
  req =$AWS_KEY)
  req.keyword_search(keyword, 'books', Amazon::Search::LIGHT) do |product| 
    newp = product.our_price || 'Not available'
    usedp = product.used_price || 'not available'
    puts "#{product.product_name}: #{newp} new, #{usedp} used."
price_books('ruby cookbook')
Ruby Cookbook (Cookbooks (O'Reilly)): $31.49 new, not available used.
Rails Cookbook (Cookbooks (O'Reilly)): $25.19 new, not available used.
Ruby Ann's Down Home Trailer Park Cookbook: $10.85 new, $3.54 used.
Ruby's Low-Fat Soul-Food Cookbook: Not available new, $12.43 used.
Error! (Exception?) Here's stdout:
Amazon::Search::Request::HTTPError: HTTP response code 500
	from /usr/local/lib/site_ruby/1.8/amazon/search.rb:939:in `get_page'
	from /usr/local/lib/site_ruby/1.8/amazon/search.rb:961:in `search'
	from /usr/local/lib/site_ruby/1.8/amazon/search.rb:697:in `keyword_search'
	from (irb):5:in `price_books'
	from (irb):11