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
39:                 def self.beautify_headers(headers)
40:                         headers.inject({}) do |out, (key, value)|
41:                                 out[key.gsub(/-/, '_').to_sym] = value.first
42:                                 out
43:                         end
44:                 end
new(string, net_http_res) click to toggle source
    # File lib/restclient/response.rb, line 11
11:                 def initialize(string, net_http_res)
12:                         @net_http_res = net_http_res
13:                         super(string || "")
14:                 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
18:                 def code
19:                         @code ||= @net_http_res.code.to_i
20:                 end
cookies() click to toggle source

Hash of cookies extracted from response headers

    # File lib/restclient/response.rb, line 29
29:     def cookies
30:       @cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
31:         key, val = raw_c.split('=')
32:         unless %(expires domain path secure).member?(key)
33:           out[key] = val
34:         end
35:         out
36:       end
37:     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
24:                 def headers
25:                         @headers ||= self.class.beautify_headers(@net_http_res.to_hash)
26:                 end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.