2009-03-16 18:28:20 -04:00
|
|
|
module RestClient
|
2009-12-29 12:27:39 -05:00
|
|
|
# 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.
|
2010-03-29 13:38:23 -04:00
|
|
|
class RawResponse
|
|
|
|
|
|
|
|
include AbstractResponse
|
2009-03-20 22:19:21 -04:00
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
attr_reader :file
|
2009-03-16 18:28:20 -04:00
|
|
|
|
2010-02-10 15:31:59 -05:00
|
|
|
def initialize tempfile, net_http_res, args
|
2010-03-29 13:38:23 -04:00
|
|
|
@net_http_res = net_http_res
|
|
|
|
@args = args
|
2009-12-29 12:27:39 -05:00
|
|
|
@file = tempfile
|
|
|
|
end
|
2009-03-16 18:28:20 -04:00
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
def to_s
|
|
|
|
@file.open
|
|
|
|
@file.read
|
|
|
|
end
|
2009-03-16 18:28:20 -04:00
|
|
|
|
2010-01-26 13:41:53 -05:00
|
|
|
def size
|
|
|
|
File.size file
|
|
|
|
end
|
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
2009-03-16 18:28:20 -04:00
|
|
|
end
|