Class: Panoptes::Endpoints::JsonApiEndpoint
- Inherits:
-
BaseEndpoint
- Object
- BaseEndpoint
- Panoptes::Endpoints::JsonApiEndpoint
- Defined in:
- lib/panoptes/endpoints/json_api_endpoint.rb
Instance Attribute Summary
Attributes inherited from BaseEndpoint
Instance Method Summary collapse
-
#paginate(path, query, resource: nil) ⇒ Object
Get a path and perform automatic depagination.
Methods inherited from BaseEndpoint
#connection, #delete, #etag_header, #get, #handle_response, #initialize, #patch, #post, #put, #request
Constructor Details
This class inherits a constructor from Panoptes::Endpoints::BaseEndpoint
Instance Method Details
#paginate(path, query, resource: nil) ⇒ Object
Get a path and perform automatic depagination
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/panoptes/endpoints/json_api_endpoint.rb', line 7 def paginate(path, query, resource: nil) resource = path.split('/').last if resource.nil? data = last_response = get(path, query) while next_path = last_response['meta'][resource]['next_href'] last_response = get(next_path, query) if block_given? yield data, last_response else data[resource].concat(last_response[resource]) if data[resource].is_a?(Array) data['meta'][resource].merge!(last_response['meta'][resource]) data['links'].merge!(last_response['links']) end end data end |