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.



7
8
9
10
11
12
13
# File 'lib/teamlab/Response.rb', line 7

def initialize(http_response)
  @code = http_response.code
  @success = @code < 400
  fail 'Error 404' if @code == 404
  @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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/teamlab/Response.rb', line 5

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/teamlab/Response.rb', line 5

def code
  @code
end

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'lib/teamlab/Response.rb', line 5

def error
  @error
end

#successObject (readonly)

Returns the value of attribute success.



5
6
7
# File 'lib/teamlab/Response.rb', line 5

def success
  @success
end