Class: RestClient::Response

Inherits:
AbstractResponse show all
Defined in:
lib/rest-client-1.4.2/lib/restclient/response.rb

Overview

A Response from RestClient, you can access the response body, the code or the headers.

Constant Summary collapse

WARNING_MESSAGE =
'[warning] The Response is no more a String and the Response content is now accessed through Response.body, please update your code'

Instance Attribute Summary collapse

Attributes inherited from AbstractResponse

#args, #net_http_res

Instance Method Summary collapse

Methods inherited from AbstractResponse

beautify_headers, #code, #cookies, #follow_redirection, #headers, #inspect, #raw_headers, #return!

Constructor Details

#initialize(body, net_http_res, args) ⇒ Response

Returns a new instance of Response.



11
12
13
14
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 11

def initialize body, net_http_res, args
  super net_http_res, args
  @body = body || ""
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 16

def method_missing symbol, *args
  if body.respond_to? symbol
    warn WARNING_MESSAGE
    body.send symbol, *args
  else
    super
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 7

def body
  @body
end

Instance Method Details

#==(o) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 25

def == o
  if super
    true
  else
    equal_body = (body == o)
    if equal_body
      warn WARNING_MESSAGE
    end
    equal_body
  end
end

#sizeObject



41
42
43
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 41

def size
  body.size
end

#to_sObject



37
38
39
# File 'lib/rest-client-1.4.2/lib/restclient/response.rb', line 37

def to_s
  body.to_s
end