a work on process

loads_from_amazon (Ruby on Rails plugin)

You are reading a post by James Stewart entitled loads_from_amazon (Ruby on Rails plugin). It was posted on 20 July 2006 at 1:59 pm.

You can find more posts by returning to the index.

Filed under: Announcements
Tagged: , , ,

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 < ActiveRecord::Base
  acts_as_amazon
  maps_to_amazon_attribute :authorlist => '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'
end
 
@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.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts

 

10 Comments »

  • 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?

    Thanks
    Steve

    Comment by Steve — 20 December 2007 @ 10:33 pm

  • 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.

    Comment by James Stewart — 20 December 2007 @ 10:34 pm

  • 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?

    Comment by Tim Gossett — 28 December 2007 @ 10:20 pm

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

    Comment by James Stewart — 28 December 2007 @ 10:49 pm

  • 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?

    Comment by Ben Gibbs — 18 January 2008 @ 1:14 pm

  • 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.

    Comment by James Stewart — 20 January 2008 @ 4:52 pm

  • 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)?

    Thanks.

    Comment by roupen — 22 March 2008 @ 11:47 pm

  • 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…

    Comment by James Stewart — 23 March 2008 @ 9:41 am

  • 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

    Comment by albemuth — 17 June 2008 @ 5:04 pm

  • 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?

    Comment by James Stewart — 18 June 2008 @ 12:51 pm

TrackBack URI

Leave a comment

Login Method

OpenID

Anonymous