Class: Nuvemshop::Response
- Inherits:
-
Object
- Object
- Nuvemshop::Response
- Defined in:
- lib/nuvemshop/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#parsed_response ⇒ Object
readonly
Returns the value of attribute parsed_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(response, formatter = nil) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
- #respond_to_missing?(name, *args) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(response, formatter = nil) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 |
# File 'lib/nuvemshop/response.rb', line 5 def initialize(response, formatter = nil) @response = response @code = response.code @body = response.body @headers = response.headers @parsed_response = response.parsed_response @formatter = formatter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
55 56 57 58 59 60 61 62 63 |
# File 'lib/nuvemshop/response.rb', line 55 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.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def code @code end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def formatter @formatter end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def headers @headers end |
#parsed_response ⇒ Object (readonly)
Returns the value of attribute parsed_response.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def parsed_response @parsed_response end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/nuvemshop/response.rb', line 3 def response @response end |
Instance Method Details
#format ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/nuvemshop/response.rb', line 14 def format return unless formatter @parsed_response = if parsed_response.is_a?(Array) parsed_response.map { |pr| formatter.new(pr) } else formatter.new(parsed_response) end end |
#inspect ⇒ Object
32 33 34 35 |
# File 'lib/nuvemshop/response.rb', line 32 def inspect inspect_id = ::Kernel.format '%x', (object_id * 2) %(#<#{self.class}:0x#{inspect_id} code, @response=#{response.inspect}, @headers=#{headers.inspect}>) end |
#pretty_print(pp) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/nuvemshop/response.rb', line 37 def pretty_print(pp) format if !parsed_response.nil? && parsed_response.respond_to?(:pretty_print) parsed_response.pretty_print(pp) else super end end |
#respond_to_missing?(name, *args) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/nuvemshop/response.rb', line 47 def respond_to_missing?(name, *args) return true if super parsed_response.respond_to?(name) || response.respond_to?(name) end |
#to_s ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/nuvemshop/response.rb', line 24 def to_s if !response.nil? && !response.body.nil? && response.body.respond_to?(:to_s) response.body.to_s else inspect end end |