| View previous topic :: View next topic |
| Author |
Message |
kittu
Joined: 05 Sep 2008 Posts: 26
|
Posted: Sun May 10, 2009 6:49 pm Post subject: Amazon E-Commerce Service (ECS) |
|
|
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 |
|
 |
s.nagesh
Joined: 23 Jul 2007 Posts: 131
|
Posted: Mon May 11, 2009 11:46 am Post subject: |
|
|
helpful post
Rating : 3 |
|
| Back to top |
|
 |
umamahesh_nyros

Joined: 17 Jul 2007 Posts: 231 Location: KAKINADA
|
Posted: Mon May 11, 2009 12:09 pm Post subject: |
|
|
Good
Rating : 3 |
|
| Back to top |
|
 |
sivakrishna.m
Joined: 01 Jan 2008 Posts: 160 Location: Narsipatnam
|
Posted: Mon May 11, 2009 12:12 pm Post subject: Re:Amazon E-Commerce Service (ECS) |
|
|
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 |
|
 |
vijay
Joined: 08 May 2008 Posts: 63
|
Posted: Tue May 12, 2009 2:18 am Post subject: |
|
|
Hi kittu,
Nice post.
Rating : 3 |
|
| Back to top |
|
 |
satya
Joined: 08 May 2008 Posts: 78
|
Posted: Tue May 12, 2009 12:22 pm Post subject: |
|
|
Good Work
Rating : 3 |
|
| Back to top |
|
 |
sharma I
Joined: 13 Jun 2008 Posts: 130
|
Posted: Tue May 12, 2009 12:40 pm Post subject: |
|
|
Nice Post regarding Amazon E-Commerce Service (ECS)
Rating: 3.5 |
|
| Back to top |
|
 |
chaitanyab_nyros
Joined: 27 Aug 2007 Posts: 47
|
Posted: Wed May 13, 2009 8:55 am Post subject: |
|
|
Nice Post
Rating: 3 |
|
| Back to top |
|
 |
mbchowdari
Joined: 08 May 2008 Posts: 52
|
Posted: Wed May 13, 2009 9:04 am Post subject: |
|
|
Hi kittu,
Good
Rating : 3 |
|
| Back to top |
|
 |
nagakishore
Joined: 07 May 2009 Posts: 15
|
Posted: Wed May 13, 2009 9:07 am Post subject: |
|
|
Nice Post
Rating: 3.5 |
|
| Back to top |
|
 |
mheidt
Joined: 16 Jun 2009 Posts: 4
|
|
| Back to top |
|
 |
kittu
Joined: 05 Sep 2008 Posts: 26
|
Posted: Fri Jul 03, 2009 5:20 am Post subject: |
|
|
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 |
|
 |
mheidt
Joined: 16 Jun 2009 Posts: 4
|
Posted: Fri Jul 03, 2009 7:37 am Post subject: |
|
|
Thanks a lot.
The missing piece in my code was:
options[:associate_tag] |
|
| Back to top |
|
 |
mheidt
Joined: 16 Jun 2009 Posts: 4
|
Posted: Tue Aug 18, 2009 5:17 pm Post subject: |
|
|
The required tag isn't associate_tag but
aWS_secret_key |
|
| Back to top |
|
 |
foozilla
Joined: 19 Aug 2009 Posts: 1
|
Posted: Wed Aug 19, 2009 10:16 pm Post subject: |
|
|
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 |
|
 |
|