RFacebook Updates!
It’s been awhile since my last blog post, but things haven’t exactly been quiet on the Facebook API front. There are tons of apps going up on Facebook every day, and its been pretty exciting. Hopefully RFacebook has been helping you all get your ideas out there.
There’s now an official home page for RFacebook:
http://rfacebook.rubyforge.org/
This will hopefully have the latest docs and information about the Gem. There has also been some updates to the API syntax:
“Facepricot” Responses
Every RFacebook API call returns a Facepricot document. This is a wrapper for an Hpricot XML document. Note that ALL of the standard Hpricot methods still apply (you can even grab the original Hpricot document via xml.hpricot and use the Hpricot stuff directly). However, a Facepricot document gives you some neat methods that simplify your code. Now, you don’t have to type this:
sess.friends_get.search("//uid").map{|xmlnode| xmlnode.inner_html} // get an array of all friend UIDs
sess.friends_get.at("//uid").inner_html // get the first UID of friends
Instead, you can type this:
sess.friends_get.uid_list // get an array of all friend UIDs sess.friends_get.uid // get the first UID of friends
Much cleaner. Hopefully that helps out.
Easier Logging
Another highly requested feature: logging. Now you can do:
sess.logger = MyLogger.new
or, if you use Rails
sess.logger = RAILS_DEFAULT_LOGGER
FacebookSession uses the “debug” log method on that logger to provide some useful behind-the-scenes information.
Caching
Yep, caching is built in now. If you make a call like cached_friends_get, the FacebookSession will automatically cache the response.
August 21st, 2007 at 2:45 pm
Thanks for RFacebook. I’ve just started to play with it. I have a question on caching - how long does the cache last? Is there a way to expire it explicity or set a TTL?
Raghu Srinivasan
August 21st, 2007 at 2:52 pm
The cache lasts for as long as the fbsession is in memory. It is a very simple in-memory cache that persists with the FacebookSession object.
This actually varies depending on the way that you use the plugin. If you are making a Canvas app, you have a new session on every request. If you are making an iframe or external app, then that session is persisted in session[:rfacebook_session], and you can nil that out when it is not needed anymore.
In the future, I would like to make the caching smarter, but I think that a real caching solution should be implemented on an app-by-app basis. There really isn’t a magic bullet for such things.
August 22nd, 2007 at 6:10 pm
Thanks for the clarification. Yes, I agree caching and expiring caches can get pretty complicated fast … what you have is good enough for me now.