class Funky::GraphRootNode
Attributes
data[R]
Public Class Methods
new(data)
click to toggle source
# File lib/funky/graph_root_node.rb, line 5 def initialize(data) @data = data end
Private Class Methods
fetch_and_parse_data(ids)
click to toggle source
# 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)
click to toggle source
# File lib/funky/graph_root_node.rb, line 45 def self.instantiate_collection(items) items.collect { |item| new item } end
parse(response)
click to toggle source
# 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
Public Instance Methods
id()
click to toggle source
@return [String] the object ID.
# File lib/funky/graph_root_node.rb, line 10 def id data[:id] end