REST is not so easy either

This afternoon, I was browsing through some photosets on Flickr, but the photos weren’t loading quickly. I thought to myself, why don’t I download them now and go through them later?

, but I couldn’t find a link to download a photoset.

I remembered that Flickr has an API, so I can write something myself to do it. It shouldn’t take long, maybe an hour, max. From their services page, I saw Ruby implementations. Even better, I thought, I’ll use that.

I started with flickr.rb, but immediately I hit my first setback.

It offered me a gems file. Flipping through my Pickaxe book, I see that RubyGems is the preferred way for installing Ruby modules. Sounds good, but Ubuntu doesn’t come with RubyGems, probably because it “clashes” with apt. After 10 minutes of looking around, I gave up on using Gems and downloaded the source directly.

I went back to my book to make sure I was including the library correctly and hit another setback. Flickr.rb requires xmlsimple, something akin to Perl’s XML::Simple module. I searched Ubuntu’s repos, but they don’t have it. I downloaded the tarball, built and installed it. That took another 10 minutes.

Let’s start cooking. But before that, I needed to get an API key to use the service. Ten minutes later, I got the magic key.

I got back into emacs and started reading the included samples. It looks pretty easy. I wrote something simple to test it:

f =
user = f.users('some user') do |photo|

puts photo.url

It was slow and the URL is wrong, but I got something back. I wrote more code for going filtering through the photos from a user’s photoset. I ran it again, but I got nothing. I added some more lines for debugging and saw that it wasn’t returning any of the photos at all. In fact, the binding to flickr.photosets.getPhotos is actually marked as incomplete. Sigh. I tried to see if I can implement it myself. I tried to switch to the other Ruby implementation but the docs are even thinner. I took a brief look at the Python ones and they didn’t seem so hot either.

However, the API Explorer did work and the URL requests really are quite simple. So I decided to write my own implementation in Squeak, because I know Smalltalk better than I do Python or Ruby. I defined a class and started writing methods. I noticed I need to authenticate before I can make any calls. I followed the instructions and began to write a method to handle it.

Except I couldn’t find a method for doing MD5 sums. I asked on the IRC channel, they (basically) told me to file a bug.

By now, I was pretty pissed off. What was supposed to take 30 mins ended up taking an afternoon, and I still didn’t have anything usable. I really didn’t care much about the photos at this point.

Lately, I have been going back to the SOAP and WS-* specs and re-reading them. The last time I read WS-Addressing was before it got accepted into the W3c. Of course, SOAP is complicated and the discussions on EndpointReferences vs. URIs go on endlessly, but I just can’t help but think that grabbing a WSDL of a service and pumping it through ASP.NET Web Services (or better yet, Indigo) is easier than what I had (not) achieved this afternoon in trying to use the Flickr API.

Someone told me there’s a Flickr.NET. I’ll try it when I feel less pissed off about this whole thing. Heck, it might even work.


  1. Jay R. Wren:

    I can relate to your frustration on two points. I also recently tried ruby development on Ubuntu. As soon as I needed a Gem I gave up, I’m glad you went a step further and did the source, maybe I’ll do that next time.

    I’ve done some flickr development. I found the perl API to be very easy to use. Of course perl is a horrible language compared to python, ruby, or smalltalk, but it really was not difficult. The hardest part was finding how to access what I wanted. The perl api just read the xml response into a hash with node names as keys. Useing a perl debugger is not fun.

    Good luck. Maybe we could team up to start packaging some of those ruby modules for Ubuntu/Debian.

  2. AC:

    Well if you aren’t too annoyed to want to continue you might check into phpFlickr or one of the tools based on it. It even has a wordpress specific plugin last I knew.

  3. Roy Tate:

    I only installed Ruby and Gem via APT-GET, then used Gem for Rake, Rails, etc. It is easy, and I can get anything I want on RubyForge. If I used APT-GET, I would still have to download and install all of the packages that Ubuntu/Debian don’t cover.

  4. HMM:

    Just because you couldn’t install RubyGems or that you found a bug in the Ruby implementation you got doesn’t mean REST is hard.
    In fact, that’s the single most stupid argument I’ve ever heard against REST and pro SOAP and that just to advertise ASP.NET Web Services (or better yet, Indigo).
    Stop spreading FUD and get a life.

  5. Chui Tey:

    One of the implicit assumptions behind a REST API is that the document is the interface. The Ruby API is just one interpretation of the document structure.

    I volunteer that the problems you encountered is a vindication of a doc-literal approach as opposed to the RPC-wrapper that WSDL generates.

    Integration is hard, especially since you are dealing with unfamiliar semantics. Rip up all the layers of indirection caused by the wrappers and you end up with a nice transparent description of the service.

Leave a comment