Class: FacebookGraph::Client

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/facebook-graph/base/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTPHelper

#get

Constructor Details

#initialize(access_token = nil) ⇒ Client

Returns a new instance of Client.



4
5
6
# File 'lib/facebook-graph/base/client.rb', line 4

def initialize(access_token=nil)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



30
31
32
# File 'lib/facebook-graph/base/client.rb', line 30

def access_token
  @access_token
end

Instance Method Details

#current_user(options = {}) ⇒ Object



18
19
20
# File 'lib/facebook-graph/base/client.rb', line 18

def current_user(options={})
  get_node('me', options)
end

#get_node(element_id, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/facebook-graph/base/client.rb', line 8

def get_node(element_id, options={})
  config = FacebookGraph.configuration
  uri = "#{config[:base_uri]}/#{element_id}"
  uri += "#{querystring_separator(uri)}access_token=#{CGI.escape(@access_token)}" if @access_token
  uri += "#{querystring_separator(uri) + hash_to_querystring(options)}" unless options.nil? || options.empty?
  node = FacebookGraph::GraphNode.new(parse_json(uri))
  node.access_token = access_token
  node
end

#search(query, options = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/facebook-graph/base/client.rb', line 22

def search(query, options={})
  config = FacebookGraph.configuration
  uri = "#{config[:base_uri] + config[:search_uri]}?q=#{CGI.escape(query)}" 
  uri += "&access_token=#{CGI.escape(@access_token)}" if @access_token
  uri += "&#{hash_to_querystring(options)}" unless options.nil? || options.empty?
  FacebookGraph::GraphNode.from_array(parse_json(uri))
end