Class: Vacuum::Response
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Vacuum::Response
- Extended by:
- Forwardable
- Defined in:
- lib/vacuum/response.rb
Overview
A wrapper around the API response
Class Attribute Summary collapse
-
.parser ⇒ nil, .parse
An optional custom parser.
Instance Attribute Summary collapse
-
#parser ⇒ nil, .parse
An optional custom parser.
Instance Method Summary collapse
-
#dig(*key) ⇒ Object
Delegates to the Hash returned by #to_h to extract a nested value specified by the sequence of keys.
-
#parse ⇒ Object
Parses the response body.
-
#to_h ⇒ Hash
Casts body to Hash.
Class Attribute Details
.parser ⇒ nil, .parse
Returns an optional custom parser.
22 23 24 |
# File 'lib/vacuum/response.rb', line 22 def parser @parser end |
Instance Attribute Details
#parser ⇒ nil, .parse
Returns an optional custom parser.
30 31 32 |
# File 'lib/vacuum/response.rb', line 30 def parser @parser || self.class.parser end |
Instance Method Details
#dig(*key) ⇒ Object
Delegates to the Hash returned by #to_h to extract a nested value specified by the sequence of keys
18 |
# File 'lib/vacuum/response.rb', line 18 def_delegator :to_h, :dig |
#parse ⇒ Object
Note:
Delegates to #to_h if no custom parser is set
Parses the response body
37 38 39 |
# File 'lib/vacuum/response.rb', line 37 def parse parser&.parse(body) || to_h end |
#to_h ⇒ Hash
Casts body to Hash
44 45 46 |
# File 'lib/vacuum/response.rb', line 44 def to_h JSON.parse(body) end |