loads_from_amazon (Ruby on Rails plugin)

UPDATE (10/2008): This plugin is no longer maintained. I’d recommend looking at one of the newer alternatives such as acts_as_amazon_product if you need this functionality.

I’ve been procrastinating on getting my first Ruby on Rails plugin (first anyone else might be interested in, at least) out the door, mainly due to some configuration problems with Subversion, but finally I have that all sorted out and the plugin ready to go.

loads_from_amazon is an ActiveRecord Mixin that works with the Ruby/Amazon library to let you populate an ActiveRecord object with the details of a product listed on amazon. In the README I use the following example:

class Book  'authors', :combine => ';'
  maps_to_amazon_attribute :title => 'product_name'
  maps_to_amazon_attribute :isbn => 'asin'
  maps_to_amazon_attribute :publisher => 'manufacturer'
  maps_to_amazon_attribute :pubdate => 'release_date'

@book = Book.load_from_amazon(isbn) # Loads but does not save
@otherbook = Book.load_from_amazon!(other_isbn) # Loads data and saves to database

So feel free to grab it from svn (http://projects.jystewart.net/svn/rails/loads_from_amazon/trunk) and let me know what you think.

Tags: , , ,


  1. This plugin looks interesting and just what I’m after for a current project. Sadly the svn repository is inaccessible, I’m asked for a login and password.

    Is this a glitch, or is the code no longer available?


  2. Sorry Steve. I’ve been moving to a new server and a few things aren’t yet configured as they should be. I’ll try and get onto that first thing tomorrow.

  3. This sounds like it’d be a great plugin. As soon as the svn repo is accessible, I’ll be downloading it.

    The repo is asking for HTTP Basic creds. Is there an anonymous account perhaps?

  4. Sorry about that. Anonymous access should be working now.

  5. Hi James,

    In the example you showed how to get the author, title, isbn, publisher and pubdate attributes of a book.

    I want to get other attributes but don’t know what values to use to gat that data. Specifically I want the image of the book cover. How do I get that information?

  6. Ben – The mapping is between the attribute names in Amazon’s Associate web services (previously E-commerce services) return values and the value you want it to be in your model.

    I believe the URL for a small image is in the smallimage attribute (but I may well be wrong as it’s a while since I looked at the API) so in that case you’d use:

    maps_to_amazon_attribute :image_url => ‘smallimage’

    Let me know how you get on. It’s been quite a while since I last worked with the plugin so it may well be due an overhaul.

  7. Hi James, thanks for posting this plug-in It looks like its exactly what I need.

    I’m new to Ruby and have not used the Amazon Associate Web Services before.

    Like Ben, my interest is in books. Users will enter ISBN, or title, or author, and I want to get back the balance of the info about a book including the cover thumbnail.

    I’m reading this http://docs.amazonwebservices.com/AWSECommerceService/2008-03-03/GSG/

    (given that I am noob :)) I am wondering where all that SETUP stuff is done in the case of your plugin (where keys are passed, etc)?


  8. roupen – at the moment those values aren’t configured anywhere, so you need to pass them into each method call:

    Model.load_from_amazon(asin_value, dev_key, associates_id)

    At some point I hope to rework the plugin to use the amazon-ecs gem (since that supports ECS 4) and at that point I aim to make this configurable to DRY up code. Since I don’t currently use this plugin in any active projects, it’s taking a while to get to the new version, but hopefully with time…

  9. Hi, I’ve been trying to get the example working but I get an error from the amazon lib, any ideas?

    Book.load_from_amazon(‘0439785960’, ‘xxxxxxxxxxxx’)
    Amazon::Search::Request::HTTPError: HTTP response code 410
    from /opt/local/lib/ruby/site_ruby/1.8/amazon/search.rb:991:in `get_page’
    from /opt/local/lib/ruby/site_ruby/1.8/amazon/search.rb:1013:in `search’
    from /opt/local/lib/ruby/site_ruby/1.8/amazon/search.rb:647:in `asin_search’
    from /home/dbc602e2/fbpoc/vendor/plugins/loads_from_amazon/lib/loads_from_amazon.rb:65:in `load_from_amazon’
    from (irb):30

  10. albemuth – it’s been quite a while since I used the plugin since the project I created it for is long since defunct. As I understand it the amazon ECS library I built it on top of isn’t maintained any more so it could well be using a version of the API that amazon no longer support.

    As mentioned above, if/when time allows I’d love to port it to use the amazon-ecs gem but I’m very busy at the moment so there’s no telling when I’ll get to it. It’s probably not a huge amount of work, so you might like to check out the gem and see whether you can hack it together?