Class: Teamlab::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/teamlab/response.rb', line 5

def initialize(http_response)
  if http_response.is_a?(String) && http_response.code < 400
    @body = { response: http_response.to_s }
    @success = true
    @code = 201
  else
    @code = http_response.code
    @success = @code < 400
    fail "Error #{@code}" if @code >= 400
    fail TimeoutError, 'Portal is warming up' if http_response.parsed_response.include?('portal is being warmed')
    @body = http_response.respond_to?(:parsed_response) && http_response.parsed_response.key?('result') ? http_response.parsed_response['result'] : http_response.to_hash
    @error = @body['error']['message'] if @body.key?('error') && @body['error'].key?('message')
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/teamlab/response.rb', line 3

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/teamlab/response.rb', line 3

def code
  @code
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/teamlab/response.rb', line 3

def error
  @error
end

#successObject (readonly)

Returns the value of attribute success.



3
4
5
# File 'lib/teamlab/response.rb', line 3

def success
  @success
end