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 occasion 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
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Attributes included from AbstractResponse
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(tempfile, net_http_res, request, start_time = nil) ⇒ 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, #log, #log_response, #raw_headers, #response_set_vars, #return!, #to_i
Constructor Details
#initialize(tempfile, net_http_res, request, start_time = nil) ⇒ RawResponse
Returns a new instance of RawResponse.
26 27 28 29 30 31 32 33 |
# File 'lib/restclient/raw_response.rb', line 26 def initialize(tempfile, net_http_res, request, start_time=nil) @file = tempfile # reopen the tempfile so we can read it @file.open response_set_vars(net_http_res, request, start_time) end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
16 17 18 |
# File 'lib/restclient/raw_response.rb', line 16 def end_time @end_time end |
#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 |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
16 17 18 |
# File 'lib/restclient/raw_response.rb', line 16 def start_time @start_time end |
Instance Method Details
#body ⇒ Object
39 40 41 42 |
# File 'lib/restclient/raw_response.rb', line 39 def body @file.rewind @file.read end |
#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
44 45 46 |
# File 'lib/restclient/raw_response.rb', line 44 def size file.size end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/restclient/raw_response.rb', line 35 def to_s body end |