Class: RestClient::RawResponse

Inherits:
AbstractResponse show all
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

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(tempfile, net_http_res, args) ⇒ RawResponse

Returns a new instance of RawResponse.



16
17
18
19
# File 'lib/restclient/raw_response.rb', line 16

def initialize tempfile, net_http_res, args
  super net_http_res, args
  @file = tempfile
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



14
15
16
# File 'lib/restclient/raw_response.rb', line 14

def file
  @file
end

Instance Method Details

#sizeObject



26
27
28
# File 'lib/restclient/raw_response.rb', line 26

def size
  File.size file
end

#to_sObject



21
22
23
24
# File 'lib/restclient/raw_response.rb', line 21

def to_s
  @file.open
  @file.read
end