Introducing RestGraph
We are proud to announce RestGraph - a lightweight open-source Facebook Graph API client for Ruby. It’s modular and compact, and provides only the essential functionality.
Moreover, it’s designed to be transparent to Facebook Graph API, which has the benefit of simplicity. Unlike other client libraries that might try to “fix” Facebook’s API, RestGraph lets you interact directly with the data that comes from the Graph API, so once you have the basic setup for RestGraph, you need only to consult the Facebook Graph API documentation.

Fine! So let’s take a look at some sample code:
require ‘rest-graph’
rg = RestGraph.new(:access_token => ‘myaccesstokenfromfb’)
rg.get(‘me’)
rg.get(‘me/likes’)
rg.get(‘search’, :q => ‘taiwan’)
If you like how this mirrors the Graph API exactly, we have more good news for you: RestGraph is also very easy to track and debug as it lets you to save many helpful log messages.
rg = RestGraph.new(:log_method => method(:puts))
#<struct RestGraph auto_decode=true, strict=false, timeout=10, graph_server=”https://graph.facebook.com/”, old_server=”https://api.facebook.com/”, accept=”text/javascript”, lang=”en-us”, app_id=”342525571645”, secret=”***”, data={}, cache=nil, log_method=#<Method: Object(Kernel)#puts>, log_handler=nil, error_handler=#<Proc:0x000001010bf570@/Users/***/vendor/plugins/rest-graph/lib/rest-graph/core.rb:107 (lambda)»
rg.get(4)
DEBUG: RestGraph: spent 0.982087 Requested https://graph.facebook.com/4 {“id”=>”4”, “name”=>”Mark Zuckerberg”, “first_name”=>”Mark”, “last_name”=>”Zuckerberg”, “link”=>”http://www.facebook.com/zuck”, “username”=>”zuck”, “gender”=>”male”, “locale”=>”en_US”}
The next advantage over the other libraries is that you can save your results directly in your cache (e.g. Memcached for Rails) without much effort. Just type:
rg = RestGraph.new(:cache => Rails.cache)
You can also set the different timeout values for each piece of data you store in your cache!
rg.get(‘4’, {:metadata => ‘1’}, :expires_in => 10)
rg.get(‘83828423’, {}, :expires_in => 69)
But that’s not all — RestGraph isn’t actually limited to Facebook Graph API only. You can use it to retrieve data from any other website’s public JSON API!

Just take a look at this example:
rg.graph_server = ‘http://api.twitter.com/’
“http://api.twitter.com/”
rg.get(‘1/statuses/public_timeline.json’)
DEBUG: RestGraph: spent 0.628466 Requested http://api.twitter.com/1/statuses/public_timeline.json
=> [{“coordinates”=>nil, “favorited”=>false, “created_at”=>”Wed Apr 06 11:46:13 +0000 2011”, “truncated”=>false, “id_str”=>”55597173609472000”, “in_reply_to_user_id_str”=>nil, “contributors”=>nil, “text”=>”Cant nobody take my pride…
We just used RestGraph to pull Twitter posts! Yay!
This is only a short introduction of all the RestGraph’s features. If you want to learn more, please feel free to visit its Github page.
____
Godfat & Mariusz