1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00
rest-client--rest-client/lib/restclient/raw_response.rb

35 lines
832 B
Ruby
Raw Normal View History

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.
class RawResponse
include AbstractResponse
2009-03-20 22:19:21 -04:00
2009-12-29 12:27:39 -05:00
attr_reader :file
def initialize tempfile, net_http_res, args
@net_http_res = net_http_res
@args = args
2009-12-29 12:27:39 -05:00
@file = tempfile
end
2009-12-29 12:27:39 -05:00
def to_s
@file.open
@file.read
end
def size
File.size file
end
2009-12-29 12:27:39 -05:00
end
end