class OneRoster::Paginator
Public Class Methods
fetch(*params)
click to toggle source
# File lib/one_roster/paginator.rb, line 37 def self.fetch(*params) new(*params).fetch end
new(connection, path, method, type, offset = 0, limit = PAGE_LIMIT, client: nil)
click to toggle source
# 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
Public Instance Methods
fetch()
click to toggle source
# 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
Private Instance Methods
next_offset()
click to toggle source
# File lib/one_roster/paginator.rb, line 43 def next_offset @offset + @limit end
request(path, offset)
click to toggle source
# File lib/one_roster/paginator.rb, line 47 def request(path, offset) @connection.execute(path, @method, limit: @limit, offset: offset) end