lib/restclient/response.rb in rest-client-1.3.1 vs lib/restclient/response.rb in rest-client-1.4.0.a
- old
+ new
@@ -1,20 +1,44 @@
-require File.dirname(__FILE__) + '/mixin/response'
-
module RestClient
- # 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:
+
+ # A Response from RestClient, you can access the response body, the code or the headers.
#
- # RestClient.get('http://example.com').headers[:content_type]
- #
- class Response < String
+ class Response < AbstractResponse
- include RestClient::Mixin::Response
+ attr_reader :body
- def initialize(string, net_http_res)
- @net_http_res = net_http_res
- super(string || "")
+ def initialize body, net_http_res, args
+ super net_http_res, args
+ @body = body || ""
+ end
+
+ def method_missing symbol, *args
+ if body.respond_to? symbol
+ warn "[warning] The Response is no more a String, please update your code"
+ body.send symbol, *args
+ else
+ super
+ end
+ end
+
+ def == o
+ if super
+ true
+ else
+ equal_body = (body == o)
+ if equal_body
+ warn "[warning] The Response is no more a String, please update your code"
+ end
+ equal_body
+ end
+ end
+
+ def to_s
+ body.to_s
+ end
+
+ def size
+ body.size
end
end
end