acts_as_amazon_product
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.
[ruby]
require ‘acts_as_amazon_product’
class Book < ActiveRecord::Base
acts_as_amazon_product(
:asin => ‘isbn’, :name => ‘title’,
:access_key => ‘0123456′,
:associate_tag => ‘assoc-20′)
end
[/ruby]
After this, you can access Amazon data in your controllers or views like this:
[ruby]
@book = Book.new(:title => ‘Getting Things Done’)
@book.amazon.isbn
@book.amazon.title
@book.amazon.author
@book.amazon.small_image_url
@book.amazon.get(’itemattributes/foobar’)
[/ruby]
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:
[ruby]
ActiveRecord::Base.connection.create_table :amazon_products do |t|
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
[/ruby]




