Parent

RestClient::Response

The response from RestClient looks like a string, but is actually one of these. 99% of the time you’re making a rest call all you care about is the body, but on the occassion you want to fetch the headers you can:

RestClient.get('http://example.com').headers[:content_type]

Attributes

net_http_res[R]

Public Class Methods

beautify_headers(headers) click to toggle source
# File lib/restclient/response.rb, line 39
def self.beautify_headers(headers)
        headers.inject({}) do |out, (key, value)|
                out[key.gsub(/-/, '_').to_sym] = value.first
                out
        end
end
new(string, net_http_res) click to toggle source
# File lib/restclient/response.rb, line 11
def initialize(string, net_http_res)
        @net_http_res = net_http_res
        super(string || "")
end

Public Instance Methods

code() click to toggle source

HTTP status code, always 200 since RestClient throws exceptions for other codes.

# File lib/restclient/response.rb, line 18
def code
        @code ||= @net_http_res.code.to_i
end
cookies() click to toggle source

Hash of cookies extracted from response headers

# File lib/restclient/response.rb, line 29
def cookies
  @cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
    key, val = raw_c.split('=')
    unless %(expires domain path secure).member?(key)
      out[key] = val
    end
    out
  end
end
headers() click to toggle source

A hash of the headers, beautified with symbols and underscores. e.g. “Content-type” will become :content_type.

# File lib/restclient/response.rb, line 24
def headers
        @headers ||= self.class.beautify_headers(@net_http_res.to_hash)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.