Class: Koala::HTTPService::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/koala/http_service/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, headers) ⇒ Response

Creates a new Response object, which standardizes the response received by Facebook for use within Koala.



7
8
9
10
11
# File 'lib/koala/http_service/response.rb', line 7

def initialize(status, body, headers)
  @status = status
  @body = body
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/koala/http_service/response.rb', line 4

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/koala/http_service/response.rb', line 4

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/koala/http_service/response.rb', line 4

def status
  @status
end

Instance Method Details

#dataObject



13
14
15
16
17
# File 'lib/koala/http_service/response.rb', line 13

def data
  # quirks_mode is needed because Facebook sometimes returns a raw true or false value --
  # in Ruby 2.4 we can drop that.
  @data ||= JSON.parse(body, quirks_mode: true) unless body.empty?
end