class Brivo::Collection
Public Class Methods
new(application, api_path, model)
click to toggle source
# File lib/brivo/collection.rb, line 7 def initialize application, api_path, model @application = application @api_path = api_path @model = model @collection = [] fetch_collection end
Public Instance Methods
each(&block)
click to toggle source
# File lib/brivo/collection.rb, line 17 def each(&block) total_count = @total_count while @collection.count < total_count do collection_count = @collection.count fetch_collection(offset: collection_count) end @collection.each(&block) end
Private Instance Methods
fetch_collection(offset: 0)
click to toggle source
# File lib/brivo/collection.rb, line 29 def fetch_collection offset: 0 response = @application.http_request(@api_path, offset: offset) @total_count = response['count'] response['data'].each do |json| @collection << @model.new(json) end end