Major Facebooker Updates

About a month ago I moved Facebooker development to GitHub. What a great decision that was. I’ve applied a flurry of patches to fix some outstanding issues and add some additional support to the platform. If you haven’t done any Facebook development, Facebooker is a Ruby library for creating Facebook Applications. It is the library that I used in Developing Facebook Platform Applications with Rails.

In the last few days, we’ve added a lot of new features. The biggest of which is support for Bebo and other social platforms. David Clements forked the repository and made massive internal changes to support multiple backends. With his change I was able to get a client’s application running on Bebo in just a few minutes. Great work David! Chris Redinger submitted several changes including support for forgery protection in Facebook forms. Brian Lee added support for friend lists as well.

On top of those changes, I added support for the new action templates to both Facebooker and the Publisher. The Facebooker Publisher is an ActionMailer like interface to Facebook messaging. Check out the documentation (http://facebooker.rubyforge.org/ and http://facebooker.rubyforge.org/classes/Facebooker/Rails/Publisher.html in particular)

If you’ve already created a publisher, you will need to re-run the script/generate command to create a new migration. By default, Facebooker will now keep track of your template ids. To send a message using the new API, you’ll need to create two methods. The first returns the templates. For example:

class MyPublisher < Facebooker::Rails::Publisher
  def publish_action_template
    one_line_story_template "{*actor*} did stuff with {*friend*}"
    one_line_story_template "{*actor*} did stuff"
    short_story_template "{*actor*} has a title {*friend*}", render(:partial=>"short_body")
    short_story_template "{*actor*} has a title", render(:partial=>"short_body")
    full_story_template "{*actor*} has a title {*friend*}", render(:partial=>"full_body")
  end

The name of the method needs to end in _template.

To register this template, you can call

MyPublisher.register_publish_action

or, to register all templates in a publisher, you can call

MyPublisher.register_all_templates

Facebooker will store the template id and the template name in the facebook_templates table.

To send a message from a stored template, you’ll need to create another method that registers the data:

 def publish_action(f)
   from f
   data :friend=>"Mike"
 end

Then, you can call

MyPublisher.deliver_publish_action

Facebooker will look up the template id automatically.

This will all be covered in a forthcoming Beta of my book.