Class: Koala::Facebook::GraphCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/koala/graph_collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, api) ⇒ GraphCollection

Returns a new instance of GraphCollection.



20
21
22
23
24
25
# File 'lib/koala/graph_collection.rb', line 20

def initialize(response, api)
  super response["data"]
  @paging = response["paging"]
  @raw_response = response
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

This class is a light wrapper for collections returned from the Graph API.

It extends Array to allow direct access to the data colleciton which should allow it to drop in seamlessly.

It also allows access to paging information and the ability to get the next/previous page in the collection by calling next_page or previous_page.



13
14
15
# File 'lib/koala/graph_collection.rb', line 13

def api
  @api
end

#pagingObject (readonly)

This class is a light wrapper for collections returned from the Graph API.

It extends Array to allow direct access to the data colleciton which should allow it to drop in seamlessly.

It also allows access to paging information and the ability to get the next/previous page in the collection by calling next_page or previous_page.



13
14
15
# File 'lib/koala/graph_collection.rb', line 13

def paging
  @paging
end

#raw_responseObject (readonly)

This class is a light wrapper for collections returned from the Graph API.

It extends Array to allow direct access to the data colleciton which should allow it to drop in seamlessly.

It also allows access to paging information and the ability to get the next/previous page in the collection by calling next_page or previous_page.



13
14
15
# File 'lib/koala/graph_collection.rb', line 13

def raw_response
  @raw_response
end

Class Method Details

.evaluate(response, api) ⇒ Object



15
16
17
18
# File 'lib/koala/graph_collection.rb', line 15

def self.evaluate(response, api)
  # turn the response into a GraphCollection if it's pageable; if not, return the original response
  response.is_a?(Hash) && response["data"].is_a?(Array) ? self.new(response, api) : response
end

Instance Method Details

#parse_page_url(url) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/koala/graph_collection.rb', line 45

def parse_page_url(url)
  match = url.match(/.com\/(.*)\?(.*)/)
  base = match[1]
  args = match[2]
  params = CGI.parse(args)
  new_params = {}
  params.each_pair do |key,value|
    new_params[key] = value.join ","
  end
  [base,new_params]
end