I have a Flickr interface that I wrote a while ago and part of it bothers me and I'd like to make it nicer. The way it works is I use method missing to construct the url parameters for the flickr call from the methods called on the flickr object, eg.
@flickr.groups.pools.getPhotos(:user_id => "12656878@N06", :group_id => "99404851@N00")
These 'method calls' construct an api call that looks like this
http://api.flickr.com/services/rest/?method=groups.pools.getPhotos&user_id=1848466274& group_id= 99404851@N00
(I have left off the api key bit) It does this by remembering each 'method' until a method is called with arguments at which time it constructs the url and and makes the call to Flickr.
The reason I took this approach is so the ruby code matches the documentation on the Flickr site, you can copy and paste it and it will mostly work, and hopefully it will make it a bit more resilient to api changes because I have no hard coded methods.
What irritates about this though is that in this example the group id is being passed to the getPhotos method rather than the groups method. I would much rather it looked like this.
@flickr.groups(:group_id => "99404851@N00").pools.getPhotos(:user_id => "12656878@N06")
So my question. Is there any way in Ruby that I can detect that the last method has been called so that I can trigger the call to Flickr?