Module: ArchivesSpace::Pagination
- Included in:
- Client
- Defined in:
- lib/archivesspace/client/pagination.rb
Overview
Handle API Pagination using enumerator
Constant Summary collapse
- ENDPOINTS =
TODO: get via lookup of endpoints that support pagination? (nice-to-have)
%w[ accessions agents/corporate_entities agents/families agents/people agents/software archival_objects digital_objects groups repositiories resources subjects users ]
Instance Method Summary collapse
Instance Method Details
#all(path, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/archivesspace/client/pagination.rb', line 29 def all(path, = {}) Enumerator.new do |yielder| page = 1 unlimited_listing = false loop do [:query] ||= {} [:query][:page] = page result = get(path, ) results = [] if result.parsed.respond_to?(:key) && result.parsed.key?('results') results = result.parsed['results'] else results = result.parsed unlimited_listing = true end if results.any? results.each do |i| yielder << i end raise StopIteration if unlimited_listing page += 1 else raise StopIteration end end end.lazy end |