A Response from RestClient, you can access the response body, the code or the headers.
# File lib/restclient/response.rb, line 41 def self.create(body, net_http_res, request) result = self.new(body || '') result.response_set_vars(net_http_res, request) fix_encoding(result) result end
# File lib/restclient/response.rb, line 50 def self.fix_encoding(response) charset = RestClient::Utils.get_encoding_from_headers(response.headers) encoding = nil begin encoding = Encoding.find(charset) if charset rescue ArgumentError if RestClient.log RestClient.log << "No such encoding: #{charset.inspect}" end end return unless encoding response.force_encoding(encoding) response end
Return the HTTP response body.
Future versions of RestClient will deprecate treating response objects directly as strings, so it will be necessary to call `.body`.
@return [String]
# File lib/restclient/response.rb, line 16 def body # Benchmarking suggests that "#{self}" is fastest, and that caching the # body string in an instance variable doesn't make it enough faster to be # worth the extra memory storage. String.new(self) end
# File lib/restclient/response.rb, line 37 def inspect "<RestClient::Response #{code.inspect} #{body_truncated(10).inspect}>" end
Convert the HTTP response body to a pure String object.
@return [String]
# File lib/restclient/response.rb, line 26 def to_s body end
Convert the HTTP response body to a pure String object.
@return [String]
# File lib/restclient/response.rb, line 33 def to_str body end
# File lib/restclient/response.rb, line 71 def body_truncated(length) b = body if b.length > length b[0..length] + '...' else b end end