Class: HTTParty::Response

Inherits:
BasicObject
Defined in:
lib/httparty/response.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Headers

Constant Summary collapse

CODES_TO_OBJ =
Net::HTTPResponse::CODE_CLASS_TO_OBJ.merge Net::HTTPResponse::CODE_TO_OBJ

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, parsed_response) ⇒ Response

Returns a new instance of Response.



38
39
40
41
42
43
# File 'lib/httparty/response.rb', line 38

def initialize(response, parsed_response)
  @response = response
  @body = response.body
  @parsed_response = parsed_response
  @headers = Headers.new(response.to_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



69
70
71
72
73
74
75
76
77
# File 'lib/httparty/response.rb', line 69

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



36
37
38
# File 'lib/httparty/response.rb', line 36

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



36
37
38
# File 'lib/httparty/response.rb', line 36

def headers
  @headers
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



36
37
38
# File 'lib/httparty/response.rb', line 36

def parsed_response
  @parsed_response
end

#responseObject (readonly)

Returns the value of attribute response.



36
37
38
# File 'lib/httparty/response.rb', line 36

def response
  @response
end

Class Method Details

.underscore(string) ⇒ Object



32
33
34
# File 'lib/httparty/response.rb', line 32

def self.underscore(string)
  string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
end

Instance Method Details

#classObject



45
46
47
# File 'lib/httparty/response.rb', line 45

def class
  Response
end

#codeObject



49
50
51
# File 'lib/httparty/response.rb', line 49

def code
  response.code.to_i
end

#inspectObject



53
54
55
56
# File 'lib/httparty/response.rb', line 53

def inspect
  inspect_id = "%x" % (object_id * 2)
  %(#<#{self.class}:0x#{inspect_id} @parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
end