Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Amazon E-Commerce Service (ECS)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> In & Arround Ruby on Rails
View previous topic :: View next topic  
Author Message
kittu



Joined: 05 Sep 2008
Posts: 26

PostPosted: Sun May 10, 2009 6:49 pm    Post subject: Amazon E-Commerce Service (ECS) Reply with quote

What was formerly the ECS - eCommerce Service - has been renamed the Amazon Associates Web Service. Through this API developers can retrieve product information.

The API exposes Amazon's product data and e-commerce functionality.

This allows developers, web site publishers and others to leverage the data that Amazon uses to power its own business, and potentially make money as an Amazon affiliate.

Both REST and SOAP APIs are provided.


Amazon.com developed A2S toward three classifications of users:

Associates: third-party site owners wishing to build more effective sponsored affiliate links to Amazon products, thus increasing their referral fees

Vendors: sellers on the Amazon platform looking to manage inventory and receive batch product data feeds

Developers: third-party developers building Amazon-driven functionality into their applications


An amazon-ecs is a generic Amazon E-commerce REST API with configurable default options and method call options.
It uses Hpricot to parse the XML output. Use Response and Element wrapper classes for easy access to the XML elements, and it supports ECS 4.0.

It is generic, so you can extend Amazon::Ecs to support the other not-implemented operations easily; and the response object just wraps around Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.

With that, if in the future, there is a change in REST XML output structure, no changes will be required on amazon-ecs, instead you just need to change your element path.


Installation of amazon-ecs
$ gem install amazon-ecs


Example
Initiating a search request:
require 'amazon/ecs'

# default options; will be camelized and converted
# to REST request parameters.
Amazon::Ecs.options = {:aWS_access_key_id => [your access key]}
res = Amazon::Ecs.item_search('ruby')

# or you can provide additional options
res = Amazon::Ecs.item_search('ruby', :response_group => 'Medium', :sort => 'salesrank')

# to search other Amazon UK
res = Amazon::Ecs.item_search('ruby', :country => :uk)
Retrieving common response values:
# some common response object methods
res.is_valid_request?
res.has_error?
res.error
res.total_pages
res.total_results
res.item_page
Retrieving items, and item attributes:
# traverse through each item (Amazon::Element)
res.items.each do |item|
# retrieve string value using XML path
item.get('asin')
item.get('itemattributes/title')

# or return Amazon::Element instance
atts = item.search_and_convert('itemattributes')

# get title as a string
atts.get('title')

# get only returns the first element of an array
atts.get('author') # 'Author 1'

# to retrieve an array
atts.get_array('author') # ['Author 1', 'Author 2', ...]

# to retrieve a hash of children text values
item.get_hash('smallimage') # {:url => ..., :width => ..., :height => ...}

# '/' returns Hpricot::Elements array object, nil if not found
reviews = item/'editorialreview'

# traverse through Hpricot elements
reviews.each do |review|
# Getting a hash value out of Hpricot element
Amazon::Element.get_hash(review) # [:source => ..., :content ==> ...]

# Or to get unescaped HTML values
Amazon::Element.get_unescaped(review, 'source')
Amazon::Element.get_unescaped(review, 'content')

# Or this way
el = Amazon::Element.new(review)
el.get_unescaped('source')
el.get_unescaped('content')
end
end
Back to top
View user's profile Send private message
s.nagesh



Joined: 23 Jul 2007
Posts: 115

PostPosted: Mon May 11, 2009 11:46 am    Post subject: Reply with quote

helpful post

Rating : 3
Back to top
View user's profile Send private message
umamahesh_nyros



Joined: 17 Jul 2007
Posts: 220
Location: KAKINADA

PostPosted: Mon May 11, 2009 12:09 pm    Post subject: Reply with quote

Good

Rating : 3
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
sivakrishna.m



Joined: 01 Jan 2008
Posts: 160
Location: Narsipatnam

PostPosted: Mon May 11, 2009 12:12 pm    Post subject: Re:Amazon E-Commerce Service (ECS) Reply with quote

Hi Kittu,

Nice Posting about Amazon E-Commerce Service (ECS) and very useful to me.

Rating : 3.5

Thank You,
Siva Krishna.
Back to top
View user's profile Send private message Send e-mail
vijay



Joined: 08 May 2008
Posts: 63

PostPosted: Tue May 12, 2009 2:18 am    Post subject: Reply with quote

Hi kittu,

Nice post.

Rating : 3
Back to top
View user's profile Send private message
satya



Joined: 08 May 2008
Posts: 62

PostPosted: Tue May 12, 2009 12:22 pm    Post subject: Reply with quote

Good Work

Rating : 3
Back to top
View user's profile Send private message
sharma I



Joined: 13 Jun 2008
Posts: 116

PostPosted: Tue May 12, 2009 12:40 pm    Post subject: Reply with quote

Nice Post regarding Amazon E-Commerce Service (ECS)

Rating: 3.5
Back to top
View user's profile Send private message
chaitanyab_nyros



Joined: 27 Aug 2007
Posts: 47

PostPosted: Wed May 13, 2009 8:55 am    Post subject: Reply with quote

Nice Post

Rating: 3
Back to top
View user's profile Send private message
mbchowdari



Joined: 08 May 2008
Posts: 52

PostPosted: Wed May 13, 2009 9:04 am    Post subject: Reply with quote

Hi kittu,

Good


Rating : 3
Back to top
View user's profile Send private message Send e-mail
nagakishore



Joined: 07 May 2009
Posts: 15

PostPosted: Wed May 13, 2009 9:07 am    Post subject: Reply with quote

Nice Post

Rating: 3.5
Back to top
View user's profile Send private message
mheidt



Joined: 16 Jun 2009
Posts: 4

