Class: Peddler::Response
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Peddler::Response
- Extended by:
- Forwardable
- Defined in:
- lib/peddler/response.rb
Overview
Wraps HTTP::Response to allow custom parsing
Instance Attribute Summary collapse
Class Method Summary collapse
-
.decorate(response, parser: nil) ⇒ ResponseDecorator
Decorates an HTTP::Response.
Instance Method Summary collapse
-
#dig(*key) ⇒ Object
Delegates to the Hash returned by ResponseDecorator#to_h to extract a nested value specified by the sequence of keys.
- #parse ⇒ Object
-
#to_h ⇒ Hash
Converts the response body to a Hash.
Instance Attribute Details
#parser ⇒ #call
33 34 35 |
# File 'lib/peddler/response.rb', line 33 def parser @parser end |
Class Method Details
.decorate(response, parser: nil) ⇒ ResponseDecorator
Decorates an HTTP::Response
25 26 27 28 29 |
# File 'lib/peddler/response.rb', line 25 def decorate(response, parser: nil) new(response).tap do |decorator| decorator.parser = parser end end |
Instance Method Details
#dig(*key) ⇒ Object
Delegates to the Hash returned by ResponseDecorator#to_h to extract a nested value specified by the sequence of keys
17 |
# File 'lib/peddler/response.rb', line 17 def_delegator :to_h, :dig |
#parse ⇒ Object
35 36 37 |
# File 'lib/peddler/response.rb', line 35 def parse parser ? parser.call(__getobj__) : __getobj__.parse end |
#to_h ⇒ Hash
Converts the response body to a Hash
42 43 44 |
# File 'lib/peddler/response.rb', line 42 def to_h (parser && parser.respond_to?(:to_h) ? parser : parse).to_h end |