Class: HttpClient::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(closeable_response) ⇒ Response

Returns a new instance of Response.



42
43
44
45
46
47
48
49
# File 'lib/http_client.rb', line 42

def initialize(closeable_response)
  @status = closeable_response.status_line.status_code
  @headers = closeable_response.get_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.



40
41
42
# File 'lib/http_client.rb', line 40

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



40
41
42
# File 'lib/http_client.rb', line 40

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



40
41
42
# File 'lib/http_client.rb', line 40

def status
  @status
end

Instance Method Details

#json_body(options = {}) ⇒ Object



55
56
57
# File 'lib/http_client.rb', line 55

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

#success?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/http_client.rb', line 51

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