Class: FGraph::Collection

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

Overview

Collection objects for Graph response with array data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Collection

Initialize Facebook response object with ‘data’ array value.



31
32
33
34
35
36
37
38
# File 'lib/fgraph.rb', line 31

def initialize(response)
  return super unless response
  
  super(response['data'])
  paging = response['paging'] || {}
  self.next_url = paging['next']
  self.previous_url = paging['previous']
end

Instance Attribute Details

#next_optionsObject (readonly)

Returns the value of attribute next_options.



28
29
30
# File 'lib/fgraph.rb', line 28

def next_options
  @next_options
end

#next_urlObject

Returns the value of attribute next_url.



28
29
30
# File 'lib/fgraph.rb', line 28

def next_url
  @next_url
end

#previous_optionsObject (readonly)

Returns the value of attribute previous_options.



28
29
30
# File 'lib/fgraph.rb', line 28

def previous_options
  @previous_options
end

#previous_urlObject

Returns the value of attribute previous_url.



28
29
30
# File 'lib/fgraph.rb', line 28

def previous_url
  @previous_url
end

Instance Method Details

#first?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fgraph.rb', line 50

def first?
  @previous_url.blank? and not @next_url.blank?
end

#next?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fgraph.rb', line 54

def next?
  not @next_url.blank?
end

#previous?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fgraph.rb', line 58

def previous?
  not @previous_url.blank?
end

#url_options(url) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fgraph.rb', line 62

def url_options(url)
  return unless url
  
  # Note: FB pass access token with '|' character, which cause URI::InvalidURIError
  uri = URI.parse(url.gsub('|', '%7C'))
  
  options = {}
  uri.query.split('&').each do |param_set|
     param_set = param_set.split('=')
     options[param_set[0]] = CGI.unescape(param_set[1])
  end
  options
end