Module: InsalesApi::Resource::WithUpdatedSince
Instance Method Summary collapse
- #find_in_batches(options = {}, &block) ⇒ Object
- #find_updated_since(updated_since, options = {}) ⇒ Object
Instance Method Details
#find_in_batches(options = {}, &block) ⇒ Object
4 5 6 7 |
# File 'lib/insales_api/resource/with_updated_since.rb', line 4 def find_in_batches( = {}, &block) return super unless updated_since = .delete(:updated_since) find_updated_since(updated_since, , &block) end |
#find_updated_since(updated_since, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/insales_api/resource/with_updated_since.rb', line 9 def find_updated_since(updated_since, = {}) per_page = [:per_page] || PER_PAGE_DEFAULT params = { per_page: per_page }.merge([:params] || {}) last_id = nil loop do items = all(params: params.merge( updated_since: updated_since, from_id: last_id, )) return unless items.any? yield items return if items.count < per_page last_item = items.last last_id = last_item.id updated_since = last_item.updated_at end end |