Class: FacebookGraph::GraphNode

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTTPHelper

#get

Constructor Details

#initialize(properties = {}) ⇒ GraphNode

Returns a new instance of GraphNode.



6
7
8
# File 'lib/facebook-graph/base/graph_node.rb', line 6

def initialize(properties={})
  @properties = symbolize_keys(properties)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mname, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/facebook-graph/base/graph_node.rb', line 10

def method_missing(mname, *args)
  prop = @properties[mname]
  return prop unless prop.nil?
  config = FacebookGraph.configuration
  prop = "#{config[:base_uri]}/#{node_id}/#{mname}"
  options = args[0] || {}
  if options.kind_of?(Hash)
    options[:access_token] = access_token
    prop += "#{querystring_separator(prop) + hash_to_querystring(options)}"       
  end
  mname == :picture ? prop : FacebookGraph::GraphNode.from_array(parse_json(prop))
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#propertiesObject (readonly)

Returns the value of attribute properties.



40
41
42
# File 'lib/facebook-graph/base/graph_node.rb', line 40

def properties
  @properties
end

Class Method Details

.from_array(array) ⇒ Object



36
37
38
# File 'lib/facebook-graph/base/graph_node.rb', line 36

def self.from_array(array)
  array['data'].map{|el| self.new(el)} if array['data']
end

Instance Method Details

#node_idObject



28
29
30
# File 'lib/facebook-graph/base/graph_node.rb', line 28

def node_id
  @properties[:id]
end

#respond_to?(mname) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/facebook-graph/base/graph_node.rb', line 23

def respond_to? mname
   = connections_defined? && @properties[:metadata]['connections'][mname.to_s]
  !! || !!@properties[mname] || super(mname)   
end