class HTTParty::Response
Constants
- CODES_TO_OBJ
- RESPOND_TO_METHODS
Attributes
body[R]
headers[R]
request[R]
response[R]
Public Class Methods
new(request, response, parsed_block, options = {})
click to toggle source
# File lib/httparty/response.rb, line 9 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
underscore(string)
click to toggle source
# File lib/httparty/response.rb, line 3 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
class()
click to toggle source
# File lib/httparty/response.rb, line 28 def class Response end
code()
click to toggle source
# File lib/httparty/response.rb, line 38 def code response.code.to_i end
inspect()
click to toggle source
# File lib/httparty/response.rb, line 47 def inspect inspect_id = ::Kernel::format "%x", (object_id * 2) %Q(#<#{self.class}:0x#{inspect_id} parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>) end
is_a?(klass)
click to toggle source
# File lib/httparty/response.rb, line 32 def is_a?(klass) self.class == klass || self.class < klass end
Also aliased as: kind_of?
parsed_response()
click to toggle source
# File lib/httparty/response.rb, line 24 def parsed_response @parsed_response ||= @parsed_block.call end
respond_to?(name, include_all = false)
click to toggle source
# File lib/httparty/response.rb, line 72 def respond_to?(name, include_all = false) return true if RESPOND_TO_METHODS.include?(name) parsed_response.respond_to?(name, include_all) || response.respond_to?(name, include_all) end
tap() { |self| ... }
click to toggle source
# File lib/httparty/response.rb, line 42 def tap yield self self end
Protected Instance Methods
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/httparty/response.rb, line 79 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
throw_exception()
click to toggle source
# File lib/httparty/response.rb, line 89 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