Last active
December 16, 2015 14:29
-
-
Save tomoyamkung/5448863 to your computer and use it in GitHub Desktop.
[Ruby]amazon-ecs を使った関連商品情報取得サンプル。関連商品5件の ASIN を取得する。ResponseGoup は Similarities を指定。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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