SOAP4R¤ÇAmazon Web Service
SOAP4R¤ò»È¤Ã¤ÆAmazon Web Service¤òÍøÍѤ·¤¿¤È¤¤Î¥á¥â¡£ ¤¢¤ó¤Þ¤ê¼Â¤¬¤Ê¤¤¤Ê¤¢¡£
SOAP4R¤ÇAWS
Amazon Hacks À¤³¦ºÇÂç¤Î¥·¥ç¥Ã¥Ô¥ó¥°¥µ¥¤¥È´°Á´³èÍѥƥ¯¥Ë¥Ã¥¯100Áª
Amazon¤ÎÄ󶡤·¤Æ¤¯¤ì¤ëWeb Service - AWS¤ò»È¤Ã¤Æ¡¢¾¦Éʤò¸¡º÷¤·¤¿¤ê ½ñÀÒ¾ðÊó¤ò¼è¤ê½Ð¤·¤Æ¤ß¤Þ¤·¤¿¡£ AWS¤Ç¤ÏXML-RPC¤äSOAP¤Ê¤ÉÊ£¿ô¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤òÄ󶡤·¤Æ¤¤¤Þ¤¹¡£ º£²ó¤ÏNaHi¤µ¤ó¤ÎSOAP4R¤ò»È¤Ã¤Æ³Ú¤ò¤·¤Á¤ã¤¤¤Þ¤·¤¿¡£
¼ê½ç
Token¤ÎÆþ¼ê
AWS¤Î¥µ¡¼¥Ó¥¹¤òÍøÍѤ¹¤ë¤Ë¤Ï¡¢¥Ç¥Ù¥í¥Ã¥Ñ¡¼¡¦¥È¡¼¥¯¥ó¤¬É¬ÍפǤ¹¡£ ¼¡¤Î¥Ú¡¼¥¸¤¬»²¹Í¤Ë¤Ê¤ê¤Þ¤¹¡£
<URL:http://www.amazon.co.jp/exec/obidos/subst/associates/join/webservices.html>
¤³¤Î¥Ú¡¼¥¸¤Ë½Ð¤Æ¤ë¤±¤É¡¢SDK¤ò¥À¥¦¥ó¥í¡¼¥É¡¢Token¤ò¼èÆÀ¤·¤Æ¥¢¥×¥ê¤ò½ñ¤¤Þ¤¹¡£
- SDK¤ò¥À¥¦¥ó¥í¡¼¥É - ¥É¥¥å¥á¥ó¥È¤¬Æþ¤Ã¤Æ¤Þ¤¹¡£±Ñ¸ì¡£
- Token¤Î¼èÆÀ - ¤ä¤Ï¤ê±Ñ¸ì¤Î¥Ú¡¼¥¸¤Ç¤¹¡£
- ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î³«È¯
¥¢¥½¥·¥¨¥¤¥È¡¦¥×¥í¥°¥é¥à¤Ø¤Î»²²Ã¤Ïɬ¿Ü¤Ç¤Ê¤¤¤è¤¦¤Ç¤¹¤Í¡£ »ä¤Ï¥¢¥½¥·¥¨¥¤¥È¤Î»²²Ã¤·¤Æ¤¿¤Î¤Ç¤½¤ÎID¤ò»È¤¦¤³¤È¤Ë¤·¤Þ¤·¤¿¡£
SOAP4R¤Î½àÈ÷
RAA¤«¤éSOAP4R¤ò¥À¥¦¥ó¥í¡¼¥É¤·¤Þ¤¹¡£ ¤³¤Î¥Ú¡¼¥¸¤ò½ñ¤¤¤Æ¤¤¤ë¸½ºß(2004-09-05)¤Î¥Ð¡¼¥¸¥ç¥ó¤Ï1.5.2¤Î¤è¤¦¤Ç¤¹¡£
»ä¤Ïruby-1.8·Ï¥Ö¥é¥ó¥Á¤ÎÀèü¤ò»ÈÍѤ·¤Æ¤¤¤Þ¤¹ *1 ¤¬¡¢SOAP4R¥é¥¤¥Ö¥é¥ê¼«ÂΤÏ1.5.2¤ÈƱÍͤʤ褦¤Ç¤¹¡£
¤·¤«¤·WSDL¤«¤éRuby¤Î¥¯¥é¥¹¤òÀ¸À®¤·¤Æ¤¯¤ì¤ëwsdl2ruby.rb¤Ï ruby¤Î¥¢¡¼¥«¥¤¥Ö¤Ë´Þ¤Þ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ RAA¤«¤é¥À¥¦¥ó¥í¡¼¥É¤·¤¿SOAP4R¤«¤éwsdl2ruby.rb¤ò¼è¤ê½Ð¤·¤ÆŬÀÚ¤Ê *2¤ËÃÖ¤¤¤Æ¼Â¹Ô¸¢¤òÀßÄꤷ¤Þ¤¹¡£
ruby-1.8.0¤ò»È¤Ã¤Æ¤¤¤ë¤Ê¤éSOAP4R¤Î¥é¥¤¥Ö¥é¥ê¤â¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿Êý¤¬ ¤¤¤¤¤Î¤«¤â¡£(¼Â¸³¤Ç¤¤Ê¤¤¤«¤é¤ï¤«¤é¤Ê¤¤¤Ç¤¹¡£¤´¤á¤ó)
wsdl2ruby¤Ë¤è¤ë¥¯¥é¥¹ÄêµÁ¤ÎÀ¸À®
SDK¤Î¥É¥¥å¥á¥ó¥È¤ËWSDL¤ÎURL¤¬ºÜ¤Ã¤Æ¤¤¤Þ¤¹¡£ wsdl2ruby.rb¤Ë¤½¤ÎURL¤òÅϤ·¤ÆRuby¤Î¥¯¥é¥¹ÄêµÁ¤òÀ¸À®¤·¤Æ¤â¤é¤¤¤Þ¤·¤ç¤¦¡£
% wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas3/AmazonWebServices.wsdl --classdef --force
AmazonSearch.rb¤È¤¤¤¦¥Õ¥¡¥¤¥ë¤¬¤Ç¤¤Þ¤·¤¿¤«? ¤¤Ã¤È¤Ç¤¤¿¤È»×¤¤¤Þ¤¹¡£
Ãæ¤ò¸«¤ë¤È¥¢¥¯¥»¥µ¤¬¤¿¤¯¤µ¤óÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£ XSDL¤ò¼«Ê¬¤ÇÆɤळ¤È¤ËÈæ¤Ù¤¿¤éwsd2ruby¤ÎÀ¸À®¤¹¤ëRuby¥¹¥¯¥ê¥×¥È¤òį¤á¤ëÊý¤¬´Êñ¤Ç¤¹¡£ ¥¯¥¨¥ê¤Î·ë²Ì¤Î»ÅÍͤò¥É¥¥å¥á¥ó¥È¤«¤éõ¤¹¤è¤ê¤â¤³¤Î¥¹¥¯¥ê¥×¥È¤òÄ´¤Ù¤ëÊý¤¬Â®¤½¤¦¤Êµ¤¤¬¤·¤Þ¤¹¡£
proxy
proxy·Ðͳ¤Ç»î¤¹¤Ë¤Ï¼¡¤ÎÀßÄ꤬ɬÍפߤ¿¤¤¡£
SOAP_USE_PROXY=on HTTP_PROXY=http://foo.bar:port
¼Â¸³
¤³¤ó¤Ê¤Î¤ò½ñ¤¤¤Æ¼Â¸³¤·¤Æ¤ß¤Þ¤·¤¿¡£ ½ñÀÒ¤ò¥¡¼¥ï¡¼¥É¤Ç¸¡º÷¤·¤Æ·ë²Ì¤òɽ¼¨¤¹¤ë¥¹¥¯¥ê¥×¥È¤Ç¤¹¡£ www.amazon.com¤Ç¤Ï¤Ê¤¯www.amazon.co.jp¤òÍøÍѤ·¤Þ¤¹¡£
# aws0.rb require 'soap/wsdlDriver' require 'AmazonSearch.rb' class AmazonWebService def initialize(tag = 'ilikeruby-22') @devtag = get_devtag @tag = tag @amazon = SOAP::WSDLDriverFactory.new(wsdl).createDriver @amazon.generate_explicit_type = true end attr_reader :amazon def locale nil end def wsdl 'http://soap.amazon.com/schemas3/AmazonWebServices.wsdl' end def keyword_search(text) req = KeywordRequest.new(text, '1', 'book', @tag, "lite", @devtag) req.locale = locale if locale @amazon.KeywordSearchRequest(req).Details end private def get_devtag File.open(File.expand_path("~/.amazon_key")) do |fp| return fp.read.chomp end end end class AmazonCoJp < AmazonWebService def locale 'jp' end def wsdl 'http://soap.amazon.co.jp/schemas3/AmazonWebServices.wsdl' end end if __FILE__ == $0 def show_item(item) puts "== #{item.ProductName}" puts "* asin: #{item.Asin}" puts "* manufacturer: #{item.Manufacturer}" end $amazon = AmazonCoJp.new while line = gets begin keyword = line.chomp $amazon.keyword_search(keyword).each do |item| show_item(item) end rescue p $! end end end
¼Â¹Ô¤¹¤ë¤È¤¤Ïruby¤ËŬÀÚ¤Êʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ Î㤨¤Ð¤ÇUTF-8¤Çɽ¼¨¤·¤Æ¤¤¤ëüËö¤Î¾ì¹ç¤Ë¤Ï-Ku¡¢ EUC¤Ê¤é-Ke¤Ê¤É¤Ç¤¹¡£
% ruby -Ku aws0.rb druby ¢« ÆþÎϤ¹¤ë == dRuby¤Ë¤è¤ëʬ»¶¥ª¥Ö¥¸¥§¥¯¥È¥×¥í¥°¥é¥ß¥ó¥° * asin: 4756139612 * manufacturer: ¥¢¥¹¥¡¼ ruby way ¢« ÆþÎϤ¹¤ë == The Ruby Way?RubyÆ»¤Ø¤Î¾·ÂÔ * asin: 4798102288 * manufacturer: æƱ˼Ò
ʸ»ú¥³¡¼¥É¤Ë¤è¤Ã¤ÆŬÀÚ¤ÊÊÑ´¹¤ò¤·¤Æ¤¯¤ì¤ë¤Î¤ÏSOAP4R¤«¤Ê¤¢¡£ÊØÍø¤À¡£
wsdl2ruby¤ÇÀ¸À®¤·¤¿¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤ÏCamelCase¤Ê¤Î¤ÇÃí°Õ¡£ ¾¯¤·¤Ó¤Ã¤¯¤ê¤·¤Þ¤¹¡£ ¼ÂºÝ¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï°ìÃÊ¥é¥Ã¥×¤¹¤ë¥¯¥é¥¹¤ò¤ª¤¯¤Î¤«¤Ê¤¢¡£
±þÍÑ
¤³¤ì¤òÍøÍѤ·¤ÆRWiki¤ò³ÈÄ¥¤·¤Æ¤ß¤Þ¤·¤¿¡£ ¤³¤Î¥µ¥¤¥È(I like Ruby)¤âSOAP4R·Ðͳ¤ÇAWS¤òÍøÍѤ·¤Æºî¤é¤ì¤Æ¤¤¤Þ¤¹¡£
¤³¤ÎÏä㤤ÏThe RWiki¤Ç(¤Û¤ó¤È¤¦?)
*11.9¤ä1.8.0¤Î¾õ¶·¤Ï¤Á¤ç¤Ã¤È¤ï¤«¤ê¤Þ¤»¤ó¡£
*2»ä¤Ï/usr/local/bin/