Class: ChimeraHttpClient::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
# File 'lib/chimera_http_client/response.rb', line 5

def initialize(response)
  @body     = response.body
  @code     = response.code
  @time     = response.total_time
  @response = response # contains the request
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/chimera_http_client/response.rb', line 18

def error?
  false
end

#parsed_bodyObject



12
13
14
15
16
# File 'lib/chimera_http_client/response.rb', line 12

def parsed_body
  JSON.parse(body)
rescue JSON::ParserError => e
  raise ChimeraHttpClient::JsonParserError, "Could not parse body as JSON: #{body}, error: #{e.message}"
end