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.
8 9 10 11 12 13 14 15 16 |
# File 'lib/drip/response.rb', line 8 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
31 32 33 34 |
# File 'lib/drip/response.rb', line 31 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.
6 7 8 |
# File 'lib/drip/response.rb', line 6 def body @body end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
6 7 8 |
# File 'lib/drip/response.rb', line 6 def links @links end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
6 7 8 |
# File 'lib/drip/response.rb', line 6 def members @members end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
6 7 8 |
# File 'lib/drip/response.rb', line 6 def @meta end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/drip/response.rb', line 6 def status @status end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 |
# File 'lib/drip/response.rb', line 18 def ==(other) status == other.status && body == other.body end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
27 28 29 |
# File 'lib/drip/response.rb', line 27 def respond_to?(method_name, include_private = false) member_map.keys.include?(method_name) || super end |
#success? ⇒ Boolean
23 24 25 |
# File 'lib/drip/response.rb', line 23 def success? (200..299).cover?(status) end |