Skip to content

Commit 7459c44

Browse files
authored
Release v0.4.0.pre (#12)
1 parent 92deb7e commit 7459c44

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### v0.4.0.pre
2+
3+
* bug-fixes
4+
* Fix product attribute definition `create` method
5+
* Fix product attribute definition `delete` method
6+
* Fix product custom attribute module name
7+
* Include `BeyondApi::ProductCustomAttributes` module into `BeyondApi::Products` class
8+
* Include `BeyondApi::ProductImages` module into `BeyondApi::Products` class
9+
10+
* enhancements
11+
* Allow to get all product attribute definitions on a single call
12+
113
### v0.3.0.pre
214

315
* 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.3.0.pre)
4+
beyond_api (0.4.0.pre)
55
faraday (~> 0.15)
66

77
GEM

lib/beyond_api/resources/product_attribute_definitions.rb

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ProductAttributeDefinitions < Base
1414
#
1515
# @beyond_api.scopes +prad:r+
1616
#
17+
# @option param [Boolean] :paginated
1718
# @option param [Integer] :size the page size
1819
# @option param [Integer] :page the page number
1920
#
@@ -23,9 +24,18 @@ class ProductAttributeDefinitions < Base
2324
# @product_attribute_definitions = session.product_attribute_definitions.all(size: 100, page: 0)
2425
#
2526
def all(params = {})
26-
response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions", params)
27+
if params[:paginated] == false
28+
result = all_paginated(page: 0, size: 1000)
2729

28-
handle_response(response, status)
30+
(1..result[:page][:total_pages] - 1).each do |page|
31+
result[:embedded][:product_attribute_definition].concat(all_paginated(page: page, size: 1000)[:embedded][:product_attribute_definitions])
32+
end
33+
34+
result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
35+
result
36+
else
37+
all_paginated(params)
38+
end
2939
end
3040

3141
#
@@ -56,8 +66,8 @@ def all(params = {})
5666
# }
5767
# @product_attribute_definition = session.product_attribute_definitions.create(body)
5868
#
59-
def create(product_attribute_name)
60-
response, status = BeyondApi::Request.post(@session, "/product-attribute-definitions")
69+
def create(body)
70+
response, status = BeyondApi::Request.post(@session, "/product-attribute-definitions", body)
6171

6272
handle_response(response, status)
6373
end
@@ -80,7 +90,7 @@ def create(product_attribute_name)
8090
# session.product_attribute_definitions.delete("filling_capacity")
8191
#
8292
def delete(product_attribute_name)
83-
response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions/#{product_attribute_name}")
93+
response, status = BeyondApi::Request.delete(@session, "/product-attribute-definitions/#{product_attribute_name}")
8494

8595
handle_response(response, status, respond_with_true: true)
8696
end
@@ -105,5 +115,12 @@ def find(product_attribute_name)
105115

106116
handle_response(response, status)
107117
end
118+
119+
private
120+
121+
def all_paginated(params = {})
122+
response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions", params)
123+
handle_response(response, status)
124+
end
108125
end
109126
end

lib/beyond_api/resources/products.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# frozen_string_literal: true
22

33
require "beyond_api/utils"
4+
require "beyond_api/resources/products/custom_attributes"
5+
require "beyond_api/resources/products/images"
46

57
module BeyondApi
68
class Products < Base
9+
include BeyondApi::ProductCustomAttributes
10+
include BeyondApi::ProductImages
711
include BeyondApi::Utils
812

913
#

lib/beyond_api/resources/products/custom_attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "beyond_api/utils"
44

55
module BeyondApi
6-
module ProductCustomAttribute
6+
module ProductCustomAttributes
77

88
#
99
# A +POST+ request is used to create a product attribute, which defines the value of a certain {product attribute definition}[http://docs.beyondshop.cloud/#resources-product-attribute-definitions] for a specific {product}[http://docs.beyondshop.cloud/#resources-products].

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.3.0.pre".freeze
2+
VERSION = "0.4.0.pre".freeze
33
end

0 commit comments

Comments
 (0)