Class: Cephalopod::Response
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Cephalopod::Response
- Defined in:
- lib/cephalopod/response.rb
Defined Under Namespace
Modules: Pagination
Instance Method Summary collapse
-
#initialize(response:, repo:, &block) ⇒ Response
constructor
A new instance of Response.
- #paginated? ⇒ Boolean
- #pagination_links? ⇒ Boolean
- #payload ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(response:, repo:, &block) ⇒ Response
Returns a new instance of Response.
26 27 28 29 30 31 |
# File 'lib/cephalopod/response.rb', line 26 def initialize(response:, repo:, &block) @response = response @repo = repo extend Pagination if paginated? super(block_given? ? yield(@response.body) : parse_response) end |
Instance Method Details
#paginated? ⇒ Boolean
33 34 35 |
# File 'lib/cephalopod/response.rb', line 33 def paginated? @response.body.is_a?(Hash) && pagination_links? && @response.body.key?(:results) end |
#pagination_links? ⇒ Boolean
37 38 39 |
# File 'lib/cephalopod/response.rb', line 37 def pagination_links? @response.body.key?(:next) || @response.body.key?(:previous) end |
#payload ⇒ Object
45 46 47 |
# File 'lib/cephalopod/response.rb', line 45 def payload @response.body end |
#query ⇒ Object
41 42 43 |
# File 'lib/cephalopod/response.rb', line 41 def query @query ||= URI::decode_www_form(@response.env.url.query).to_h.symbolize_keys end |