我是一个 Rails 新手 - 有点过头了,可以使用一些帮助。
我有一个现有的 Rails 应用程序,我正在尝试将 Amazon Products API 与 gem“ruby-aaws”集成......即将项目放在模型中,在视图中显示它们等。
我以前从未使用过外部 API,所以我不确定从哪里开始集成。任何帮助都非常感谢!
以下是我用来通过 API 提取数据的一些代码:
require 'amazon/aws'
require 'amazon/aws/search'
include Amazon::AWS
include Amazon::AWS::Search
is = ItemSearch.new( 'Watches', { 'Keywords' => 'Gucci' } )
rg = ResponseGroup.new( 'Large' )
req = Request.new
req.locale = 'us'
resp = req.search( is, rg )
items = resp.item_search_response[0].items[0].item
# Available properties for first item:
#
puts items[0].properties
items.each do |item|
attribs = item.item_attributes[0]
puts attribs.label
if attribs.list_price
puts attribs.title, attribs.list_price[0].formatted_price, item.medium_image, ''
end
end