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.
21 22 23 |
# File 'lib/vacuum/response.rb', line 21 def parser @parser end |
Instance Attribute Details
#parser ⇒ nil, .parse
Returns an optional custom parser.
29 30 31 |
# File 'lib/vacuum/response.rb', line 29 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
17 |
# File 'lib/vacuum/response.rb', line 17 def_delegator :to_h, :dig |
#parse ⇒ Object
Note:
Delegates to #to_h if no custom parser is set
Parses the response body
36 37 38 |
# File 'lib/vacuum/response.rb', line 36 def parse parser ? parser.parse(body) : to_h end |
#to_h ⇒ Hash
Casts body to Hash
42 43 44 |
# File 'lib/vacuum/response.rb', line 42 def to_h JSON.parse(body) end |