Skip to content

Commit c6dd194

Browse files
author
unabris
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4b5ffd9 + 1536161 commit c6dd194

18 files changed

+88
-83
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
### v0.11.0.pre
2+
3+
* enhancements
4+
* Improve error handling class
5+
* Improve `BeyondApi::Error` class
6+
7+
### v0.10.0.pre
8+
9+
* features
10+
* Add optional `paginated: false` parameter to `session.categories_view.all(paginated: false)`
11+
* Add optional `paginated: false` parameter to `session.categories.all(paginated: false)`
12+
* Add optional `paginated: false` parameter to `session.customers.all(paginated: false)`
13+
* Add optional `paginated: false` parameter to `session.orders.all(paginated: false)`
14+
* Add optional `paginated: false` parameter to `session.payment_methods.all(paginated: false)`
15+
* Add optional `paginated: false` parameter to `session.products_view.all(paginated: false)`
16+
* Add optional `paginated: false` parameter to `session.script_tags.all(paginated: false)`
17+
* Add optional `paginated: false` parameter to `session.shipping_zones.all(paginated: false)`
18+
* Add optional `paginated: false` parameter to `session.users.all(paginated: false)`
19+
* Add optional `paginated: false` parameter to `session.webhook_subscriptions.all(paginated: false)`
20+
121
### v0.9.0.pre
222

323
* 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.9.0.pre)
4+
beyond_api (0.11.0.pre)
55
faraday (~> 0.15)
66

77
GEM

lib/beyond_api/error.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# frozen_string_literal: true
22

33
module BeyondApi
4-
class Error
5-
attr_reader :error_id, :details, :message, :trace_id
4+
class Error < StandardError
5+
attr_reader :error_id, :details, :trace_id, :full_message, :status_code
66

7-
def initialize(data)
8-
@error_id = data['errorId']
9-
@details = data['details']
10-
@message = data['message']
11-
@trace_id = data['traceId']
7+
def initialize(data, status_code = nil)
8+
@error_id = data['errorId']
9+
@details = data['details']
10+
@trace_id = data['traceId']
11+
@full_message = data
12+
@status_code = status_code
13+
14+
super(data['message'])
1215
end
1316
end
1417
end

lib/beyond_api/resources/categories.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Categories < Base
1616
#
1717
# @beyond_api.scopes +catg:r+
1818
#
19+
# @option params [Boolean] :paginated
1920
# @option params [Integer] :size the page size
2021
# @option params [Integer] :page the page number
2122
#
@@ -25,9 +26,7 @@ class Categories < Base
2526
# @categories = session.categories.all(size: 100, page: 0)
2627
#
2728
def all(params = {})
28-
response, status = BeyondApi::Request.get(@session, "/categories", params)
29-
30-
handle_response(response, status)
29+
handle_all_request("/categories", :categories, params)
3130
end
3231

3332
#

lib/beyond_api/resources/categories_view.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CategoriesView < Base
1414
# -H 'Accept: application/hal+json'
1515
#
1616
#
17+
# @option params [Boolean] :paginated
1718
# @option params [Integer] :size the page size
1819
# @option params [Integer] :page the page number
1920
#
@@ -23,9 +24,7 @@ class CategoriesView < Base
2324
# @categories = session.categories_view.all(size: 100, page: 0)
2425
#
2526
def all(params = {})
26-
response, status = BeyondApi::Request.get(@session, "/product-view/categories", params)
27-
28-
handle_response(response, status)
27+
handle_all_request("/product-view/categories", :categories, params)
2928
end
3029

3130
#

lib/beyond_api/resources/customers.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Customers < Base
1414
#
1515
# @beyond_api.scopes +cust:r+
1616
#
17+
# @option params [Boolean] :paginated
1718
# @option params [Integer] :size the page size
1819
# @option params [Integer] :page the page number
1920
#
@@ -23,9 +24,7 @@ class Customers < Base
2324
# @customers = session.customers.all(size: 20, page: 0)
2425
#
2526
def all(params = {})
26-
response, status = BeyondApi::Request.get(@session, "/customers", params)
27-
28-
handle_response(response, status)
27+
handle_all_request("/customers", :customers, params)
2928
end
3029

3130
#

lib/beyond_api/resources/orders.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def active_refund_process(order_id)
5757
#
5858
# @beyond_api.scopes +ordr:r+
5959
#
60+
# @option params [Boolean] :paginated
6061
# @option params [Integer] :size the page size
6162
# @option params [Integer] :page the page number
6263
#
@@ -66,9 +67,7 @@ def active_refund_process(order_id)
6667
# @orders = session.orders.all(size: 100, page: 0)
6768
#
6869
def all(params = {})
69-
response, status = BeyondApi::Request.get(@session, "/orders", params)
70-
71-
handle_response(response, status)
70+
handle_all_request("/orders", :orders, params)
7271
end
7372

7473
#

lib/beyond_api/resources/payment_methods.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def activate(payment_method_id)
3838
#
3939
# @beyond_api.scopes +pymt:r+
4040
#
41+
# @option params [Boolean] :paginated
4142
# @option params [Integer] :size the page size
4243
# @option params [Integer] :page the page number
4344
#
@@ -47,9 +48,7 @@ def activate(payment_method_id)
4748
# @payment_methods = session.payment_methods.all(size: 100, page: 0)
4849
#
4950
def all(params = {})
50-
response, status = BeyondApi::Request.get(@session, "/payment-methods", params)
51-
52-
handle_response(response, status)
51+
handle_all_request("/payment-methods", :payment_methods, params)
5352
end
5453

5554
#

lib/beyond_api/resources/product_attribute_definitions.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@ class ProductAttributeDefinitions < Base
2424
# @product_attribute_definitions = session.product_attribute_definitions.all(size: 100, page: 0)
2525
#
2626
def all(params = {})
27-
if params[:paginated] == false
28-
result = all_paginated(page: 0, size: 1000)
29-
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-
36-
result
37-
else
38-
all_paginated(params)
39-
end
27+
handle_all_request("/product-attribute-definitions", :product_attribute_definitions, params)
4028
end
4129

4230
#
@@ -114,12 +102,5 @@ def find(product_attribute_name)
114102

115103
handle_response(response, status)
116104
end
117-
118-
private
119-
120-
def all_paginated(params = {})
121-
response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions", params)
122-
handle_response(response, status)
123-
end
124105
end
125106
end

lib/beyond_api/resources/products.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,7 @@ class Products < Base
4242
# @products = session.products.all(size: 100, page: 0)
4343
#
4444
def all(params = {})
45-
if params[:paginated] == false
46-
result = all_paginated(page: 0, size: 1000)
47-
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
45+
handle_all_request("/products", :products, params)
5846
end
5947

6048
#
@@ -293,13 +281,5 @@ def assign_variation_images_differentiator(product_id, differentiator)
293281
alias_method :create_variation, :create
294282
alias_method :find_variation, :find
295283
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
304284
end
305285
end

0 commit comments

Comments
 (0)