class HTTParty::Response
Constants
- CODES_TO_OBJ
Attributes
Public Class Methods
Source
# File lib/httparty/response.rb, line 9 def self._load(data) req, resp, parsed_resp, resp_body = Marshal.load(data) new(req, resp, -> { parsed_resp }, body: resp_body) end
Source
# File lib/httparty/response.rb, line 17 def initialize(request, response, parsed_block, options = {}) @request = request @response = response @body = options[:body] || response.body @parsed_block = parsed_block @headers = Headers.new(response.to_hash) if request.options[:logger] logger = ::HTTParty::Logger.build( request.options[:logger], request.options[:log_level], request.options[:log_format] ) logger.format(request, self) end throw_exception end
Source
# File lib/httparty/response.rb, line 5 def self.underscore(string) string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z])([A-Z])/, '\1_\2').downcase end
Public Instance Methods
Source
# File lib/httparty/response.rb, line 119 def _dump(_level) Marshal.dump([request, response, parsed_response, body]) end
Source
# File lib/httparty/response.rb, line 104 def display(port=$>) if !parsed_response.nil? && parsed_response.respond_to?(:display) parsed_response.display(port) elsif !response.nil? && !response.body.nil? && response.body.respond_to?(:display) response.body.display(port) else port.write(inspect) end end
Source
# File lib/httparty/response.rb, line 44 def http_version response.http_version end
Source
# File lib/httparty/response.rb, line 53 def inspect inspect_id = ::Kernel::format '%x', (object_id * 2) %(#<#{self.class}:0x#{inspect_id} parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>) end
Source
# File lib/httparty/response.rb, line 83 def nil? warn_about_nil_deprecation response.nil? || response.body.nil? || response.body.empty? end
Source
# File lib/httparty/response.rb, line 36 def parsed_response @parsed_response ||= @parsed_block.call end
Source
# File lib/httparty/response.rb, line 96 def pretty_print(pp) if !parsed_response.nil? && parsed_response.respond_to?(:pretty_print) parsed_response.pretty_print(pp) else super end end
Calls superclass method
Source
# File lib/httparty/response.rb, line 114 def respond_to_missing?(name, *args) return true if super parsed_response.respond_to?(name) || response.respond_to?(name) end
Calls superclass method
Source
# File lib/httparty/response.rb, line 88 def to_s if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s) response.body.to_s else inspect end end
Protected Instance Methods
Source
# File lib/httparty/response.rb, line 125 def method_missing(name, *args, &block) if parsed_response.respond_to?(name) parsed_response.send(name, *args, &block) elsif response.respond_to?(name) response.send(name, *args, &block) else super end end
Calls superclass method
Source
# File lib/httparty/response.rb, line 135 def throw_exception if @request.options[:raise_on] && @request.options[:raise_on].include?(code) ::Kernel.raise ::HTTParty::ResponseError.new(@response), "Code #{code} - #{body}" end end
Private Instance Methods
Source
# File lib/httparty/response.rb, line 143 def warn_about_nil_deprecation trace_line = caller.reject { |line| line.include?('httparty') }.first warning = "[DEPRECATION] HTTParty will no longer override `response#nil?`. " \ "This functionality will be removed in future versions. " \ "Please, add explicit check `response.body.nil? || response.body.empty?`. " \ "For more info refer to: https://github.com/jnunemaker/httparty/issues/568\n" \ "#{trace_line}" warn(warning) end