Class: Nestful::Response
- Inherits:
-
Object
- Object
- Nestful::Response
- Defined in:
- lib/nestful/response/headers.rb,
lib/nestful/response.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Headers
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #as_json ⇒ Object
- #code ⇒ Object (also: #status)
- #decoded ⇒ Object
-
#initialize(response, location = nil) ⇒ Response
constructor
A new instance of Response.
- #respond_to?(name) ⇒ Boolean
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response, location = nil) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 |
# File 'lib/nestful/response.rb', line 5 def initialize(response, location = nil) @response = response @body = response.body @location = location @headers = Headers.new(response.to_hash) @format = Formats.for(headers.content_type) @parser ||= @format && @format.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
42 43 44 45 46 47 48 49 50 |
# File 'lib/nestful/response.rb', line 42 def method_missing(name, *args, &block) if decoded.respond_to?(name) decoded.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/nestful/response.rb', line 3 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/nestful/response.rb', line 3 def headers @headers end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
3 4 5 |
# File 'lib/nestful/response.rb', line 3 def location @location end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
3 4 5 |
# File 'lib/nestful/response.rb', line 3 def parser @parser end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/nestful/response.rb', line 3 def response @response end |
Instance Method Details
#as_json ⇒ Object
18 19 20 |
# File 'lib/nestful/response.rb', line 18 def as_json decoded end |
#code ⇒ Object Also known as: status
26 27 28 |
# File 'lib/nestful/response.rb', line 26 def code response.code.to_i end |
#decoded ⇒ Object
32 33 34 |
# File 'lib/nestful/response.rb', line 32 def decoded @decoded ||= parser ? parser.decode(body) : body end |
#respond_to?(name) ⇒ Boolean
36 37 38 |
# File 'lib/nestful/response.rb', line 36 def respond_to?(name) super || decoded.respond_to?(name) || response.respond_to?(name) end |
#to_json ⇒ Object
22 23 24 |
# File 'lib/nestful/response.rb', line 22 def to_json(*) as_json.to_json end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/nestful/response.rb', line 14 def to_s body end |