# Rest-graph 1.1.0 - super simple facebook open graph api client

**URL:** <https://www.ruby-forum.com/t/rest-graph-1-1-0-super-simple-facebook-open-graph-api-client/188485>\
**Category:** Ruby\
**Created:** [May 12, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/rest-graph-1-1-0-super-simple-facebook-open-graph-api-client/188485 "2010-05-12T18:45:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lin\_Jen-Shin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7993a0/32.png) [@Lin\_Jen-Shin](https://www.ruby-forum.com/u/Lin_Jen-Shin)\
**Post date:** [May 12, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/rest-graph-1-1-0-super-simple-facebook-open-graph-api-client/188485/1 "2010-05-12T18:45:12Z")

</div>

= rest-graph 1.1.0  
by Cardinal Blue ( [http://cardinalblue.com](http://cardinalblue.com) )

== LINKS:

- [GitHub - cardinalblue/rest-graph: A lightweight Facebook Graph API client](http://github.com/cardinalblue/rest-graph)
- [rest-graph | RubyGems.org | your community gem host](http://rubygems.org/gems/rest-graph)
- [http://rdoc.info/projects/cardinalblue/rest-graph](http://rdoc.info/projects/cardinalblue/rest-graph)

== DESCRIPTION:

super simple facebook open graph api client

== FEATURES:

- simple graph api call
- simple fql call
- utility to extract access\_token and check sig in cookies

== CHANGES in 1.1.0

- Main repository was moved to [GitHub - cardinalblue/rest-graph: A lightweight Facebook Graph API client](http://github.com/cardinalblue/rest-graph)  
Sorry for the inconvenience. I’ll keep pushing to both repositories  
until  
I am too lazy to do that.

- Better way to deal with default attributes, use class methods.

- If you want to auto load config, do require ‘rest-graph/auto\_load’  
if it’s rails, it would load the config from config/rest-  
graph.y(a)ml.  
if you’re using rails plugin, we do require ‘rest-graph/auto\_load’  
for you.

- Config could be load manually as well. require ‘rest-graph/  
load\_config’ and  
RestGraph::LoadConfig.load\_config!(‘path/to/rest-graph.yaml’, ‘env’)

== SYNOPSIS:

require ‘rest-graph’

# every option is optional!!

rg = RestGraph.new(:access\_token =\> ‘…’,  
:graph\_server =\> ‘[https://graph.facebook.com/](https://graph.facebook.com/)’,  
:fql\_server =\> ‘[https://api.facebook.com/](https://api.facebook.com/)’,  
:accept =\> ‘text/javascript’,  
:lang =\> ‘en-us’, # this affect search  
:auto\_decode =\> true, # decode by json  
:app\_id =\> ‘123’,  
:secret =\> ‘1829’)

rg.get(‘me’) # GET [https://graph.facebook.com/me?access\_token=](https://graph.facebook.com/me?access_token=)…  
rg.get(‘4/likes’) # GET  
[https://graph.facebook.com/4/likes?access\_token=](https://graph.facebook.com/4/likes?access_token=)…

# GET [https://graph.facebook.com/search?q=taiwan&access\_token=](https://graph.facebook.com/search?q=taiwan&access_token=)…

rg.get(‘search’, :q =\> ‘taiwan’)

# GET [https://graph.facebook.com/me?metadata=1&access\_token=](https://graph.facebook.com/me?metadata=1&access_token=)…

rg.get(‘me’, :metadata =\> ‘1’)

# POST

[https://graph.facebook.com/feed/me?message=bread!&access\_token=](https://graph.facebook.com/feed/me?message=bread%21&access_token=)…  
rg.post(‘feed/me’, :message =\> ‘bread!’)

# for fully blown cookies hash

rg = RestGraph.new(:app\_id =\> ‘123’, :secret =\> ‘1829’)  
rg.parse\_cookies!(cookies) # auto save access\_token if sig checked  
rg.data[‘uid’] # =\> facebook uid

# fql query, same as:

# GET [https://api.facebook.com/method/fql.query?query=](https://api.facebook.com/method/fql.query?query=)

# SELECT+name+FROM+page+WHERE+page\_id%3D%22123%22&

# format=json&access\_token=…

rg.fql(‘SELECT name FROM page WHERE page\_id=“123”’)

# default setting:

class RestGraph  
def self.default\_app\_id  
‘456’  
end

def self.default\_secret  
‘category theory’  
end  
end

# auto load config

require ‘rest-graph’  
require ‘rest-graph/auto\_load’ # under Rails, load config/rest-  
graph.yaml  
RestGraph.new # all default options would honor  
config  
RestGraph.new(:app\_id =\> ‘123’) # default could be override as well

# manually load config

require ‘rest-graph/load\_config’  
RestGraph::LoadConfig.load\_config!(‘path/to/rest-graph.yaml’, ‘env’)

# see test/config/rest-graph.yaml for an example for config

== REQUIREMENTS:

- tested with MRI 1.8.7 and 1.9.1
- gem install rest-client
- gem install json (optional)
- gem install json\_pure (optional)
- gem install rack (optional, to parse access\_token in  
HTTP\_COOKIE)

== INSTALL:

> gem install rest-graph

# or if you want rails plugin and bleeding edge

> script/plugin install git://github.com/cardinalblue/rest-graph.git

== LICENSE:

Apache License 2.0

Copyright (c) 2010, Cardinal Blue

Licensed under the Apache License, Version 2.0 (the “License”);  
you may not use this file except in compliance with the License.  
You may obtain a copy of the License at

```
 http://www.apache.org/licenses/LICENSE-2.0

```

Unless required by applicable law or agreed to in writing, software  
distributed under the License is distributed on an “AS IS” BASIS,  
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
implied.  
See the License for the specific language governing permissions and  
limitations under the License.
