Class: HttpClient::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(closeable_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
# File 'lib/http_client/response.rb', line 6

def initialize(closeable_response)
  @status = closeable_response.status_line.status_code
  @headers = closeable_response.all_headers.inject({}) do |headers, header|
    headers[header.name] = header.value
    headers
  end
  @body = read_body(closeable_response)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#json_body(options = {}) ⇒ Object



19
20
21
# File 'lib/http_client/response.rb', line 19

def json_body(options = {})
  @json_body ||= JSON.parse(body, options)
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/http_client/response.rb', line 15

def success?
  status >= 200 && status <= 206
end