Module: LHS::Service::All::ClassMethods
- Defined in:
- lib/lhs/concerns/service/all.rb
Instance Method Summary collapse
-
#all(params = {}) ⇒ Object
Should be an edge case but sometimes all objects from a certain resource are required.
Instance Method Details
#all(params = {}) ⇒ Object
Should be an edge case but sometimes all objects from a certain resource are required. In this case we load the first page with the default max limit, compute the amount of left over requests, do all the the left over requests for the following pages and concatenate all the results in order to return all the objects for a given resource.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lhs/concerns/service/all.rb', line 15 def all(params = {}) all = [] default_max_limit = 100 data = instance.request(params: params.merge(limit: default_max_limit)) all.concat(data._raw['items']) total_left = data._raw['total'] - data.count limit = data._raw['limit'] || data.count if limit > 0 requests = total_left / limit requests.times do |i| offset = limit * (i+1) + 1 all.concat instance.request(params: params.merge(limit: limit, offset: offset))._raw['items'] end end LHS::Data.new(all, nil, self) end |