beyond_api 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +4 -0
  7. data/CONTRIBUTING.md +48 -0
  8. data/GETTING_STARTED.md +0 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +55 -0
  11. data/LICENSE +19 -0
  12. data/README.md +51 -0
  13. data/Rakefile +11 -0
  14. data/beyond_api.gemspec +31 -0
  15. data/bin/console +18 -0
  16. data/bin/setup +8 -0
  17. data/lib/beyond_api.rb +37 -0
  18. data/lib/beyond_api/connection.rb +30 -0
  19. data/lib/beyond_api/ext.rb +43 -0
  20. data/lib/beyond_api/request.rb +55 -0
  21. data/lib/beyond_api/resources/base.rb +17 -0
  22. data/lib/beyond_api/resources/carts.rb +547 -0
  23. data/lib/beyond_api/resources/categories.rb +168 -0
  24. data/lib/beyond_api/resources/categories_view.rb +142 -0
  25. data/lib/beyond_api/resources/checkout_settings.rb +48 -0
  26. data/lib/beyond_api/resources/newsletter_target.rb +97 -0
  27. data/lib/beyond_api/resources/order_settings.rb +80 -0
  28. data/lib/beyond_api/resources/orders.rb +968 -0
  29. data/lib/beyond_api/resources/payment_methods.rb +192 -0
  30. data/lib/beyond_api/resources/product_attribute_definitions.rb +109 -0
  31. data/lib/beyond_api/resources/product_settings.rb +28 -0
  32. data/lib/beyond_api/resources/products.rb +245 -0
  33. data/lib/beyond_api/resources/products/attachments.rb +119 -0
  34. data/lib/beyond_api/resources/products/availability.rb +177 -0
  35. data/lib/beyond_api/resources/products/custom_attributes.rb +141 -0
  36. data/lib/beyond_api/resources/products/images.rb +165 -0
  37. data/lib/beyond_api/resources/products/searches.rb +52 -0
  38. data/lib/beyond_api/resources/products/variation_properties.rb +87 -0
  39. data/lib/beyond_api/resources/products_view.rb +158 -0
  40. data/lib/beyond_api/resources/scopes.rb +31 -0
  41. data/lib/beyond_api/resources/script_tags.rb +122 -0
  42. data/lib/beyond_api/resources/shipping_zones.rb +324 -0
  43. data/lib/beyond_api/resources/shop.rb +561 -0
  44. data/lib/beyond_api/resources/signers.rb +63 -0
  45. data/lib/beyond_api/resources/token.rb +41 -0
  46. data/lib/beyond_api/resources/users.rb +376 -0
  47. data/lib/beyond_api/resources/variations.rb +145 -0
  48. data/lib/beyond_api/resources/variations/availability.rb +105 -0
  49. data/lib/beyond_api/resources/webhook_subscriptions.rb +176 -0
  50. data/lib/beyond_api/session.rb +121 -0
  51. data/lib/beyond_api/utils.rb +51 -0
  52. data/lib/beyond_api/version.rb +3 -0
  53. data/lib/generators/beyond_api/install_generator.rb +13 -0
  54. data/lib/generators/templates/beyond_api_initializer.rb +29 -0
  55. metadata +194 -0
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class Signers < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +GET+ request is used to list all signers.
11
+ #
12
+ # $ curl 'https://api-shop.beyondshop.cloud/api/signers' -i -X GET \
13
+ # H 'Accept: application/hal+json' \
14
+ # H 'Authorization: Bearer <Access token>'
15
+ #
16
+ # @return [OpenStruct]
17
+ #
18
+ # @example
19
+ # @signers = session.signers.all
20
+ #
21
+ def all
22
+ response, status = BeyondApi::Request.get(@session, "/signers")
23
+
24
+ handle_response(response, status)
25
+ end
26
+
27
+ #
28
+ # A +POST+ request is used to create a signer. You cannot create more than five signers.
29
+ #
30
+ # $ curl 'https://api-shop.beyondshop.cloud/api/signers' -i -X POST \
31
+ # -H 'Accept: application/hal+json' \
32
+ # -H 'Authorization: Bearer <Access token>'
33
+ #
34
+ # @return [OpenStruct]
35
+ #
36
+ # @example
37
+ # @signers = session.signers.create
38
+ #
39
+ def create
40
+ response, status = BeyondApi::Request.post(@session, "/signers")
41
+
42
+ handle_response(response, status)
43
+ end
44
+
45
+ #
46
+ # A +DELETE+ request is used to delete a signer. If at least one signer has been created, you cannot delete the last signer.
47
+ #
48
+ # $ curl 'https://api-shop.beyondshop.cloud/api/signers/6bb72afd-340e-439a-9990-eef2e0883e1e' -i -X DELETE \
49
+ # -H 'Accept: application/hal+json' \
50
+ # -H 'Authorization: Bearer <Access token>'
51
+ #
52
+ # @return [OpenStruct]
53
+ #
54
+ # @example
55
+ # session.signers.delete("6bb72afd-340e-439a-9990-eef2e0883e1e")
56
+ #
57
+ def delete(signer_id)
58
+ response, status = BeyondApi::Request.delete(@session, "/signers#{signer_id}")
59
+
60
+ handle_response(response, status, respond_with_true: true)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ class Token
5
+ class InvalidSessionError < StandardError; end
6
+
7
+ attr_reader :session
8
+
9
+ def initialize(session)
10
+ @session = session
11
+ raise InvalidSessionError.new("Invalid session") unless session.is_a? BeyondApi::Session
12
+ raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
13
+ end
14
+
15
+ def create(code)
16
+ response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
17
+ grant_type: "authorization_code",
18
+ code: code)
19
+
20
+ if status.between?(200, 299)
21
+ @session.access_token = response["access_token"]
22
+ @session.refresh_token = response["refresh_token"]
23
+ else
24
+ BeyondApi::Error.new(response)
25
+ end
26
+ end
27
+
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
+ if status.between?(200, 299)
34
+ @session.access_token = response["access_token"]
35
+ @session.refresh_token = response["refresh_token"]
36
+ else
37
+ BeyondApi::Error.new(response)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,376 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class Users < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +POST+ request is used to add the roles of a user.
11
+ #
12
+ # @beyond_api.scopes +user:r+, +user:u+
13
+ #
14
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/ac186856-59c4-4d78-a444-8c47ff623525/roles' -i -X POST \
15
+ # -H 'Content-Type: text/uri-list' \
16
+ # -H 'Authorization: Bearer <Access token>' \
17
+ # -d 'https://api-shop.beyondshop.cloud/api/roles/4553f87f-d232-4bf6-8e15-34c373661e82'
18
+ #
19
+ # @param user_id [String] the user UUID
20
+ # @param body [Hash] the request body
21
+ #
22
+ # @return true
23
+ #
24
+ # @example
25
+ # session.users.add_roles(user_id, body)
26
+ #
27
+ def add_roles(user_id, body)
28
+ response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/roles", body)
29
+
30
+ handle_response(response, status, respond_with_true: true)
31
+ end
32
+
33
+ #
34
+ # A +GET+ request is used to list all users visible to the current user. This request will not list the support user.
35
+ #
36
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users' -i -X GET \
37
+ # -H 'Content-Type: application/json' \
38
+ # -H 'Accept: application/hal+json' \
39
+ # -H 'Authorization: Bearer <Access token>'
40
+ #
41
+ # @beyond_api.scopes +user:r+
42
+ #
43
+ # @option params [Integer] :size the page size
44
+ # @option params [Integer] :page the page number
45
+ #
46
+ # @return [OpenStruct]
47
+ #
48
+ # @example
49
+ # session.users.all(params = {})
50
+ #
51
+ def all(params = {})
52
+ response, status = BeyondApi::Request.get(@session, "/users")
53
+
54
+ handle_response(response, status)
55
+ end
56
+
57
+ #
58
+ # A +POST+ request is used to change the password of a user.
59
+ #
60
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/e112b1fe-5f67-4e22-a3c7-a1f6d1891b22/change-password' -i -X POST \
61
+ # -H 'Content-Type: application/json' \
62
+ # -H 'Accept: application/json' \
63
+ # -H 'Authorization: Bearer <Access token>' \
64
+ # -d '{
65
+ # "currentPassword" : "GoodPassword01!;)",
66
+ # "newPassword" : "ValidPassword123"
67
+ # }'
68
+ #
69
+ # @beyond_api.scopes ++
70
+ #
71
+ # @param user_id [String] the user UUID
72
+ # @param current_password [String] the current password
73
+ # @param new_password [String] the new password
74
+ #
75
+ # @return [OpenStruct]
76
+ #
77
+ # @example
78
+ # session.users.change_password(user_id, current_password, new_password)
79
+ #
80
+ def change_password(user_id, current_password, new_password)
81
+ response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-password", current_password: current_password, new_password: new_password)
82
+
83
+ handle_response(response, status)
84
+ end
85
+
86
+ #
87
+ # A +POST+ request is used to change the username of a user.
88
+ #
89
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/ea0ddc0b-e3fb-47c7-9133-e9f5fc0ec442/change-username' -i -X POST \
90
+ # -H 'Content-Type: application/json' \
91
+ # -H 'Accept: application/json' \
92
+ # -H 'Authorization: Bearer <Access token>' \
93
+ # -d '{
94
+ # "currentPassword" : "GoodPassword01!;)",
95
+ # "newUsername" : "new username"
96
+ # }'
97
+ #
98
+ # @beyond_api.scopes ++
99
+ #
100
+ # @param user_id [String] the user UUID
101
+ # @param new_username [String] the new username
102
+ # @param current_password [String] the current password
103
+ #
104
+ # @return [OpenStruct]
105
+ #
106
+ # @example
107
+ # session.users.change_username(user_id, new_username, current_password)
108
+ #
109
+ def change_username(user_id, new_username, current_password)
110
+ response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-username", new_username: new_username, current_password: current_password)
111
+
112
+ handle_response(response, status)
113
+ end
114
+
115
+ #
116
+ # A +POST+ request is used to create a user.
117
+ #
118
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users' -i -X POST \
119
+ # -H 'Content-Type: application/json' \
120
+ # -H 'Accept: application/json' \
121
+ # -H 'Authorization: Bearer <Access token>' \
122
+ # -d '{
123
+ # "username" : "user",
124
+ # "password" : "GoodPassword01!;)",
125
+ # "email" : "baxter@example.org"
126
+ # }'
127
+ #
128
+ # @beyond_api.scopes +user:c+
129
+ #
130
+ # @param body [Hash] the request body
131
+ #
132
+ # @return [OpenStruct]
133
+ #
134
+ # @example
135
+ # session.users.create(body)
136
+ #
137
+ def create(body)
138
+ response, status = BeyondApi::Request.post(@session, "/users", body)
139
+
140
+ handle_response(response, status)
141
+ end
142
+
143
+ #
144
+ # A +POST+ request is used to enable support access for a shop. If enabled, the customer support will receive specific rights for direct support in the merchant’s cockpit.
145
+ #
146
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/support' -i -X POST \
147
+ # -H 'Content-Type: application/json' \
148
+ # -H 'Accept: application/json' \
149
+ # -H 'Authorization: Bearer <Access token>'
150
+ #
151
+ # @beyond_api.scopes +user:c+
152
+ #
153
+ # @return true
154
+ #
155
+ # @example
156
+ # session.users.enable_support_access
157
+ #
158
+ def enable_support_access
159
+ response, status = BeyondApi::Request.post(@session, "/users/support")
160
+
161
+ handle_response(response, status, respond_with_true: true)
162
+ end
163
+
164
+ #
165
+ # A +POST+ request is used to disable support access.
166
+ #
167
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/support' -i -X DELETE \
168
+ # -H 'Content-Type: application/json' \
169
+ # -H 'Accept: application/json' \
170
+ # -H 'Authorization: Bearer <Access token>'
171
+ #
172
+ # @beyond_api.scopes +user:c+
173
+ #
174
+ # @return true
175
+ #
176
+ # @example
177
+ # session.users.disable_support_access
178
+ #
179
+ def disable_support_access
180
+ response, status = BeyondApi::Request.delete(@session, "/users/support")
181
+
182
+ handle_response(response, status, respond_with_true: true)
183
+ end
184
+
185
+ #
186
+ # A +GET+ request is used to retrieve the details of a user.
187
+ #
188
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/e4b528ce-bb9e-4cc5-95e1-7dadfa4cf0f3' -i -X GET \
189
+ # -H 'Content-Type: application/json' \
190
+ # -H 'Accept: application/hal+json' \
191
+ # -H 'Authorization: Bearer <Access token>'
192
+ #
193
+ # @beyond_api.scopes +user:r+
194
+ #
195
+ # @param user_id [String] the user UUID
196
+ #
197
+ # @return [OpenStruct]
198
+ #
199
+ # @example
200
+ # session.users.find(user_id)
201
+ #
202
+ def find(user_id)
203
+ response, status = BeyondApi::Request.get(@session, "/users/#{user_id}")
204
+
205
+ handle_response(response, status)
206
+ end
207
+
208
+ #
209
+ # A +GET+ request is used to list all roles of a user.
210
+ #
211
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/0d4bd0a5-94dc-498e-b6a6-305c619bb20d/roles' -i -X GET \
212
+ # -H 'Authorization: Bearer <Access token>'
213
+ #
214
+ # @beyond_api.scopes +user:r+
215
+ #
216
+ # @param user_id [String] the user UUID
217
+ #
218
+ # @return [OpenStruct]
219
+ #
220
+ # @example
221
+ # session.users.roles(user_id)
222
+ #
223
+ def roles(user_id)
224
+ response, status = BeyondApi::Request.get(@session, "/users/#{user_id}/roles")
225
+
226
+ handle_response(response, status)
227
+ end
228
+
229
+ #
230
+ # A +GET+ request is used to find a user by username.
231
+ #
232
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/search/find-by-username?username=username' -i -X GET \
233
+ # -H 'Accept: application/hal+json' \
234
+ # -H 'Authorization: Bearer <Access token>'
235
+ #
236
+ # @beyond_api.scopes +user:r+
237
+ #
238
+ # @param username [String] the user username
239
+ #
240
+ # @return [OpenStruct]
241
+ #
242
+ # @example
243
+ # session.users.search_by_username(username)
244
+ #
245
+ def search_by_username(username)
246
+ response, status = BeyondApi::Request.get(@session, "/users/search/find-by-username", username: username)
247
+
248
+ handle_response(response, status)
249
+ end
250
+
251
+ #
252
+ # A +POST+ request is used to trigger an email address change. A confirmation email to change the email address will be sent to the user. The confirmation email will contain a link to the email address change page of the merchant’s cockpit. The link includes a JWT to authorize the email address change.
253
+ #
254
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/8f5fd817-0ea1-4550-b4b9-fc437b1b6905/change-email-request?locale=en-US' -i -X POST \
255
+ # -H 'Content-Type: application/json' \
256
+ # -H 'Accept: application/json' \
257
+ # -H 'Authorization: Bearer <Access token>' \
258
+ # -d '{
259
+ # "currentPassword" : "GoodPassword01!;)",
260
+ # "newEmail" : "newEmail@Gmail.com"
261
+ # }'
262
+ #
263
+ # @beyond_api.scopes ++
264
+ #
265
+ # @param user_id [String] the user UUID
266
+ # @param new_email [String] the new email address
267
+ # @param current_password [String] the current password
268
+ # @param locale [String] the email locale
269
+ #
270
+ # @return true
271
+ #
272
+ # @example
273
+ # session.users.send_email_address_change(user_id, new_email, current_password, locale)
274
+ #
275
+ def send_email_address_change(user_id, new_email, current_password, locale)
276
+ response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-email-request", { new_email: new_email, current_password: current_password }, { locale: locale })
277
+
278
+ handle_response(response, status, respond_with_true: true)
279
+ end
280
+
281
+ #
282
+ # A +POST+ request is used to trigger a password reset email to be sent to a user. The email will contain a link to the change password settings page of the merchant’s cockpit. The link includes a JWT to authorize the password reset.
283
+ #
284
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/reset-password-request?locale=en-US' -i -X POST \
285
+ # -H 'Content-Type: application/json' \
286
+ # -H 'Accept: application/json' \
287
+ # -d '{
288
+ # "email" : "customer@host.tld"
289
+ # }'
290
+ #
291
+ # @beyond_api.scopes ++
292
+ #
293
+ # @param email [String] the user email
294
+ # @param locale [String] the email locale
295
+ #
296
+ # @return true
297
+ #
298
+ # @example
299
+ # session.users.send_reset_password_email(email, locale)
300
+ #
301
+ def send_reset_password_email(email, locale)
302
+ response, status = BeyondApi::Request.post(@session, "/users/reset-password-request", { email: email }, { locale: locale })
303
+
304
+ handle_response(response, status, respond_with_true: true)
305
+ end
306
+
307
+ #
308
+ # A +PUT+ request is used set the roles of a user.
309
+ #
310
+ # @beyond_api.scopes +user:u+
311
+ #
312
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/cfd08a92-dc96-4947-8142-1b6021177f60/roles' -i -X PUT \
313
+ # -H 'Content-Type: text/uri-list' \
314
+ # -H 'Authorization: Bearer <Access token>' \
315
+ # -d 'https://api-shop.beyondshop.cloud/api/roles/165fee2b-f87e-4f33-b036-14b8d96d927a'
316
+ #
317
+ # @param user_id [String] the user UUID
318
+ # @param body [Hash] the request body
319
+ #
320
+ # @return true
321
+ #
322
+ # @example
323
+ # session.users.set_roles(user_id, body)
324
+ #
325
+ def set_roles(user_id, body)
326
+ response, status = BeyondApi::Request.put(@session, "/users/#{user_id}/roles", body)
327
+
328
+ handle_response(response, status, respond_with_true: true)
329
+ end
330
+
331
+ #
332
+ # A +GET+ request is used to retrieve the status of the support access for a shop, i.e. if the support user is enabled or disabled for the shop.
333
+ #
334
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/support' -i -X GET \
335
+ # -H 'Accept: application/hal+json' \
336
+ # -H 'Authorization: Bearer <Access token>'
337
+ #
338
+ # @beyond_api.scopes +user:r+
339
+ #
340
+ # @return [OpenStruct]
341
+ #
342
+ # @example
343
+ # session.users.support_access
344
+ #
345
+ def support_access
346
+ response, status = BeyondApi::Request.get(@session, "/users/support")
347
+
348
+ handle_response(response, status)
349
+ end
350
+
351
+ #
352
+ # A +POST+ request is used to verify a password against the password guidelines.
353
+ #
354
+ # $ curl 'https://api-shop.beyondshop.cloud/api/users/verify-password' -i -X POST \
355
+ # -H 'Content-Type: application/json' \
356
+ # -H 'Accept: application/json' \
357
+ # -d '{
358
+ # "password" : "ValidPassword!"
359
+ # }'
360
+ #
361
+ # @beyond_api.scopes ++
362
+ #
363
+ # @param password [String] the password to verify
364
+ #
365
+ # @return true
366
+ #
367
+ # @example
368
+ # session.users.verify_password(password)
369
+ #
370
+ def verify_password(password)
371
+ response, status = BeyondApi::Request.post(@session, "/users/verify-password", password: password)
372
+
373
+ handle_response(response, status, respond_with_true: true)
374
+ end
375
+ end
376
+ end