Created
March 26, 2011 21:38
-
-
Save mwmitchell/888663 to your computer and use it in GitHub Desktop.
A Minimalist Facebook FQL Client in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "open-uri" | |
require "rack/utils" | |
require "json" | |
class Fql | |
class << self | |
attr_accessor :base_url | |
end | |
self.base_url = "https://api.facebook.com/method/" | |
attr :access_token | |
def initialize access_token | |
@access_token = access_token | |
end | |
def query q | |
request("fql.query", {:query => q, :access_token => access_token, :format => "json"}) | |
end | |
def request method, params | |
response = open "#{self.class.base_url}#{method}?#{build_query(params)}" | |
JSON.parse response.read | |
end | |
def build_query params | |
@helper ||= Object.new.extend(Rack::Utils) | |
@helper.send :build_query, params | |
end | |
end | |
# fql = Fql.new("token-here") | |
# response = fql.query( | |
# "SELECT uid, name, pic_square | |
# FROM user WHERE uid = me() | |
# OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) limit 2,1") | |
# puts response.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment