beyond_api 0.16.0.pre → 0.18.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +33 -0
  3. data/CHANGELOG.md +38 -1
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +30 -2
  6. data/Rakefile +4 -2
  7. data/beyond_api.gemspec +13 -9
  8. data/bin/console +2 -1
  9. data/lib/beyond_api/connection.rb +7 -4
  10. data/lib/beyond_api/error.rb +6 -6
  11. data/lib/beyond_api/ext.rb +16 -16
  12. data/lib/beyond_api/request.rb +4 -4
  13. data/lib/beyond_api/resources/carts.rb +52 -23
  14. data/lib/beyond_api/resources/categories_view.rb +16 -6
  15. data/lib/beyond_api/resources/newsletter_target.rb +10 -4
  16. data/lib/beyond_api/resources/orders.rb +152 -33
  17. data/lib/beyond_api/resources/payment_method_definitions.rb +11 -4
  18. data/lib/beyond_api/resources/product_attribute_definitions.rb +16 -4
  19. data/lib/beyond_api/resources/products/attachments.rb +0 -2
  20. data/lib/beyond_api/resources/products/availability.rb +20 -11
  21. data/lib/beyond_api/resources/products/cross_sells.rb +0 -1
  22. data/lib/beyond_api/resources/products/custom_attributes.rb +0 -1
  23. data/lib/beyond_api/resources/products/images.rb +12 -9
  24. data/lib/beyond_api/resources/products/searches.rb +2 -2
  25. data/lib/beyond_api/resources/products/variation_properties.rb +0 -1
  26. data/lib/beyond_api/resources/products/videos.rb +4 -3
  27. data/lib/beyond_api/resources/products.rb +32 -13
  28. data/lib/beyond_api/resources/products_view.rb +21 -5
  29. data/lib/beyond_api/resources/script_tags.rb +21 -5
  30. data/lib/beyond_api/resources/shipping_zones.rb +53 -12
  31. data/lib/beyond_api/resources/shop.rb +9 -2
  32. data/lib/beyond_api/resources/shops/address.rb +0 -1
  33. data/lib/beyond_api/resources/shops/attributes.rb +0 -1
  34. data/lib/beyond_api/resources/shops/images.rb +12 -9
  35. data/lib/beyond_api/resources/shops/legals.rb +14 -7
  36. data/lib/beyond_api/resources/shops/locations.rb +0 -1
  37. data/lib/beyond_api/resources/signers.rb +12 -3
  38. data/lib/beyond_api/resources/token.rb +20 -18
  39. data/lib/beyond_api/resources/users.rb +73 -15
  40. data/lib/beyond_api/resources/variations/availability.rb +17 -5
  41. data/lib/beyond_api/resources/variations/images.rb +32 -15
  42. data/lib/beyond_api/resources/variations.rb +14 -3
  43. data/lib/beyond_api/resources/webhook_subscriptions.rb +30 -8
  44. data/lib/beyond_api/session.rb +7 -1
  45. data/lib/beyond_api/utils.rb +44 -38
  46. data/lib/beyond_api/version.rb +3 -1
  47. data/lib/beyond_api.rb +6 -2
  48. data/lib/generators/beyond_api/install_generator.rb +1 -1
  49. data/lib/generators/templates/beyond_api_initializer.rb +3 -0
  50. metadata +59 -15
@@ -4,7 +4,6 @@ require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
6
  module ShopLegals
7
-
8
7
  #
9
8
  # A +GET+ request is used to retrieve a specific part of the legal content information.
10
9
  #
@@ -20,7 +19,8 @@ module BeyondApi
20
19
  # @legal_content = session.shop.legal_content("right-of-withdrawal")
21
20
  #
22
21
  def legal_content(legal_content_type)
23
- response, status = BeyondApi::Request.get(@session, "/legal-content/#{legal_content_type}")
22
+ response, status = BeyondApi::Request.get(@session,
23
+ "/legal-content/#{legal_content_type}")
24
24
 
25
25
  handle_response(response, status)
26
26
  end
@@ -41,7 +41,9 @@ module BeyondApi
41
41
  # @legal_content = session.shop.legal_contents(size: 5, page: 1)
42
42
  #
43
43
  def legal_contents(params = {})
44
- response, status = BeyondApi::Request.get(@session, "/legal-content", params)
44
+ response, status = BeyondApi::Request.get(@session,
45
+ "/legal-content",
46
+ params)
45
47
 
46
48
  handle_response(response, status)
47
49
  end
@@ -60,12 +62,13 @@ module BeyondApi
60
62
  # @legal_details = session.shop.legal_details
61
63
  #
62
64
  def legal_details
63
- response, status = BeyondApi::Request.get(@session, "/shop/legal")
65
+ response, status = BeyondApi::Request.get(@session,
66
+ "/shop/legal")
64
67
 
65
68
  handle_response(response, status)
66
69
  end
67
70
 
68
- #
71
+ #
69
72
  # A +PUT+ request is used to update the content of a specific part of the legal content information. Changes on the properties type and mandatory will be ignored.
70
73
  #
71
74
  # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/legal-notice' -i -X PUT \
@@ -86,7 +89,9 @@ module BeyondApi
86
89
  # session.shop.update_legal_content(body)
87
90
  #
88
91
  def update_legal_content(body)
89
- response, status = BeyondApi::Request.put(@session, "/legal-content/legal-notice")
92
+ response, status = BeyondApi::Request.put(@session,
93
+ "/legal-content/legal-notice",
94
+ body)
90
95
 
91
96
  handle_response(response, status)
92
97
  end
@@ -116,7 +121,9 @@ module BeyondApi
116
121
  # session.shop.update_legal_details(body)
117
122
  #
118
123
  def update_legal_details(body)
119
- response, status = BeyondApi::Request.patch(@session, "/shop/legal")
124
+ response, status = BeyondApi::Request.patch(@session,
125
+ "/shop/legal",
126
+ body)
120
127
 
121
128
  handle_response(response, status)
122
129
  end
@@ -4,7 +4,6 @@ require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
6
  module ShopLocations
7
-
8
7
  #
9
8
  # A +GET+ request is used to retrieve a list of all locations for the current shop.
10
9
  #
@@ -19,7 +19,10 @@ module BeyondApi
19
19
  # @signers = session.signers.all
20
20
  #
21
21
  def all
22
- response, status = BeyondApi::Request.get(@session, "/signers")
22
+ path = "/signers"
23
+
24
+ response, status = BeyondApi::Request.get(@session,
25
+ path)
23
26
 
24
27
  handle_response(response, status)
25
28
  end
@@ -37,7 +40,10 @@ module BeyondApi
37
40
  # @signer = session.signers.create
38
41
  #
39
42
  def create
40
- response, status = BeyondApi::Request.post(@session, "/signers")
43
+ path = "/signers"
44
+
45
+ response, status = BeyondApi::Request.post(@session,
46
+ path)
41
47
 
42
48
  handle_response(response, status)
43
49
  end
@@ -55,7 +61,10 @@ module BeyondApi
55
61
  # session.signers.delete("6bb72afd-340e-439a-9990-eef2e0883e1e")
56
62
  #
57
63
  def delete(signer_id)
58
- response, status = BeyondApi::Request.delete(@session, "/signers/#{signer_id}")
64
+ path = "/signers/#{signer_id}"
65
+
66
+ response, status = BeyondApi::Request.delete(@session,
67
+ path)
59
68
 
60
69
  handle_response(response, status, respond_with_true: true)
61
70
  end
@@ -13,35 +13,37 @@ module BeyondApi
13
13
  def initialize(session)
14
14
  @session = session
15
15
 
16
- raise InvalidSessionError.new("Invalid session") unless session.is_a? BeyondApi::Session
17
- raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
16
+ raise InvalidSessionError, "Invalid session" unless session.is_a? BeyondApi::Session
17
+ raise InvalidSessionError, "Session api_url cannot be nil" if session.api_url.nil?
18
18
  end
19
19
 
20
- def create(code)
21
- response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
22
- grant_type: "authorization_code",
23
- code: code)
24
-
25
- handle_response(response, status)
20
+ def authorization_code(code)
21
+ handle_token_call("authorization_code", code: code)
26
22
  end
27
23
 
28
- def refresh
29
- response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
30
- grant_type: "refresh_token",
31
- refresh_token: @session.refresh_token)
32
-
33
- handle_response(response, status)
24
+ def refresh_token
25
+ handle_token_call("refresh_token", refresh_token: @session.refresh_token)
34
26
  end
35
27
 
36
28
  def client_credentials
37
- response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
38
- grant_type: "client_credentials")
39
-
40
- handle_response(response, status)
29
+ handle_token_call("client_credentials")
41
30
  end
42
31
 
32
+ alias refresh refresh_token
33
+ alias create authorization_code
34
+
43
35
  private
44
36
 
37
+ def handle_token_call(grant_type, params = {})
38
+ path = "#{@session.api_url}/oauth/token"
39
+ params.merge!(grant_type: grant_type)
40
+
41
+ response, status = BeyondApi::Request.token(path,
42
+ params)
43
+
44
+ handle_response(response, status)
45
+ end
46
+
45
47
  def handle_response(response, status)
46
48
  if status.between?(200, 299)
47
49
  @session.access_token = response["access_token"]
@@ -25,7 +25,11 @@ module BeyondApi
25
25
  # session.users.add_roles(user_id, body)
26
26
  #
27
27
  def add_roles(user_id, body)
28
- response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/roles", body)
28
+ path = "/users/#{user_id}/roles"
29
+
30
+ response, status = BeyondApi::Request.post(@session,
31
+ path,
32
+ body)
29
33
 
30
34
  handle_response(response, status, respond_with_true: true)
31
35
  end
@@ -50,7 +54,9 @@ module BeyondApi
50
54
  # @users = session.users.all(size: 100, page: 0)
51
55
  #
52
56
  def all(params = {})
53
- handle_all_request("/users", :users, params)
57
+ path = "/users"
58
+
59
+ handle_all_request(path, :users, params)
54
60
  end
55
61
 
56
62
  #
@@ -77,7 +83,12 @@ module BeyondApi
77
83
  # session.users.change_password(user_id, current_password, new_password)
78
84
  #
79
85
  def change_password(user_id, current_password, new_password)
80
- response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-password", current_password: current_password, new_password: new_password)
86
+ path = "/users/#{user_id}/change-password"
87
+
88
+ response, status = BeyondApi::Request.post(@session,
89
+ path,
90
+ current_password: current_password,
91
+ new_password: new_password)
81
92
 
82
93
  handle_response(response, status)
83
94
  end
@@ -104,7 +115,12 @@ module BeyondApi
104
115
  # session.users.change_username(user_id, new_username, current_password)
105
116
  #
106
117
  def change_username(user_id, new_username, current_password)
107
- response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-username", new_username: new_username, current_password: current_password)
118
+ path = "/users/#{user_id}/change-username"
119
+
120
+ response, status = BeyondApi::Request.post(@session,
121
+ path,
122
+ new_username: new_username,
123
+ current_password: current_password)
108
124
 
109
125
  handle_response(response, status)
110
126
  end
@@ -137,7 +153,11 @@ module BeyondApi
137
153
  # @user = session.users.create(body)
138
154
  #
139
155
  def create(body)
140
- response, status = BeyondApi::Request.post(@session, "/users", body)
156
+ path = "/users"
157
+
158
+ response, status = BeyondApi::Request.post(@session,
159
+ path,
160
+ body)
141
161
 
142
162
  handle_response(response, status)
143
163
  end
@@ -158,7 +178,10 @@ module BeyondApi
158
178
  # session.users.enable_support_access
159
179
  #
160
180
  def enable_support_access
161
- response, status = BeyondApi::Request.post(@session, "/users/support")
181
+ path = "/users/support"
182
+
183
+ response, status = BeyondApi::Request.post(@session,
184
+ path)
162
185
 
163
186
  handle_response(response, status, respond_with_true: true)
164
187
  end
@@ -179,7 +202,10 @@ module BeyondApi
179
202
  # session.users.disable_support_access
180
203
  #
181
204
  def disable_support_access
182
- response, status = BeyondApi::Request.delete(@session, "/users/support")
205
+ path = "/users/support"
206
+
207
+ response, status = BeyondApi::Request.delete(@session,
208
+ path)
183
209
 
184
210
  handle_response(response, status, respond_with_true: true)
185
211
  end
@@ -202,7 +228,10 @@ module BeyondApi
202
228
  # @user = session.users.find("e4b528ce-bb9e-4cc5-95e1-7dadfa4cf0f3")
203
229
  #
204
230
  def find(user_id)
205
- response, status = BeyondApi::Request.get(@session, "/users/#{user_id}")
231
+ path = "/users/#{user_id}"
232
+
233
+ response, status = BeyondApi::Request.get(@session,
234
+ path)
206
235
 
207
236
  handle_response(response, status)
208
237
  end
@@ -223,7 +252,10 @@ module BeyondApi
223
252
  # @roles = session.users.roles("0d4bd0a5-94dc-498e-b6a6-305c619bb20d")
224
253
  #
225
254
  def roles(user_id)
226
- response, status = BeyondApi::Request.get(@session, "/users/#{user_id}/roles")
255
+ path = "/users/#{user_id}/roles"
256
+
257
+ response, status = BeyondApi::Request.get(@session,
258
+ path)
227
259
 
228
260
  handle_response(response, status)
229
261
  end
@@ -245,7 +277,11 @@ module BeyondApi
245
277
  # @user = session.users.search_by_username(username)
246
278
  #
247
279
  def search_by_username(username)
248
- response, status = BeyondApi::Request.get(@session, "/users/search/find-by-username", username: username)
280
+ path = "/users/search/find-by-username"
281
+
282
+ response, status = BeyondApi::Request.get(@session,
283
+ path,
284
+ username: username)
249
285
 
250
286
  handle_response(response, status)
251
287
  end
@@ -275,7 +311,12 @@ module BeyondApi
275
311
  # session.users.send_email_address_change(user_id, new_email, current_password, locale)
276
312
  #
277
313
  def send_email_address_change(user_id, new_email, current_password, locale)
278
- response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-email-request", { new_email: new_email, current_password: current_password }, { locale: locale })
314
+ path = "/users/#{user_id}/change-email-request"
315
+
316
+ response, status = BeyondApi::Request.post(@session,
317
+ path,
318
+ { new_email: new_email, current_password: current_password },
319
+ { locale: locale })
279
320
 
280
321
  handle_response(response, status, respond_with_true: true)
281
322
  end
@@ -301,7 +342,12 @@ module BeyondApi
301
342
  # session.users.send_reset_password_email(email, locale)
302
343
  #
303
344
  def send_reset_password_email(email, locale)
304
- response, status = BeyondApi::Request.post(@session, "/users/reset-password-request", { email: email }, { locale: locale })
345
+ path = "/users/reset-password-request"
346
+
347
+ response, status = BeyondApi::Request.post(@session,
348
+ path,
349
+ { email: email },
350
+ { locale: locale })
305
351
 
306
352
  handle_response(response, status, respond_with_true: true)
307
353
  end
@@ -325,7 +371,11 @@ module BeyondApi
325
371
  # session.users.set_roles(user_id, body)
326
372
  #
327
373
  def set_roles(user_id, body)
328
- response, status = BeyondApi::Request.put(@session, "/users/#{user_id}/roles", body)
374
+ path = "/users/#{user_id}/roles"
375
+
376
+ response, status = BeyondApi::Request.put(@session,
377
+ path,
378
+ body)
329
379
 
330
380
  handle_response(response, status, respond_with_true: true)
331
381
  end
@@ -345,7 +395,10 @@ module BeyondApi
345
395
  # session.users.support_access
346
396
  #
347
397
  def support_access
348
- response, status = BeyondApi::Request.get(@session, "/users/support")
398
+ path = "/users/support"
399
+
400
+ response, status = BeyondApi::Request.get(@session,
401
+ path)
349
402
 
350
403
  handle_response(response, status)
351
404
  end
@@ -370,7 +423,12 @@ module BeyondApi
370
423
  # session.users.verify_password(password)
371
424
  #
372
425
  def verify_password(password, user_role)
373
- response, status = BeyondApi::Request.post(@session, "/users/verify-password", password: password, user_role: user_role)
426
+ path = "/users/verify-password"
427
+
428
+ response, status = BeyondApi::Request.post(@session,
429
+ path,
430
+ password: password,
431
+ user_role: user_role)
374
432
 
375
433
  handle_response(response, status, respond_with_true: true)
376
434
  end
@@ -4,7 +4,6 @@ require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
6
  module VariationAvailability
7
-
8
7
  #
9
8
  # A +POST+ request is used to adjust the available stock of a variation.
10
9
  #
@@ -26,7 +25,11 @@ module BeyondApi
26
25
  # @availability = session.variations.adjust_stock_level(product_id, variation_id, { relativeAmount => -1 })
27
26
  #
28
27
  def adjust_stock_level(product_id, variation_id, relative_amount)
29
- response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/variations/#{variation_id}/availability/adjust-available-stock", relative_amount: relative_amount)
28
+ path = "/products/#{product_id}/variations/#{variation_id}/availability/adjust-available-stock"
29
+
30
+ response, status = BeyondApi::Request.post(@session,
31
+ path,
32
+ relative_amount: relative_amount)
30
33
 
31
34
  handle_response(response, status)
32
35
  end
@@ -50,7 +53,10 @@ module BeyondApi
50
53
  # @availability = session.variations.availability("fb22d408-00dc-47e3-ae58-e35769bdb428", "13b28149-975a-4f47-ad54-bdc4ca4a07ec")
51
54
  #
52
55
  def availability(product_id, variation_id)
53
- response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/variations/#{variation_id}/availability")
56
+ path = "/products/#{product_id}/variations/#{variation_id}/availability"
57
+
58
+ response, status = BeyondApi::Request.get(@session,
59
+ path)
54
60
 
55
61
  handle_response(response, status)
56
62
  end
@@ -74,7 +80,10 @@ module BeyondApi
74
80
  # @availability = session.variations.enable_purchaability("1e3a92b-6f3b-4415-bd8f-c9c8921a5a73", "13b28149-975a-4f47-ad54-bdc4ca4a07ec")
75
81
  #
76
82
  def enable_purchasability(product_id, variation_id)
77
- response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/variations/#{variation_id}/availability/enable-purchasability")
83
+ path = "/products/#{product_id}/variations/#{variation_id}/availability/enable-purchasability"
84
+
85
+ response, status = BeyondApi::Request.post(@session,
86
+ path)
78
87
 
79
88
  handle_response(response, status)
80
89
  end
@@ -97,7 +106,10 @@ module BeyondApi
97
106
  # @availability = session.variations.disable_purchasability("17e3a92b-6f3b-4415-bd8f-c9c8921a5a73", "13b28149-975a-4f47-ad54-bdc4ca4a07ec")
98
107
  #
99
108
  def disable_purchasability(product_id, variation_id)
100
- response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/variations/#{variation_id}/availability/disable-purchasability")
109
+ path = "/products/#{product_id}/variations/#{variation_id}/availability/disable-purchasability"
110
+
111
+ response, status = BeyondApi::Request.post(@session,
112
+ path)
101
113
 
102
114
  handle_response(response, status)
103
115
  end
@@ -4,7 +4,6 @@ require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
6
  module VariationImages
7
-
8
7
  #
9
8
  # A +POST+ request is used to create an image and add it to a variation. The URL of the image will be assigned to the variation. The image URL has to be provided in body of the request.
10
9
  #
@@ -35,12 +34,15 @@ module BeyondApi
35
34
  # @image = session.variations.add_image("a08ca814-52e9-4e00-82a2-3e9b012e5f9d", "4b58cdb7-4d3d-419a-ae27-8469f8b04276", body)
36
35
  #
37
36
  def add_image(product_id, variation_id, body)
38
- response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/variations/#{variation_id}/images", body)
39
-
37
+ path = "/products/#{product_id}/variations/#{variation_id}/images"
38
+
39
+ response, status = BeyondApi::Request.post(@session,
40
+ path,
41
+ body)
42
+
40
43
  handle_response(response, status)
41
44
  end
42
45
 
43
-
44
46
  #
45
47
  # A +DELETE+ request is used to delete a variation image
46
48
  #
@@ -61,7 +63,10 @@ module BeyondApi
61
63
  # session.variations.delete_image("8f5736f8-0a5f-4c08-bbac-3c524e2a6294", "86f3047c-ff29-4906-83c1-93e24ef88f3e", "193d2ba4-3cf0-4326-a655-ef46e8a97c6a")
62
64
  #
63
65
  def delete_image(product_id, variation_id, image_id)
64
- response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}")
66
+ path = "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}"
67
+
68
+ response, status = BeyondApi::Request.delete(@session,
69
+ path)
65
70
 
66
71
  handle_response(response, status, respond_with_true: true)
67
72
  end
@@ -86,7 +91,10 @@ module BeyondApi
86
91
  # @image = session.variations.image("8665fc36-003e-4120-8a74-a9d6449644ae", "a9163db42-92e7-418c-a3d8-651e7aaca569", "86fc2691-5dfb-47e1-aae7-4bc2f658a80b")
87
92
  #
88
93
  def image(product_id, image_id)
89
- response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}")
94
+ path = "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}"
95
+
96
+ response, status = BeyondApi::Request.get(@session,
97
+ path)
90
98
 
91
99
  handle_response(response, status)
92
100
  end
@@ -112,7 +120,11 @@ module BeyondApi
112
120
  # @images = session.variations.images("b4948e53-05af-4e0b-8877-28bc8811f73e", "50c5bf45-5dd6-4bae-babf-813c7cdca488", size: 100, page: 0)
113
121
  #
114
122
  def images(product_id, variation_id, params = {})
115
- response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/variations/#{variation_id}/images", params)
123
+ path = "/products/#{product_id}/variations/#{variation_id}/images"
124
+
125
+ response, status = BeyondApi::Request.get(@session,
126
+ path,
127
+ params)
116
128
 
117
129
  handle_response(response, status)
118
130
  end
@@ -142,17 +154,22 @@ module BeyondApi
142
154
  # session.variations.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111", "/home/epages/file.png", "file.png")
143
155
  #
144
156
  def upload_image(product_id, variation_id, image_path, image_name)
157
+ path = "/products/#{product_id}/variations/#{variation_id}/images"
145
158
  content_type = case File.extname(image_path)
146
- when ".png"
147
- "image/png"
148
- when ".jpg", ".jpeg"
149
- "image/jpeg"
150
- when ".gif"
151
- "image/gif"
152
- end
159
+ when ".png"
160
+ "image/png"
161
+ when ".jpg", ".jpeg"
162
+ "image/jpeg"
163
+ when ".gif"
164
+ "image/gif"
165
+ end
153
166
  image_binary = File.binread(image_path)
154
167
 
155
- response, status = BeyondApi::Request.upload(@session, "/products/#{product_id}/variations/#{variation_id}/images", image_binary, content_type, { file_name: image_name })
168
+ response, status = BeyondApi::Request.upload(@session,
169
+ path,
170
+ image_binary,
171
+ content_type,
172
+ { file_name: image_name })
156
173
 
157
174
  handle_response(response, status, respond_with_true: true)
158
175
  end
@@ -29,7 +29,11 @@ module BeyondApi
29
29
  # @variations = session.variations.all("dc1b5caf-51ea-4fcd-b1ba-0c5128e91d17", { size: 100, page: 0 })
30
30
  #
31
31
  def all(product_id, params = {})
32
- response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/variations", params)
32
+ path = "/products/#{product_id}/variations"
33
+
34
+ response, status = BeyondApi::Request.get(@session,
35
+ path,
36
+ params)
33
37
 
34
38
  handle_response(response, status)
35
39
  end
@@ -53,7 +57,10 @@ module BeyondApi
53
57
  # @variation = session.variations.find("5f6e426e-c8d9-48ba-9b37-9a8eb6381373", "f6e5bb16-af2e-440f-acd3-a883ad3c1922")
54
58
  #
55
59
  def find(product_id, variation_id)
56
- response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/variations/#{variation_id}")
60
+ path = "/products/#{product_id}/variations/#{variation_id}"
61
+
62
+ response, status = BeyondApi::Request.get(@session,
63
+ path)
57
64
 
58
65
  handle_response(response, status)
59
66
  end
@@ -143,7 +150,11 @@ module BeyondApi
143
150
  # @variation = session.variations.update("7cf4b5b1-b141-4869-96d1-4eaee8bf7563", "9f93fdd0-2d21-4ea9-b9d7-e9a53edb091b", body)
144
151
  #
145
152
  def update(product_id, variation_id, body)
146
- response, status = BeyondApi::Request.patch(@session, "/products/#{product_id}/variations/#{variation_id}", body)
153
+ path = "/products/#{product_id}/variations/#{variation_id}"
154
+
155
+ response, status = BeyondApi::Request.patch(@session,
156
+ path,
157
+ body)
147
158
 
148
159
  handle_response(response, status)
149
160
  end
@@ -3,7 +3,7 @@
3
3
  require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
- class WebhookSubscriptions < Base # :category: Resources
6
+ class WebhookSubscriptions < Base
7
7
  include BeyondApi::Utils
8
8
 
9
9
  #
@@ -22,7 +22,10 @@ module BeyondApi
22
22
  # session.webhook_subscriptions.activate("268a8629-55cd-4890-9013-936b9b5ea14c")
23
23
  #
24
24
  def activate(webhook_subscription_id)
25
- response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions/#{webhook_subscription_id}/activate")
25
+ path = "/webhook-subscriptions/#{webhook_subscription_id}/activate"
26
+
27
+ response, status = BeyondApi::Request.post(@session,
28
+ path)
26
29
 
27
30
  handle_response(response, status, respond_with_true: true)
28
31
  end
@@ -44,7 +47,9 @@ module BeyondApi
44
47
  # @webhook_subscriptions = session.webhook_subscriptions.all(size: 100, page: 0)
45
48
  #
46
49
  def all(params = {})
47
- handle_all_request("/webhook-subscriptions", :webhook_subscriptions, params)
50
+ path = "/webhook-subscriptions"
51
+
52
+ handle_all_request(path, :webhook_subscriptions, params)
48
53
  end
49
54
 
50
55
  #
@@ -74,7 +79,11 @@ module BeyondApi
74
79
  # @webhook_subscription = session.webhook_subscriptions.create(body)
75
80
  #
76
81
  def create(body)
77
- response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions", body)
82
+ path = "/webhook-subscriptions"
83
+
84
+ response, status = BeyondApi::Request.post(@session,
85
+ path,
86
+ body)
78
87
 
79
88
  handle_response(response, status)
80
89
  end
@@ -93,7 +102,10 @@ module BeyondApi
93
102
  # session.webhook_subscriptions.deactivate("a597cea4-b688-4164-8c56-b6568ea4d5aa")
94
103
  #
95
104
  def deactivate(webhook_subscription_id)
96
- response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions/#{webhook_subscription_id}/deactivate")
105
+ path = "/webhook-subscriptions/#{webhook_subscription_id}/deactivate"
106
+
107
+ response, status = BeyondApi::Request.post(@session,
108
+ path)
97
109
 
98
110
  handle_response(response, status, respond_with_true: true)
99
111
  end
@@ -112,7 +124,10 @@ module BeyondApi
112
124
  # session.webhook_subscriptions.delete("c6076a5a-a8ad-443f-b20b-8a1b268b069e")
113
125
  #
114
126
  def delete(webhook_subscription_id)
115
- response, status = BeyondApi::Request.delete(@session, "/webhook-subscriptions/#{webhook_subscription_id}")
127
+ path = "/webhook-subscriptions/#{webhook_subscription_id}"
128
+
129
+ response, status = BeyondApi::Request.delete(@session,
130
+ path)
116
131
 
117
132
  handle_response(response, status, respond_with_true: true)
118
133
  end
@@ -132,7 +147,10 @@ module BeyondApi
132
147
  # @webhook_subscription = session.webhook_subscriptions.find("3d44ec71-768c-4927-9069-a96a5153e87c")
133
148
  #
134
149
  def find(webhook_subscription_id)
135
- response, status = BeyondApi::Request.get(@session, "/webhook-subscriptions/#{webhook_subscription_id}")
150
+ path = "/webhook-subscriptions/#{webhook_subscription_id}"
151
+
152
+ response, status = BeyondApi::Request.get(@session,
153
+ path)
136
154
 
137
155
  handle_response(response, status)
138
156
  end
@@ -167,7 +185,11 @@ module BeyondApi
167
185
  # @webhook_subscription = session.webhook_subscriptions.update("6f3bc033-c2d1-4f44-80e3-1b668f6bd699", body)
168
186
  #
169
187
  def update(webhook_subscription_id, body)
170
- response, status = BeyondApi::Request.put(@session, "/webhook-subscriptions/#{webhook_subscription_id}", body)
188
+ path = "/webhook-subscriptions/#{webhook_subscription_id}"
189
+
190
+ response, status = BeyondApi::Request.put(@session,
191
+ path,
192
+ body)
171
193
 
172
194
  handle_response(response, status)
173
195
  end
@@ -26,11 +26,17 @@ module BeyondApi
26
26
  autoload :WebhookSubscriptions, "beyond_api/resources/webhook_subscriptions"
27
27
 
28
28
  class Session
29
+ class InvalidUriProtocolError < StandardError; end
30
+
29
31
  attr_reader :api_url
30
32
  attr_accessor :access_token, :refresh_token
31
33
 
32
34
  def initialize(api_url:, access_token: nil, refresh_token: nil)
33
- @api_url = api_url
35
+ raise InvalidUriProtocolError, "Invalid URI protocol" unless api_url.start_with? "https://"
36
+
37
+ uri = URI.parse(api_url)
38
+
39
+ @api_url = "#{uri.scheme}://#{uri.host}/api"
34
40
  @access_token = access_token
35
41
  @refresh_token = refresh_token
36
42
  end