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” %>
<%=image_tag(img[1],:alt=>’Amazon’,:title=>’Product’)%> <br/>
<%end%>

<%end%>

<%end%> <!–if check       –>
<%item['ItemAttributes'].each  do | attri|%>

<% if attri[0]==”Title” %>
Title:-<%=attri[1]%> <br/>
<%end%>

<% if attri[0]==”ListPrice” %>
<%attri[1].each  do | pric|%>
<% if pric[0]==”FormattedPrice” %>
Prize:-<%=pric[1]%> <br/>
<%end%>
<% if pric[0]==”Amount” %>
<%#*Amount:-<%=pric[1]%> <br/>
<%end%>
<%end%>
<%end%>
<% end %>
<br/>
<br/>———————————————————— <br/><br/>
<%end %>

Sources

1) http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/

2) http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?RG_ItemAttributes.html

3) https://www.relishapp.com/papercavalier/sucker/docs/item-search

4) http://rubydoc.info/github/hakanensari/amazon_product/master/frames

5) https://github.com/hakanensari/amazon_product/

6) http://code.papercavalier.com/amazon_product/

7) https://github.com/hakanensari/amazon_product/tree/master/examples