Sha256: 6272eabd0700db83fd53648805327165f106f1870c13a36bb83d629cc91b927e

Contents?: true

Size: 805 Bytes

Versions: 18

Compression:

Stored size: 805 Bytes

Contents

require_relative 'base_endpoint'

module Panoptes
  module Endpoints
    class JsonApiEndpoint < BaseEndpoint
      # Get a path and perform automatic depagination
      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
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
panoptes-client-1.0.0.pre1 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-1.0.0.pre lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.4.0 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.8 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.7 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.6 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.5 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.4 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.3 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.2 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.1 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.3.0 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.13 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.12 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.11 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.10 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.9 lib/panoptes/endpoints/json_api_endpoint.rb
panoptes-client-0.2.8 lib/panoptes/endpoints/json_api_endpoint.rb