Class: OneRoster::Paginator
- Inherits:
-
Object
- Object
- OneRoster::Paginator
- Defined in:
- lib/one_roster/paginator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(connection, path, method, type, offset = 0, limit = PAGE_LIMIT, client: nil) ⇒ Paginator
constructor
A new instance of Paginator.
Constructor Details
#initialize(connection, path, method, type, offset = 0, limit = PAGE_LIMIT, client: nil) ⇒ Paginator
Returns a new instance of Paginator.
7 8 9 10 11 12 13 14 15 |
# File 'lib/one_roster/paginator.rb', line 7 def initialize(connection, path, method, type, offset = 0, limit = PAGE_LIMIT, client: nil) @connection = connection @path = path @method = method @type = type @offset = offset @limit = limit @client = client end |
Class Method Details
.fetch(*params, **kwargs) ⇒ Object
37 38 39 |
# File 'lib/one_roster/paginator.rb', line 37 def self.fetch(*params, **kwargs) new(*params, **kwargs).fetch end |
Instance Method Details
#fetch ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/one_roster/paginator.rb', line 17 def fetch Enumerator.new do |yielder| loop do response = request(@path, @offset) body = response.body fail "Failed to fetch #{@path}" unless response.success? fail StopIteration if body.empty? if body.any? body.each do |item| yielder << @type.new(item, client: @client) unless item['status'] == 'tobedeleted' end end @offset = next_offset end end.lazy end |