diff --git a/lib/ecwid_api/paged_ecwid_response.rb b/lib/ecwid_api/paged_ecwid_response.rb index 266a09a..a1a57a8 100644 --- a/lib/ecwid_api/paged_ecwid_response.rb +++ b/lib/ecwid_api/paged_ecwid_response.rb @@ -36,13 +36,16 @@ def initialize(client, path, params = {}, &block) response = client.get(path, params) @paged_enumerator = PagedEnumerator.new(response) do |response, yielder| - response.body["items"].each do |item| - yielder << block.call(item) - end - + count, offset, total = %w(count offset total).map do |i| response.body[i].to_i end + + if count > 0 + response.body["items"].each do |item| + yielder << block.call(item) + end + end if count == 0 || count + offset >= total false @@ -52,4 +55,4 @@ def initialize(client, path, params = {}, &block) end end end -end \ No newline at end of file +end