acts_as_amazon_product
Sep 26th, 2007 by scott
Today we released a new Ruby Gem that makes integrating with Amazon E-Commerce Service (ECS) a snap. It's called acts_as_amazon_product and you can find it on RubyForge.
All that's necessary to integrate any of your existing models with Amazon is to add a require line to the top of your model file and then an acts_as_amazon_product line just inside your class definition.
class Book <ActiveRecord::Base
acts_as_amazon_product(
:asin => 'isbn', :name => 'title',
:access_key => '0123456',
:associate_tag => 'assoc-20')
end
After this, you can access Amazon data in your controllers or views like this:
@book.amazon.isbn
@book.amazon.title
@book.amazon.author
@book.amazon.small_image_url
@book.amazon.get('itemattributes/foobar')
The code does not require changing any current database tables. It only requires adding one migration for a single new table used to cache responses from Amazon:
t.column :asin, :string
t.column :xml, :text
t.column :created_at, :datetime, :null => false
t.column :amazonable_id, :integer, :default => 0, :null => false
t.column :amazonable_type, :string, :limit => 15, :default => "", :null => false
end
Scott Nedderman is the founder of Netphase.com, a consulting practice that specializes in building web applications for Internet startups. He is also a vocalist, plays guitar and penny whistle, occasionally performs in musicals, enjoys camping and is a homeschooling father of 6.



