I’m proud to announce the release of my very first gem: THUMBNAIL. It’s a Ruby wrapper for the Amazon Web Services Alexa Site Thumbnail Service, which lets you automatically download thumbnails of any website or dynamically embed them in your own pages for an incredibly small fee ($0.20 per 1000 images). And it has a badass logo (see above)!
You can get it from RubyForge thusly:
$ sudo gem install thumbnail
You’ve got to do some bureaucratic overhead at Amazon before you can play (more about that on the THUMBNAIL homepage), but once you do it’s just as easy as pie to download pix of sites from around the web like so:
require 'rubygems'
require 'thumbnail'
require 'open-uri'
t = Thumbnail::Client.new :access_key_id => YOUR_ACCESS_KEY_ID,
:secret_access_key => YOUR_SECRET_ACCESS_KEY
url = t.get("www.urbanhonking.com")[:thumbnail][:url]
File.open("urho.jpg", "w") { |f| f.write open(url).read }
where YOUR_ACCESS_KEY_ID and YOUR_SECRET_ACCESS_KEY are things you get from Amazon when signing up for the service. Running such code would make you the proud owner of a local copy of an image like this:
THUMBNAIL will also build you a url you can include in any webpage that will redirect to the site thumbnail you want like so:
require 'thumbnail'
t = Thumbnail::Client.new :access_key_id => YOUR_ACCESS_KEY_ID,
:secret_access_key => YOUR_SECRET_ACCESS_KEY,
:action => :redirect
url = t.get("www.twitter.com")
#=> http://ast.amazonaws.com/?Action=Redirect&AWSAccessKeyId=YOUR_ACCESS_KEY_ID
&Signature=sdhfiawrkjw3h9bncoa8ue&Timestamp=2007-06-14T09:09:18.000Z&Url=www.tw
itter.com&Size=Large
I’m working on a Rails plugin that will provide a view helper so you can easily do this from any template, but for now you’ll have to be satisfied with the additional sample code available on the THUMBNAIL RDoc.
There are all kinds of other details available at the THUMBNAIL homepage. And the code is, of course, available to all for free under the MIT License. So, Go! Get your thumbs dirty! Enjoy!
Tagged: thumbnail, ruby, aws, amazon, web, service, alexa, api, rubyforge, gem
Whoa, very cool.
This is great for accessing the thumbnails, but if you’re after the Alexa Web Info (such as traffic rank), I recommend the AWIS4Ruby project:
http://labs.votanweb.com/awis4ruby/