Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Last active December 16, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyamkung/5448863 to your computer and use it in GitHub Desktop.
Save tomoyamkung/5448863 to your computer and use it in GitHub Desktop.
[Ruby]amazon-ecs を使った関連商品情報取得サンプル。関連商品5件の ASIN を取得する。ResponseGoup は Similarities を指定。
# encoding: utf-8
require 'amazon/ecs'
require 'yaml'
require 'nokogiri'
class PaapiSimilaritiesSample
def initialize
@config = YAML.load_file('./paapi-similarities-sample.yaml')
Amazon::Ecs.options = {
:associate_tag => @config['associate_tag'],
:AWS_access_key_id => @config['AWS_access_key_id'],
:AWS_secret_key => @config['AWS_secret_key']
}
end
def search asin
res = Amazon::Ecs.item_lookup(asin, :response_group => "Similarities", :country => 'jp')
res.items.each do |item|
Nokogiri::XML(item.to_s).xpath('/Item/SimilarProducts/SimilarProduct/ASIN').each do |node|
p node.inner_text
end
end
end
end
if __FILE__ == $0
obj = PaapiSimilaritiesSample.new
asin = "4894712288"
asin = ARGV[0] unless ARGV[0] == nil
obj.search(asin).each do |x|
p x
end
end
associate_tag: XXX
AWS_access_key_id: YYY
AWS_secret_key: ZZZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment