From 3d37ac58dd2c42cdea17000e46c750918df768ef Mon Sep 17 00:00:00 2001 From: Kathia Date: Fri, 16 Jul 2021 16:07:01 +0200 Subject: [PATCH] Fix all paginated (#37) * Fix all paginated * Update version --- CHANGELOG.md | 5 +++++ Gemfile.lock | 2 +- lib/beyond_api/utils.rb | 9 ++++++--- lib/beyond_api/version.rb | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccce848..4fa2bbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v0.16.1.pre + +* bug-fixes + * Fix method to retrieve resources without pagination + ### v0.16.0.pre * features diff --git a/Gemfile.lock b/Gemfile.lock index e01b278..b1e8f00 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - beyond_api (0.16.0.pre) + beyond_api (0.16.1.pre) faraday (~> 0.15) GEM diff --git a/lib/beyond_api/utils.rb b/lib/beyond_api/utils.rb index 6e1bd53..aa39e96 100644 --- a/lib/beyond_api/utils.rb +++ b/lib/beyond_api/utils.rb @@ -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 diff --git a/lib/beyond_api/version.rb b/lib/beyond_api/version.rb index 0c237c7..82e5b37 100644 --- a/lib/beyond_api/version.rb +++ b/lib/beyond_api/version.rb @@ -1,3 +1,3 @@ module BeyondApi - VERSION = "0.16.0.pre".freeze + VERSION = "0.16.1.pre".freeze end