Class: FbGraph2::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/fb_graph2/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, attributes = {}) ⇒ Node

Returns a new instance of Node.



11
12
13
14
15
16
# File 'lib/fb_graph2/node.rb', line 11

def initialize(id, attributes = {})
  self.id = id
  self.raw_attributes = attributes
  assign attributes if respond_to? :assign
  authenticate attributes[:access_token] if attributes.include? :access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



3
4
5
# File 'lib/fb_graph2/node.rb', line 3

def access_token
  @access_token
end

#idObject Also known as: identifier

Returns the value of attribute id.



3
4
5
# File 'lib/fb_graph2/node.rb', line 3

def id
  @id
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



3
4
5
# File 'lib/fb_graph2/node.rb', line 3

def raw_attributes
  @raw_attributes
end

Class Method Details

.inherited(klass) ⇒ Object



6
7
8
9
# File 'lib/fb_graph2/node.rb', line 6

def self.inherited(klass)
  klass.send :include, AttributeAssigner
  FbGraph2.object_classes << klass
end

Instance Method Details

#authenticate(access_token) ⇒ Object



18
19
20
21
# File 'lib/fb_graph2/node.rb', line 18

def authenticate(access_token)
  self.access_token = access_token
  self
end

#destroy(params = {}, options = {}) ⇒ Object



49
50
51
# File 'lib/fb_graph2/node.rb', line 49

def destroy(params = {}, options = {})
  delete params, options
end

#edge(edge, params = {}, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/fb_graph2/node.rb', line 28

def edge(edge, params = {}, options = {})
  Edge.new(
    self,
    edge,
    params,
    options.merge(
      collection: edge_for(edge, params, options)
    )
  )
end

#edgesObject



39
40
41
42
43
# File 'lib/fb_graph2/node.rb', line 39

def edges
  @edges ||= self.class.included_modules.select do |_module_|
    _module_.name =~ /FbGraph2::Edge/
  end.collect(&:instance_methods).flatten.sort
end

#fetch(params = {}, options = {}) ⇒ Object



23
24
25
26
# File 'lib/fb_graph2/node.rb', line 23

def fetch(params = {}, options = {})
  attributes = get params, options
  self.class.new(attributes[:id], attributes).authenticate access_token
end

#update(params = {}, options = {}) ⇒ Object



45
46
47
# File 'lib/fb_graph2/node.rb', line 45

def update(params = {}, options = {})
  post params, options
end