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(request, response, parsed_response) ⇒ Response

Returns a new instance of Response.



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

def initialize(request, response, parsed_response)
  @request = request
  @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)



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

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

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
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



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

def class
  Response
end

#codeObject



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

def code
  response.code.to_i
end

#inspectObject



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

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