beyond_api 0.9.0.pre → 0.10.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eb69d55a6ff81113a94022f031b7c09c6dd0e51a4337d48dc698d5aa6a79153
4
- data.tar.gz: 3b782cea11e4d0533827192fc8141519b487d034bf194657f05e01c04895458c
3
+ metadata.gz: 70c9bf9ccb3e7a42a71c8d5a092e0af6969842daf91a7219398b9f5516836cfe
4
+ data.tar.gz: d976cda9fdcc8df93394b3b9ad678453db3634a096c6832208e8fe49c917198b
5
5
  SHA512:
6
- metadata.gz: 705ebbe6fb68e9a8e4b456978d9d05af02ed03cf96c5002ad384037cda169a9074a99aa71e57e3e83a9e9651aa2662d21eeb7b2a11ac4c60e53a97fe7d35b59e
7
- data.tar.gz: fbba10e64cdb172ee326d1092841c2212683377a3f8325b3bcce1340cf76e149edb8ab2dfe0f9a3e5ea158b3dedc64915c19cf6ff8fe71293bdc3e89321fc19c
6
+ metadata.gz: 94e86e146eb7ed0696efbb7bf7a61e1ade093ba00571ef140e0fb019c6708680d8a26b3b0bc8295e3f30a1327b362b44b0b56b7b474973a975fd212e61317c90
7
+ data.tar.gz: 68cc2ad0ec1a9d855dc22c52ca4b5f9a1a76af244eeccc406bb7e384b72267c476f99db47652b34653a9d297836e7637ac9856e60eab09961eec7ea6e8733688
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### v0.10.0.pre
2
+
3
+ * features
4
+ * Add optional `paginated: false` parameter to `session.categories_view.all(paginated: false)`
5
+ * Add optional `paginated: false` parameter to `session.categories.all(paginated: false)`
6
+ * Add optional `paginated: false` parameter to `session.customers.all(paginated: false)`
7
+ * Add optional `paginated: false` parameter to `session.orders.all(paginated: false)`
8
+ * Add optional `paginated: false` parameter to `session.payment_methods.all(paginated: false)`
9
+ * Add optional `paginated: false` parameter to `session.products_view.all(paginated: false)`
10
+ * Add optional `paginated: false` parameter to `session.script_tags.all(paginated: false)`
11
+ * Add optional `paginated: false` parameter to `session.shipping_zones.all(paginated: false)`
12
+ * Add optional `paginated: false` parameter to `session.users.all(paginated: false)`
13
+ * Add optional `paginated: false` parameter to `session.webhook_subscriptions.all(paginated: false)`
14
+
1
15
  ### v0.9.0.pre
2
16
 
3
17
  * bug-fixes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.9.0.pre)
4
+ beyond_api (0.10.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -16,6 +16,7 @@ module BeyondApi
16
16
  #
17
17
  # @beyond_api.scopes +catg:r+
18
18
  #
19
+ # @option params [Boolean] :paginated
19
20
  # @option params [Integer] :size the page size
20
21
  # @option params [Integer] :page the page number
21
22
  #
@@ -25,9 +26,7 @@ module BeyondApi
25
26
  # @categories = session.categories.all(size: 100, page: 0)
26
27
  #
27
28
  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)
31
30
  end
32
31
 
33
32
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  # -H 'Accept: application/hal+json'
15
15
  #
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @categories = session.categories_view.all(size: 100, page: 0)
24
25
  #
25
26
  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)
29
28
  end
30
29
 
31
30
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  #
15
15
  # @beyond_api.scopes +cust:r+
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @customers = session.customers.all(size: 20, page: 0)
24
25
  #
25
26
  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)
29
28
  end
30
29
 
31
30
  #
@@ -57,6 +57,7 @@ module BeyondApi
57
57
  #
58
58
  # @beyond_api.scopes +ordr:r+
59
59
  #
60
+ # @option params [Boolean] :paginated
60
61
  # @option params [Integer] :size the page size
61
62
  # @option params [Integer] :page the page number
62
63
  #
@@ -66,9 +67,7 @@ module BeyondApi
66
67
  # @orders = session.orders.all(size: 100, page: 0)
67
68
  #
68
69
  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)
72
71
  end
73
72
 
74
73
  #
@@ -38,6 +38,7 @@ module BeyondApi
38
38
  #
39
39
  # @beyond_api.scopes +pymt:r+
40
40
  #
41
+ # @option params [Boolean] :paginated
41
42
  # @option params [Integer] :size the page size
42
43
  # @option params [Integer] :page the page number
43
44
  #
@@ -47,9 +48,7 @@ module BeyondApi
47
48
  # @payment_methods = session.payment_methods.all(size: 100, page: 0)
48
49
  #
49
50
  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)
53
52
  end
54
53
 
55
54
  #
@@ -24,19 +24,7 @@ module BeyondApi
24
24
  # @product_attribute_definitions = session.product_attribute_definitions.all(size: 100, page: 0)
25
25
  #
26
26
  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)
40
28
  end
41
29
 
42
30
  #
@@ -114,12 +102,5 @@ module BeyondApi
114
102
 
115
103
  handle_response(response, status)
116
104
  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
124
105
  end
125
106
  end
@@ -42,19 +42,7 @@ module BeyondApi
42
42
  # @products = session.products.all(size: 100, page: 0)
43
43
  #
44
44
  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)
58
46
  end
59
47
 
60
48
  #
@@ -293,13 +281,5 @@ module BeyondApi
293
281
  alias_method :create_variation, :create
294
282
  alias_method :find_variation, :find
295
283
  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
304
284
  end
305
285
  end
@@ -13,6 +13,7 @@ module BeyondApi
13
13
  # -H 'Content-Type: application/json' \
14
14
  # -H 'Accept: application/hal+json'
15
15
  #
16
+ # @option params [Boolean] :paginated
16
17
  # @option params [Integer] :size the page size
17
18
  # @option params [Integer] :page the page number
18
19
  #
@@ -22,9 +23,7 @@ module BeyondApi
22
23
  # @products = session.products_view.all(page: 0, size: 100)
23
24
  #
24
25
  def all(params = {})
25
- response, status = BeyondApi::Request.get(@session, "/product-view/products", params)
26
-
27
- handle_response(response, status)
26
+ handle_all_request("/product-view/products", :products, params)
28
27
  end
29
28
 
30
29
  #
@@ -12,6 +12,7 @@ module BeyondApi
12
12
  # $ curl 'https://api-shop.beyondshop.cloud/api/script-tags' -i -X GET \
13
13
  # -H 'Authorization: Bearer <Access token>'
14
14
  #
15
+ # @option params [Boolean] :paginated
15
16
  # @option params [Integer] :size the page size
16
17
  # @option params [Integer] :page the page number
17
18
  #
@@ -21,9 +22,7 @@ module BeyondApi
21
22
  # @script_tags = session.script_tags.all(size: 20, page: 0)
22
23
  #
23
24
  def all(params = {})
24
- response, status = BeyondApi::Request.get(@session, "/script-tags", params)
25
-
26
- handle_response(response, status)
25
+ handle_all_request("/script-tags", :script_tags, params)
27
26
  end
28
27
 
29
28
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X GET \
15
15
  # -H 'Authorization: Bearer <Access token>'
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @shipping_zones = session.shipping_zones.all(size: 20, page: 0)
24
25
  #
25
26
  def all(params = {})
26
- response, status = BeyondApi::Request.get(@session, "/shipping-zones", params)
27
-
28
- handle_response(response, status)
27
+ handle_all_request("/shipping-zones", :shipping_zones, params)
29
28
  end
30
29
 
31
30
  #
@@ -40,6 +40,7 @@ module BeyondApi
40
40
  #
41
41
  # @beyond_api.scopes +user:r+
42
42
  #
43
+ # @option params [Boolean] :paginated
43
44
  # @option params [Integer] :size the page size
44
45
  # @option params [Integer] :page the page number
45
46
  #
@@ -49,9 +50,7 @@ module BeyondApi
49
50
  # @users = session.users.all(size: 100, page: 0)
50
51
  #
51
52
  def all(params = {})
52
- response, status = BeyondApi::Request.get(@session, "/users")
53
-
54
- handle_response(response, status)
53
+ handle_all_request("/users", :users, params)
55
54
  end
56
55
 
57
56
  #
@@ -34,6 +34,7 @@ module BeyondApi
34
34
  # -H 'Accept: application/hal+json' \
35
35
  # -H 'Authorization: Bearer <Access token>'
36
36
  #
37
+ # @option params [Boolean] :paginated
37
38
  # @option params [Integer] :size the page size
38
39
  # @option params [Integer] :page the page number
39
40
  #
@@ -43,9 +44,7 @@ module BeyondApi
43
44
  # @webhook_subscriptions = session.webhook_subscriptions.all(size: 100, page: 0)
44
45
  #
45
46
  def all(params = {})
46
- response, status = BeyondApi::Request.get(@session, "/webhook-subscriptions", params)
47
-
48
- handle_response(response, status)
47
+ handle_all_request("/webhook-subscriptions", :webhook_subscriptions, params)
49
48
  end
50
49
 
51
50
  #
@@ -39,6 +39,22 @@ module BeyondApi
39
39
  key.chars.first == "_" ? key[1..-1] : key
40
40
  end
41
41
 
42
+ def handle_all_request(url, resource, params = {})
43
+ if params[:paginated] == false
44
+ result = all_paginated(url, { page: 0, size: 1000 })
45
+
46
+ (1..result[:page][:total_pages] - 1).each do |page|
47
+ result[:embedded][resource].concat(all_paginated(url, { page: page, size: 1000 })[:embedded][resource])
48
+ end
49
+
50
+ result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
51
+
52
+ result
53
+ else
54
+ all_paginated(url, params)
55
+ end
56
+ end
57
+
42
58
  private
43
59
 
44
60
  def transform(thing)
@@ -48,5 +64,11 @@ module BeyondApi
48
64
  else; thing
49
65
  end
50
66
  end
67
+
68
+ def all_paginated(url, params = {})
69
+ response, status = BeyondApi::Request.get(@session, url, params)
70
+
71
+ handle_response(response, status)
72
+ end
51
73
  end
52
74
  end
@@ -1,3 +1,3 @@
1
1
  module BeyondApi
2
- VERSION = "0.9.0.pre".freeze
2
+ VERSION = "0.10.0.pre".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.pre
4
+ version: 0.10.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-05-11 00:00:00.000000000 Z
13
+ date: 2020-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler