Class: RestClient::RawResponse
- Inherits:
-
Object
- Object
- RestClient::RawResponse
- Includes:
- AbstractResponse
- Defined in:
- lib/restclient/raw_response.rb
Overview
The response from RestClient on a raw request 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]
In addition, if you do not use the response as a string, you can access a Tempfile object at res.file, which contains the path to the raw downloaded request body.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Attributes included from AbstractResponse
Instance Method Summary collapse
-
#initialize(tempfile, net_http_res, request) ⇒ RawResponse
constructor
A new instance of RawResponse.
- #inspect ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Methods included from AbstractResponse
beautify_headers, #code, #cookie_jar, #cookies, #description, #follow_get_redirection, #follow_redirection, #headers, #history, #raw_headers, #response_set_vars, #return!, #to_i
Constructor Details
#initialize(tempfile, net_http_res, request) ⇒ RawResponse
Returns a new instance of RawResponse.
22 23 24 25 26 |
# File 'lib/restclient/raw_response.rb', line 22 def initialize(tempfile, net_http_res, request) @net_http_res = net_http_res @file = tempfile @request = request end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
16 17 18 |
# File 'lib/restclient/raw_response.rb', line 16 def file @file end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
16 17 18 |
# File 'lib/restclient/raw_response.rb', line 16 def request @request end |
Instance Method Details
#inspect ⇒ Object
18 19 20 |
# File 'lib/restclient/raw_response.rb', line 18 def inspect "<RestClient::RawResponse @code=#{code.inspect}, @file=#{file.inspect}, @request=#{request.inspect}>" end |
#size ⇒ Object
33 34 35 |
# File 'lib/restclient/raw_response.rb', line 33 def size File.size file end |
#to_s ⇒ Object
28 29 30 31 |
# File 'lib/restclient/raw_response.rb', line 28 def to_s @file.open @file.read end |