PostPosted: Tue Jun 16, 2009 8:03 pm    Post subject: Reply with quote

Nice Post.

But as of 08/15/09 a signature will be required

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?RequestAuthenticationArticle.html

How will this look like in rails?
Back to top
View user's profile Send private message
kittu



Joined: 05 Sep 2008
Posts: 26

PostPosted: Fri Jul 03, 2009 5:20 am    Post subject: Reply with quote

hi mheidt, first you need to get AWS access key ID and associate ID that you have acquired from Amazon.com. Next install AWS gem as follows

$gem install amazon-ecs --include-dependencies
This will install the Amazon ECS Ruby gem from the remote gem repository and will also install Hpricot if you don't have Hpricot installed.

After successful installation. Create sample rails application. In that create a controller and add the following lines.

include Amazon
@@book_asin = '0974514055'

def sidebar
@book = get_book_details @@book_asin
@similars = get_similar_products @@book_asin
end


After that Creating the Amazon Rails library

This is a Ruby module that we include in your book controller. It contains the main processing logic of the mashup. It is used mainly to communicate with the Amazon ECS API provided by Amazon.com, using the Amazon ECS Ruby library.

Create a Ruby file in the RAILS_ROOT/lib folder called amazon.rb. For those uninitiated in Ruby on Rails, all Ruby files placed here are directly accessible to the Rails application during run time. This is why we only need to add the line include Amazon in the controller.

require 'amazon/ecs'
module Amazon
@@key_id = <your Amazon.com access key ID>
@@associate_id = <your associate ID>

# get the details of the book given the ASIN
def get_book_details(asin)
book = Hash.new
res = ecs.item_lookup(asin, :response_group => 'Large')
book[:title] = res.first_item.get("title")
book[:publication_date] = res.first_item.get("publicationdate")
book[:salesrank] = res.first_item.get("salesrank")
book[:image_url] = res.first_item.get("mediumimage/url")
book[:author] = res.first_item.get("itemattributes/author")
book[:isbn] = res.first_item.get("itemattributes/isbn")
book[:price] = res.first_item.get("price/currencycode") + res.first_item.get("price/formattedprice")
book[:total_reviews] = res.first_item.get("customerreviews/totalreviews")
book[:average_rating] = res.first_item.get("customerreviews/averagerating")
book[:offer_listing_id] = res.first_item.get("offerlisting/offerlistingid")
return book
end

# get similar products to a given ASIN
def get_similar_products(asin)
similars = Array.new
res = ecs.send_request(:aWS_access_key_id => @@key_id, : operation => 'SimilarityLookup', :item_id => asin, : response_group => 'Small,Images' )
res.items.each do |item|
similar = Hash.new
similar[:asin] = item.get('asin')
similar[:title] = item.get('itemattributes/title')
similar[:author] = item.get('itemattributes/author')
similar[:small_image] = item.get_hash('smallimage')
similars << similar
end
return similars
end

protected
# configure and return an Ecs object

def ecs
Amazon::Ecs.configure do |options|
options[:aWS_access_key_id] = @@key_id
options[:associate_tag] = @@associate_id
end
return Amazon::Ecs
end
end

Note that as before, this is not how the file will finally look. We will be adding more functions in terms of methods, as we go along.
We will need to require the Amazon ECS Ruby library, and also define the AWS access key ID and associate ID that you have acquired from Amazon.com

After that create appropriate view to display the output.

I think this will help to you.

Regards,
kittu
Back to top
View user's profile Send private message
mheidt



Joined: 16 Jun 2009
Posts: 4

PostPosted: Fri Jul 03, 2009 7:37 am    Post subject: Reply with quote

Thanks a lot.

The missing piece in my code was:
options[:associate_tag]
Back to top
View user's profile Send private message
mheidt



Joined: 16 Jun 2009
Posts: 4

PostPosted: Tue Aug 18, 2009 5:17 pm    Post subject: Reply with quote

The required tag isn't associate_tag but

aWS_secret_key
Back to top
View user's profile Send private message
foozilla



Joined: 19 Aug 2009
Posts: 1

PostPosted: Wed Aug 19, 2009 10:16 pm    Post subject: Reply with quote

what do you mean by "aWS_secret_key"?

Can you help me out?

I can't connnect to Amazon API because they want signed API call.

so how do I do this?

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> In & Arround Ruby on Rails
Page 1 of 2

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Documentation
0 Anu 8 Thu Mar 18, 2010 4:01 am
Anu View latest post
No new posts File handling in ruby
0 Anu 18 Wed Mar 17, 2010 2:14 pm
Anu View latest post
No new posts sending an email from rb file
0 umamahesh_nyros 15 Wed Mar 17, 2010 6:13 am
umamahesh_nyros View latest post
No new posts difference bewteen render component and render partial
0 umamahesh_nyros 11 Wed Mar 17, 2010 6:06 am
umamahesh_nyros View latest post
No new posts Acts_as_tsearch plugin
0 swaminadhan 23 Sat Mar 13, 2010 9:10 am
swaminadhan View latest post
No new posts Built in classes in ruby
0 ktulasi 33 Thu Mar 11, 2010 1:09 pm
ktulasi View latest post
No new posts User defined classes and types of variables.
2 swaminadhan 51 Wed Mar 10, 2010 4:40 am
swaminadhan View latest post
No new posts Background & Introduction of ruby
0 Divya 49 Mon Mar 08, 2010 12:59 pm
Divya View latest post
No new posts i have lost the data in schema.rb file in rails application
0 Raja 57 Thu Mar 04, 2010 4:46 am
Raja View latest post
No new posts AlertPay
0 Raghu 37 Mon Mar 01, 2010 11:36 am
Raghu View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More