Klairvoyant infosolution's Blog

Amazon Product Advertising API Interface in Rails

john

1) In gem file add the following and bundle it.

gem ‘amazon_product’

2)

configure the request object in controller

a) req = AmazonProduct['us']

b)req.configure do |c|
c.key    = ‘YOURKEY’
c.secret = ‘YOURSECREAT’
c.tag    = ‘YOURTAG’
end

get your key,secret etc…  from

https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key

c) req << {
:operation    => ‘ItemSearch’,
:search_index => ‘All’,
:Keywords => ‘Book’,
:response_group => ['ItemAttributes','Images'],
:Version=> ‘2011-08-01′
}

3) get the results
@resp = req.get

code in view

<% @resp.each(‘Item’) do | item |%>
<%#*http://www.amazon.com/dp/<%= item['ASIN'] %>

<%g =item['MediumImage'].nil? %>

<% if g==false %>
<%item['MediumImage'].each  do | img|%>
<% if img[0]==”URL” %>
...

Read more