Class: Drip::Response
- Inherits:
-
Object
- Object
- Drip::Response
- Defined in:
- lib/drip/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(status, body) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(status, body) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 |
# File 'lib/drip/response.rb', line 10 def initialize(status, body) @status = status @body = body @links = parse_links @meta = @members = parse_members @body.freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
33 34 35 36 |
# File 'lib/drip/response.rb', line 33 def method_missing(method_name, *args, &block) return super unless member_map.keys.include?(method_name) members[member_map[method_name]] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/drip/response.rb', line 8 def body @body end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
8 9 10 |
# File 'lib/drip/response.rb', line 8 def links @links end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
8 9 10 |
# File 'lib/drip/response.rb', line 8 def members @members end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'lib/drip/response.rb', line 8 def @meta end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/drip/response.rb', line 8 def status @status end |
Instance Method Details
#==(other) ⇒ Object
20 21 22 23 |
# File 'lib/drip/response.rb', line 20 def ==(other) status == other.status && body == other.body end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
29 30 31 |
# File 'lib/drip/response.rb', line 29 def respond_to?(method_name, include_private = false) member_map.keys.include?(method_name) || super end |
#success? ⇒ Boolean
25 26 27 |
# File 'lib/drip/response.rb', line 25 def success? (200..299).cover?(status) end |