amazon-ecsを試す


EXAMPLEを参考にしてプログラムを作ってみる。

require 'rubygems'
require 'amazon/ecs'


Amazon::Ecs.options = {
 :aWS_access_key_id => ["ここにはアクセスキーIDを設定"],
 :associate_tag => "ここにはアソシエイトIDを設定",
 :country => :jp
}

res = Amazon::Ecs.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})

print "res.is_valid_request? : #{res.is_valid_request?}\n"
print "res.has_error? : #{res.has_error?}\n"
print "res.error :" #{res.error}\n"
print "res.total_pages : #{res.total_pages}\n"
print "res.total_results : #{res.total_results}\n"
print "res.item_page : #{res.item_page}\n"

res.items.each do |item|
	print "asin : #{item.get('asin')}\n"
	print "itemattributes/title : #{item.get('itemattributes/title')}\n"

	atts = item.search_and_convert('itemattributes')
	print "title : #{atts.get('title')}\n"

	print "author : #{atts.get('author')}\n"          # 'Author 1'
	print "author : #{atts.get_array('author')}\n"    # ['Author 1', 'Author 2', ...]

	print "smallimage : #{item.get_hash('smallimage')}\n"
end


上記のプログラムを実行した結果

$ ruby amazon_ecs_example.rb
res.is_valid_request? : true
res.has_error? : false
res.error :res.total_pages : 11
res.total_results : 110
res.item_page : 0
asin : B001ACG1TQ
itemattributes/title : The Ruby (ザ・ルビー) 2008年 07月号 [雑誌]
title : The Ruby (ザ・ルビー) 2008年 07月号 [雑誌]
author : 
author : 
smallimage : 
asin : 4844325795
itemattributes/title : まるごと Ruby! Vol.1
title : まるごと Ruby! Vol.1
author : るびきち
author : るびきちarton大場 光一郎高井 直人後藤 謙太郎新井 俊一瀧内 元気cuzic倉貫 義人大場 寧子久保 優子十河 学舞波
smallimage : width53urlhttp://ecx.images-amazon.com/images/I/61BONHQc2nL._SL75_.jpgheight75
asin : 4839928266
itemattributes/title : Ruby on Rails 逆引きクイックリファレンス Rails 2.0対応
title : Ruby on Rails 逆引きクイックリファレンス Rails 2.0対応
author : 大場 寧子
author : 大場 寧子大場 光一郎久保 優子
smallimage : width52urlhttp://ecx.images-amazon.com/images/I/41nTPEtVmPL._SL75_.jpgheight75
asin : 4797336617
itemattributes/title : たのしいRuby 第2版 Rubyではじめる気軽なプログラミング
title : たのしいRuby 第2版 Rubyではじめる気軽なプログラミング
author : 高橋 征義
author : 高橋 征義後藤 裕蔵
smallimage : width52urlhttp://ecx.images-amazon.com/images/I/3138132M6EL._SL75_.jpgheight75
asin : 477751353X
itemattributes/title : はじめてのRuby on Rails 2―話題の「Webアプリケーション・フレームワーク」が使える! 便利なフレームワーク (2) (I/O BOOKS)
title : はじめてのRuby on Rails 2―話題の「Webアプリケーション・フレームワーク」が使える! 便利なフレームワーク (2) (I/O BOOKS)
author : 清水 美樹
author : 清水 美樹
smallimage : width53urlhttp://ecx.images-amazon.com/images/I/41TVHSXz90L._SL75_.jpgheight75
asin : 4798114723
itemattributes/title : 10日でおぼえる Ruby on Rails入門教室
title : 10日でおぼえる Ruby on Rails入門教室
author : arton
author : arton
smallimage : width59urlhttp://ecx.images-amazon.com/images/I/51ULhLrQunL._SL75_.jpgheight75
asin : 4798115339
itemattributes/title : Ruby Way 第2版 (Professional Ruby Series)
title : Ruby Way 第2版 (Professional Ruby Series)
author : Hal Fulton
author : Hal Fulton
smallimage : width60urlhttp://ecx.images-amazon.com/images/I/51okU1xsXlL._SL75_.jpgheight75
asin : 4873113539
itemattributes/title : RESTful Webサービス
title : RESTful Webサービス
author : Leonard Richardson
author : Leonard RichardsonSam Ruby
smallimage : width58urlhttp://ecx.images-amazon.com/images/I/51ojIhXBP3L._SL75_.jpgheight75
asin : 4873113563
itemattributes/title : Rubyスクリプティングテクニック ―テスト駆動による日常業務処理術
title : Rubyスクリプティングテクニック ―テスト駆動による日常業務処理術
author : Brian Marick
author : Brian Marick
smallimage : width58urlhttp://ecx.images-amazon.com/images/I/41P4GL5v1aL._SL75_.jpgheight75
asin : 4274066428
itemattributes/title : プログラミングRuby 第2版 言語編
title : プログラミングRuby 第2版 言語編
author : Dave Thomas
author : Dave ThomasChad FowlerAndy Hunt
smallimage : width57urlhttp://ecx.images-amazon.com/images/I/4151YFZ27NL._SL75_.jpgheight75