Building a del.ico.us and flickr sidebar in 5 minutes

April 8, 2007

You need a del.icio.us sidebar which shows recent bookmarks or one of these nice flickr badges? This is really is easy as the Typo Weblog Engine already includes an flickr and del.icio.us aggregator.

Download the files delicous.rb and flickr.rb and drop them into your rails lib folder.

Now add these two little helpers to your application_helper.rb:

  1. require 'delicious'
  2. require 'flickr'
  3. def delicious(tag)
  4. Delicious.new("http://del.icio.us/rss/tag/#{tag}")
  5. end
  6. def flickr(tag)
  7. url = "http://api.flickr.com/services/feeds/photos_public.gne?"
  8. url << "tags=#{tag}&format=rss_200"
  9. FlickrAggregation.new(url)
  10. end

We are now able to fetch the feeds for our desired tags with a simple method call. Next step is to render a list of links for our sidebar. So for rendering the del.icio.us sidebar, you need something like this:

  1. <ul>
  2. <% for item in delicious(:ruby).items[0, 10] %>
  3. <li>
  4. <%= link_to item.title, item.link %>
  5. </li>
  6. <% end %>
  7. </ul>

This is pretty self-explanatory. We take the first ten items of the del.icio.us feed and for each item we output a list element containing a link to the item. The view for the flickr badge is similar:

  1. <ul>
  2. <% for item in flickr(:ruby).pics[0, 10] %>
  3. <%= image_tag item.square, :size => '48x48' %>
  4. <% end %>
  5. </ul>

We take the first ten items of the flickr feed and for each item we render an image tag which shows a square thumbnail of the size 48x48. Congratulations, you have just written a del.icio.us and flickr sidebar in 5 minutes using only 18 lines of code. Now you can spend the rest of the day pimping up your sidebar with all kinds of feeds using one of these plugins of the typo weblog.


Posted in category Ruby by Matthias Georgi. Tagged with ruby, flickr, delicious, rails.
Similar Posts