beyond_api 0.18.0.pre → 0.21.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.template +3 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -8
- data/Rakefile +4 -2
- data/beyond_api.gemspec +13 -9
- data/bin/console +2 -1
- data/lib/beyond_api/connection.rb +17 -6
- data/lib/beyond_api/error.rb +6 -6
- data/lib/beyond_api/ext.rb +16 -16
- data/lib/beyond_api/request.rb +25 -6
- data/lib/beyond_api/resources/carts.rb +52 -23
- data/lib/beyond_api/resources/categories_view.rb +16 -6
- data/lib/beyond_api/resources/newsletter_target.rb +10 -4
- data/lib/beyond_api/resources/orders.rb +152 -33
- data/lib/beyond_api/resources/payment_method_definitions.rb +11 -4
- data/lib/beyond_api/resources/product_attribute_definitions.rb +16 -4
- data/lib/beyond_api/resources/products/attachments.rb +0 -2
- data/lib/beyond_api/resources/products/availability.rb +20 -11
- data/lib/beyond_api/resources/products/cross_sells.rb +0 -1
- data/lib/beyond_api/resources/products/custom_attributes.rb +0 -1
- data/lib/beyond_api/resources/products/images.rb +36 -11
- data/lib/beyond_api/resources/products/searches.rb +62 -1
- data/lib/beyond_api/resources/products/variation_properties.rb +0 -1
- data/lib/beyond_api/resources/products/videos.rb +4 -3
- data/lib/beyond_api/resources/products.rb +28 -9
- data/lib/beyond_api/resources/products_view.rb +21 -5
- data/lib/beyond_api/resources/script_tags.rb +21 -5
- data/lib/beyond_api/resources/shipping_zones.rb +53 -12
- data/lib/beyond_api/resources/shop.rb +9 -2
- data/lib/beyond_api/resources/shops/address.rb +0 -1
- data/lib/beyond_api/resources/shops/attributes.rb +0 -1
- data/lib/beyond_api/resources/shops/images.rb +12 -9
- data/lib/beyond_api/resources/shops/legals.rb +14 -7
- data/lib/beyond_api/resources/shops/locations.rb +0 -1
- data/lib/beyond_api/resources/signers.rb +12 -3
- data/lib/beyond_api/resources/token.rb +6 -5
- data/lib/beyond_api/resources/users.rb +73 -15
- data/lib/beyond_api/resources/variations/availability.rb +17 -5
- data/lib/beyond_api/resources/variations/images.rb +92 -18
- data/lib/beyond_api/resources/variations.rb +14 -3
- data/lib/beyond_api/resources/webhook_subscriptions.rb +30 -8
- data/lib/beyond_api/session.rb +7 -1
- data/lib/beyond_api/utils.rb +55 -42
- data/lib/beyond_api/version.rb +3 -1
- data/lib/beyond_api.rb +3 -1
- data/lib/generators/beyond_api/install_generator.rb +1 -1
- metadata +61 -17
@@ -19,7 +19,10 @@ module BeyondApi
|
|
19
19
|
# @signers = session.signers.all
|
20
20
|
#
|
21
21
|
def all
|
22
|
-
|
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
|
-
|
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
|
-
|
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,8 +13,8 @@ module BeyondApi
|
|
13
13
|
def initialize(session)
|
14
14
|
@session = session
|
15
15
|
|
16
|
-
raise InvalidSessionError
|
17
|
-
raise InvalidSessionError
|
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
20
|
def authorization_code(code)
|
@@ -29,15 +29,16 @@ module BeyondApi
|
|
29
29
|
handle_token_call("client_credentials")
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
alias refresh refresh_token
|
33
|
+
alias create authorization_code
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def handle_token_call(grant_type, params = {})
|
38
|
+
path = "#{@session.api_url}/oauth/token"
|
38
39
|
params.merge!(grant_type: grant_type)
|
39
40
|
|
40
|
-
response, status = BeyondApi::Request.token(
|
41
|
+
response, status = BeyondApi::Request.token(path,
|
41
42
|
params)
|
42
43
|
|
43
44
|
handle_response(response, status)
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,11 +120,47 @@ 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
|
-
|
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
|
119
131
|
|
132
|
+
# A +PUT+ request is used to sort the variation images. This is done by passing the self-links of the images to the desired variation. The request must contain URIs for all images of the given page.
|
133
|
+
#
|
134
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images' -i -X PUT \
|
135
|
+
# -H 'Content-Type: text/uri-list' \
|
136
|
+
# -H 'Authorization: Bearer <Access token>' \
|
137
|
+
# -d 'https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/a12cae49-3efb-4874-989e-37df6981a4db
|
138
|
+
# https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/4f562165-968c-42fd-a245-1dcc045f8151
|
139
|
+
# https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/93cd0802-15db-4772-b524-e1c4c6c27b77'
|
140
|
+
#
|
141
|
+
# @beyond_api.scopes +prod:u+
|
142
|
+
#
|
143
|
+
# @param product_id [String] the product UUID
|
144
|
+
# @param variation_id [String] the variation UUID
|
145
|
+
# @param images [Array] the image UUIDS
|
146
|
+
#
|
147
|
+
# @return true
|
148
|
+
#
|
149
|
+
# @example
|
150
|
+
# body = [
|
151
|
+
# "c9082802-a0d0-416e-9039-02fa465a027e",
|
152
|
+
# "78e9993d-8db3-45d8-8f76-6b8f2aea9c45",
|
153
|
+
# "9233ee97-5dbb-4c00-a7b2-e1512c69a938"
|
154
|
+
# ]
|
155
|
+
# session.variations.sort_images("3f4b2b56-c22d-4d80-b4ed-d5b33ed161eb", body)
|
156
|
+
#
|
157
|
+
def sort_images(product_id, variation_id, image_ids)
|
158
|
+
body = image_ids.map { |image_id| "#{@session.api_url}/products/#{product_id}/variations/#{variation_id}/images/#{image_id}" }
|
159
|
+
response, status = BeyondApi::Request.put(@session, "/products/#{product_id}/variations/#{variation_id}/images", body.join("\n"), {}, 'text/uri-list')
|
160
|
+
|
161
|
+
handle_response(response, status, respond_with_true: true)
|
162
|
+
end
|
163
|
+
|
120
164
|
#
|
121
165
|
# A +POST+ request is used to upload an image to the image storage and assign the URL of the image to the variation. The body of the request must contain the content of the image.
|
122
166
|
#
|
@@ -128,8 +172,8 @@ module BeyondApi
|
|
128
172
|
#
|
129
173
|
# @param product_id [String] the product UUID
|
130
174
|
# @param variation_id [String] the variation UUID
|
131
|
-
# @param
|
132
|
-
# @param
|
175
|
+
# @param images_path [Array] the images path
|
176
|
+
# @param images_name [Array] the images name
|
133
177
|
#
|
134
178
|
# @return [OpenStruct]
|
135
179
|
#
|
@@ -142,19 +186,49 @@ module BeyondApi
|
|
142
186
|
# session.variations.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111", "/home/epages/file.png", "file.png")
|
143
187
|
#
|
144
188
|
def upload_image(product_id, variation_id, image_path, image_name)
|
145
|
-
content_type =
|
146
|
-
|
147
|
-
|
148
|
-
when ".jpg", ".jpeg"
|
149
|
-
"image/jpeg"
|
150
|
-
when ".gif"
|
151
|
-
"image/gif"
|
152
|
-
end
|
189
|
+
content_type = file_content_type(image_path)
|
190
|
+
path = "/products/#{product_id}/variations/#{variation_id}/images"
|
191
|
+
|
153
192
|
image_binary = File.binread(image_path)
|
154
193
|
|
155
|
-
response, status = BeyondApi::Request.upload(@session,
|
194
|
+
response, status = BeyondApi::Request.upload(@session,
|
195
|
+
path,
|
196
|
+
image_binary,
|
197
|
+
content_type,
|
198
|
+
{ file_name: image_name })
|
156
199
|
|
157
200
|
handle_response(response, status, respond_with_true: true)
|
158
201
|
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# A +POST+ request is used to upload up to 10 images to the image storage and assign the URL of the images to up to 30 variations. The body of the request must contain the content of the images.
|
205
|
+
#
|
206
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/variations/images?fileName=file.png&fileName=file2.png&variation=ca53ae26-e7c6-44a4-8070-9fca08cc87ed&variation=ab63fa3a-c2ac-4074-aaa3-b547217b042d' -i -X POST \
|
207
|
+
# -H 'Content-Type: multipart/form-data' \
|
208
|
+
# -H 'Authorization: Bearer <Access token>' \
|
209
|
+
# -F 'image=@/home/epages/file.png' \
|
210
|
+
# -F 'image=@/home/epages/file2.png'
|
211
|
+
#
|
212
|
+
# @beyond_api.scopes +prod:u+
|
213
|
+
#
|
214
|
+
# @param product_id [String] the product UUID
|
215
|
+
# @param variation_id [String] the variation UUID
|
216
|
+
# @param images_path [String] the image path
|
217
|
+
# @param images_name [String] the image name
|
218
|
+
#
|
219
|
+
# @return [OpenStruct]
|
220
|
+
#
|
221
|
+
# @example
|
222
|
+
# session.variations.upload_multiple_images("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111",
|
223
|
+
# ["/home/epages/file.png", "/home/epages/file2.png"], ["file.png", "file2.png"])
|
224
|
+
#
|
225
|
+
def upload_multiple_images(product_id, variation_id, images_path, images_name)
|
226
|
+
response, status = BeyondApi::Request.upload_by_form(@session,
|
227
|
+
"/products/#{product_id}/variations/#{variation_id}/images",
|
228
|
+
images_path,
|
229
|
+
file_name: images_name)
|
230
|
+
|
231
|
+
handle_response(response, status)
|
232
|
+
end
|
159
233
|
end
|
160
234
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/beyond_api/session.rb
CHANGED
@@ -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
|
-
|
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
|