Skip to content

Commit

Permalink
Fix all paginated (#37)
Browse files Browse the repository at this point in the history
* Fix all paginated

* Update version
  • Loading branch information
k4th authored Jul 16, 2021
1 parent 9c2d65e commit 3d37ac5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### v0.16.1.pre

* bug-fixes
* Fix method to retrieve resources without pagination

### v0.16.0.pre

* features
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
beyond_api (0.16.0.pre)
beyond_api (0.16.1.pre)
faraday (~> 0.15)

GEM
Expand Down
9 changes: 6 additions & 3 deletions lib/beyond_api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ def sanitize_key(key)
end

def handle_all_request(url, resource, params = {})

if params[:paginated] == false
result = all_paginated(url, { page: 0, size: 1000 })
result = all_paginated(url, params.merge(page: 0, size: 1000))

(1..result[:page][:total_pages] - 1).each do |page|
result[:embedded][resource].concat(all_paginated(url, { page: page, size: 1000 })[:embedded][resource])
result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: 1000))[:embedded][resource])
end

result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
result[:page][:size] = result[:page][:total_elements]
result[:page][:total_pages] = 1
result[:page][:number] = 0

result
else
Expand Down
2 changes: 1 addition & 1 deletion lib/beyond_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BeyondApi
VERSION = "0.16.0.pre".freeze
VERSION = "0.16.1.pre".freeze
end

0 comments on commit 3d37ac5

Please sign in to comment.