Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gambuzino (4517)

gambuzino
  (email not shown publicly)
http://nunonunes.org/
Yahoo! ID: gambuzinix (Add User, Send Message)
Jabber: gambuzino@jabber.org

Journal of gambuzino (4517)

Sunday August 07, 2005
12:50 PM

Searching the Flickr API and iterators

[ #26159 ]

I've been slacking off on the Flickr-Tools project, mainly because it serves all my purposes as it is right now.

But then someone pinged me regarding the photos method in the Flickr::Person class (the one that will return all the photos for the user) and that was the incentive I needed to finally get to writing that method.

So now I remember why I left it half-way through...

The thing is that this method must use the flickr.photos.search method to get it's info and it could return a lot of info.

So flickr.photos.search has a mechanism for managing the potentially huge volume of information --it forces you to break up your request into "pages" of results-- which, of course, is the right way to do it.

But how do I map that onto my Flickr::Person class in a nice way? I surely don't want to make the user have to control things like results per page and current page and so on, that would defeat the purpose of the whole thing, but I sure as hell can't just go and fetch everything from Flickr because for a user with many photos I would blow up the computer's memory fast!

So after thinking about it for something like 10 seconds I knew that the right way to do it would be to use an iterator. Instead of returning an array of Flickr::Photo objects I should return a Flickr::Photogroup object (or somesuch) and it should have a few simple methods like next, previous and total. You know, a classic iterator. When it ran out of results it should then invoque the Flickr::API::Photos::search method to get the next batch of photos.

OK, that is a bit more work than I bargained for but it is the right way to do it.

But then all of the other methods which I've already written and which return groups of things (mostly photos) should also return this kind of object. And each instance should know how to get more results when it needs it, so it should be rather smart about what it is representing.

This means two things:

  1. I have to rewrite the interface for methods which are already out there (major turn-off)
  2. I have a lot more work ahead of me in order to do it

So I will make this re-write and, unfortunately, I probably won't be able to have it done by tomorrow as I told the poor soul who is expecting a new version of Flickr-Tools with the new method and, probably, no interface changes.

Should have though of that before, now shouldn't I? Duh!

(This entry is cross-posted from my personal weblog at http://nowhereland.nunonunes.org/archives/2005/08/searching_the_f.html)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.