Class: HTTP::Response

Inherits:
Object show all
Defined in:
lib/http_client/mri/response.rb,
lib/http_client/jruby/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native_response, cookies) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
# File 'lib/http_client/mri/response.rb', line 5

def initialize(native_response)
  @native_response = native_response
  @status_code = native_response.code.to_i
  @body = native_response.body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



15
16
17
18
19
20
# File 'lib/http_client/mri/response.rb', line 15

def cookies
  native_cookies = CGI::Cookie.parse(@native_response['set-cookie'])
  cookies = {}
  native_cookies.each {|name, cookie| cookies[name] = cookie.value.first}
  cookies
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/http_client/mri/response.rb', line 11

def headers
  @native_response
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



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

def status_code
  @status_code
end