Class: GraphResponse

Inherits:
SDKComponent show all
Defined in:
lib/graph_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SDKComponent

#ensure_slash, #query_decode

Constructor Details

#initialize(response, request) ⇒ GraphResponse

Returns a new instance of GraphResponse.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graph_response.rb', line 14

def initialize response, request
	@request = request
	@response = response
	if !response.is_a?(Hash)
		response = {"data" => response}
	end
	
	if response["data"].nil?
		@data = response
	else
		@data = response["data"]
	end
	if !response["error"].nil? 
		@error = SDKException.new response["error"]["message"],response["error"]["code"],response["error"]["type"],request.effective_url
	end
	@paging = response["paging"]
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#errorObject

Returns the value of attribute error.



11
12
13
# File 'lib/graph_response.rb', line 11

def error
  @error
end

#pagingObject

Returns the value of attribute paging.



12
13
14
# File 'lib/graph_response.rb', line 12

def paging
  @paging
end

#requestObject

Returns the value of attribute request.



8
9
10
# File 'lib/graph_response.rb', line 8

def request
  @request
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/graph_response.rb', line 9

def response
  @response
end

Instance Method Details

#iterate(url) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/graph_response.rb', line 40

def iterate url
	if url
		url = URI(URI.encode url)
		params = Rack::Utils.parse_nested_query(url.query)
		GraphRequest.new(url.path, params).get_response
	end
end

#nextObject



32
33
34
# File 'lib/graph_response.rb', line 32

def next
	self.iterate @paging['next']
end

#previousObject



36
37
38
# File 'lib/graph_response.rb', line 36

def previous
	self.iterate @paging['previous']
end