Class: Funky::GraphRootNode

Inherits:
Object
  • Object
show all
Defined in:
lib/funky/graph_root_node.rb

Direct Known Subclasses

Page, Post, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ GraphRootNode

Returns a new instance of GraphRootNode.



5
6
7
# File 'lib/funky/graph_root_node.rb', line 5

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/funky/graph_root_node.rb', line 3

def data
  @data
end

Class Method Details

.fetch_and_parse_data(ids) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/funky/graph_root_node.rb', line 16

def self.fetch_and_parse_data(ids)
  if ids.is_a?(Array) && ids.size > 1
    ids.each_slice(50).inject([]) do |total, slice|
      response = Connection::API.batch_request ids: slice, fields: fields
      total += parse response
    end
  else
    id = ids.is_a?(Array) ? ids.first : ids
    parse Connection::API.request(id: id, fields: fields)
  end
rescue ContentNotFound
  []
end

.instantiate_collection(items) ⇒ Object



45
46
47
# File 'lib/funky/graph_root_node.rb', line 45

def self.instantiate_collection(items)
  items.collect { |item| new item }
end

.parse(response) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/funky/graph_root_node.rb', line 30

def self.parse(response)
  if response.code == '200'
    body = JSON.parse response.body, symbolize_names: true
    if body.is_a? Array
      body.select{|item| item[:code] == 200}.collect do |item|
        JSON.parse(item[:body], symbolize_names: true)
      end.compact
    else
      [body]
    end
  else
    raise ContentNotFound, "Error #{response.code}: #{response.body}"
  end
end

Instance Method Details

#idString

Returns the object ID.

Returns:

  • (String)

    the object ID.



10
11
12
# File 'lib/funky/graph_root_node.rb', line 10

def id
  data[:id]
end