Skip to content

Commit a442b43

Browse files
author
Unai Abrisketa
authored
v0.9.0.pre
1 parent 7c1fa37 commit a442b43

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### v0.9.0.pre
2+
3+
* bug-fixes
4+
* Fix typo
5+
6+
* features
7+
* Add optional `paginated: false` parameter to `session.products.all(paginated: false)`
8+
19
### v0.8.1.pre
210

311
* bug-fixes

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
beyond_api (0.8.1.pre)
4+
beyond_api (0.9.0.pre)
55
faraday (~> 0.15)
66

77
GEM

lib/beyond_api/resources/product_attribute_definitions.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class ProductAttributeDefinitions < Base
1414
#
1515
# @beyond_api.scopes +prad:r+
1616
#
17-
# @option param [Boolean] :paginated
18-
# @option param [Integer] :size the page size
19-
# @option param [Integer] :page the page number
17+
# @option params [Boolean] :paginated
18+
# @option params [Integer] :size the page size
19+
# @option params [Integer] :page the page number
2020
#
2121
# @return [OpenStruct]
2222
#
@@ -32,6 +32,7 @@ def all(params = {})
3232
end
3333

3434
result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
35+
3536
result
3637
else
3738
all_paginated(params)

lib/beyond_api/resources/products.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Products < Base
3232
#
3333
# @beyond_api.scopes +prod:r+
3434
#
35+
# @option params [Boolean] :paginated
3536
# @option params [Integer] :size the page size
3637
# @option params [Integer] :page the page number
3738
#
@@ -41,9 +42,19 @@ class Products < Base
4142
# @products = session.products.all(size: 100, page: 0)
4243
#
4344
def all(params = {})
44-
response, status = BeyondApi::Request.get(@session, "/products", params)
45+
if params[:paginated] == false
46+
result = all_paginated(page: 0, size: 1000)
4547

46-
handle_response(response, status)
48+
(1..result[:page][:total_pages] - 1).each do |page|
49+
result[:embedded][:products].concat(all_paginated(page: page, size: 1000)[:embedded][:products])
50+
end
51+
52+
result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
53+
54+
result
55+
else
56+
all_paginated(params)
57+
end
4758
end
4859

4960
#
@@ -282,5 +293,13 @@ def assign_variation_images_differentiator(product_id, differentiator)
282293
alias_method :create_variation, :create
283294
alias_method :find_variation, :find
284295
alias_method :update_variation, :update
296+
297+
private
298+
299+
def all_paginated(params = {})
300+
response, status = BeyondApi::Request.get(@session, "/products", params)
301+
302+
handle_response(response, status)
303+
end
285304
end
286305
end

lib/beyond_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module BeyondApi
2-
VERSION = "0.8.1.pre".freeze
2+
VERSION = "0.9.0.pre".freeze
33
end

0 commit comments

Comments
 (0)