ruby-amazonでAmazonWebService
ちょっと堕落して[RAA:ruby-amazon]でAWS。
インストール
略。
特別なことはなかったよ。
keywordで検索
example/searchが参考になります。
#!/usr/local/bin/ruby
require 'amazon/search'
class AmazonWebService
  def initialize(tag = 'ilikeruby-22', locale = 'jp')
    @devtag = get_devtag
    @tag = tag
    @locale = locale
    @amazon = Amazon::Search::Request.new(@devtag, @tag, @locale)
  end
  attr_reader :amazon
  def keyword_search(text, &block)
    @amazon.send('keyword_search', text, 'books', true, &block)
  end
  private
  def get_devtag
    File.open(File.expand_path("~/.amazon_key")) do |fp|
      return fp.read.chomp
    end
  end
end
if __FILE__ == $0
  def show_item(item)
    puts "== #{item.product_name}"
    puts "* asin: #{item.asin}"
    puts "* manufacturer: #{item.manufacturer}"
  end
  amazon = AmazonWebService.new
  while line = gets
    begin
      keyword = line.chomp
      amazon.keyword_search(keyword) do |item|
        show_item(item)
      end
    rescue
      p $!
    end
  end
end



