Class: HTTParty::Response
- Inherits:
- BasicObject
- Defined in:
- lib/httparty/response.rb,
lib/httparty/response/headers.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Headers
Constant Summary collapse
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #class ⇒ Object
- #code ⇒ Object
-
#initialize(request, response, parsed_block, options = {}) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #parsed_response ⇒ Object
- #respond_to?(name, include_all = false) ⇒ Boolean
Constructor Details
#initialize(request, response, parsed_block, options = {}) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/httparty/response.rb', line 9 def initialize(request, response, parsed_block, ={}) @request = request @response = response @body = [:body] || response.body @parsed_block = parsed_block @headers = Headers.new(response.to_hash) if request.[:logger] logger = ::HTTParty::Logger.build(request.[:logger], request.[:log_level], request.[:log_format]) logger.format(request, self) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
60 61 62 63 64 65 66 67 68 |
# File 'lib/httparty/response.rb', line 60 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
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/httparty/response.rb', line 7 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/httparty/response.rb', line 7 def headers @headers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/httparty/response.rb', line 7 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/httparty/response.rb', line 7 def response @response end |
Class Method Details
.underscore(string) ⇒ Object
3 4 5 |
# 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 |
Instance Method Details
#class ⇒ Object
26 27 28 |
# File 'lib/httparty/response.rb', line 26 def class Response end |
#code ⇒ Object
30 31 32 |
# File 'lib/httparty/response.rb', line 30 def code response.code.to_i end |
#inspect ⇒ Object
34 35 36 37 |
# File 'lib/httparty/response.rb', line 34 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 |
#parsed_response ⇒ Object
22 23 24 |
# File 'lib/httparty/response.rb', line 22 def parsed_response @parsed_response ||= @parsed_block.call end |
#respond_to?(name, include_all = false) ⇒ Boolean
53 54 55 56 |
# File 'lib/httparty/response.rb', line 53 def respond_to?(name, include_all = false) return true if [:request, :response, :parsed_response, :body, :headers].include?(name) parsed_response.respond_to?(name, include_all) || response.respond_to?(name, include_all) end |