netphase / aaap

Acts as Amazon Product

This URL has Read+Write access

commit  48a80e7bedbb0d5f24a31b93278419da681207bd
tree    15f76c2eabce2e6e9ceaa210fb60de04c06abc27
parent  d797ef9d7fea6f2512ee8db7c701910ca9bcaf91
aaap /
name age message
file .gitignore Loading commit data...
file CHANGELOG
file COPYING Thu Apr 24 11:33:05 -0700 2008 initial import v1.1 [scottned]
file README
file Rakefile
file init.rb Thu Apr 24 11:33:05 -0700 2008 initial import v1.1 [scottned]
file install.rb Thu Apr 24 11:33:05 -0700 2008 initial import v1.1 [scottned]
directory lib/
directory tasks/ Thu Apr 24 11:33:05 -0700 2008 initial import v1.1 [scottned]
directory test/
file uninstall.rb Thu Apr 24 11:33:05 -0700 2008 initial import v1.1 [scottned]
README
= ActsAsAmazonProduct

This "acts_as" module makes it extremely simple to add Amazon integration to an existing model.  

== Setup

This 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:

  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

== Using acts_as_amazon_product

Add the "acts_as" line to your model.  Only :access_key is required.  The :asin and :name assignments override what 
attributes in your class should be used for a direct lookup (item_looup) or general search (item_search).  If no value 
is assigned to :asin then a general search is made and the first item (sorted by salesrank) is assigned (this 
functionality will likely change).

  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

You can now access the Amazon data in your views like so (see):

  @book = Book.new(:title => 'Getting Things Done')
  @book.amazon.isbn
  @book.amazon.title
  @book.amazon.author
  @book.amazon.small_image_url
  
  or
  @book.amazon.get('itemattributes/foobar')

== Unit tests

There are tests you can run in the [gem]/test directory.  Just create a test/config.yml from the example and run "Rake 
test" from the [gem] directory.

= Credits
acts_as_amazon_product was credited by Scott Nedderman and Chris Beck from netphase.com

We'd love to here how you like it.  Also, if you'd like us to help out with your next project, let us know. 

http://netphase.com