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,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ class Base
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
+ if session.api_url.nil? || session.access_token.nil? || session.refresh_token.nil?
13
+ raise InvalidSessionError.new("Session api_url, access_token and refresh_token cannot be nil")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,547 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class Carts < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +POST+ request is used to add a line item to the cart. Currently only product line items are supported.
11
+ #
12
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/6d529573-b39e-4cd4-99fe-856432ea97f3/line-items' -i -X POST \
13
+ # -H 'Content-Type: application/json' \
14
+ # -d '{"_type":"PRODUCT","_ref":"c3a52c19-2b43-4ceb-a7ca-00c558aec072","quantity":1}'
15
+ #
16
+ # @param cart_id [String] the cart UUID
17
+ # @param body [Hash] the request body
18
+ #
19
+ # @return [OpenStruct]
20
+ #
21
+ # @example
22
+ # body = {
23
+ # "_type" => "PRODUCT",
24
+ # "_ref" => "c3a52c19-2b43-4ceb-a7ca-00c558aec072",
25
+ # "quantity" => 1
26
+ # }
27
+ # @cart = session.carts.add_line_item("6d529573-b39e-4cd4-99fe-856432ea97f3", body)
28
+ #
29
+ def add_line_item(cart_id, body)
30
+ response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/line-items", body)
31
+
32
+ handle_response(response, status)
33
+ end
34
+
35
+ #
36
+ # A +POST+ request is used to create a cart.
37
+ #
38
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts' -i -X POST \
39
+ # -H 'Accept: application/hal+json'
40
+ #
41
+ # @return [OpenStruct]
42
+ #
43
+ # @example
44
+ # @cart = session.carts.create
45
+ #
46
+ def create(body)
47
+ response, status = BeyondApi::Request.post(@session, "/carts", body)
48
+
49
+ handle_response(response, status)
50
+ end
51
+
52
+ #
53
+ # A +POST+ request is used to initiate the creation of a payment.
54
+ #
55
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/158bdcee-178a-4b5f-88ff-1953f5ea8e09/create-payment' -i -X POST \
56
+ # -H 'Content-Type: application/json' \
57
+ # -H 'Accept: application/hal+json' \
58
+ # -d '{
59
+ # "returnUri" : "http://some.com/return",
60
+ # "cancelUri" : "http://some.com/cancel"
61
+ # }'
62
+ #
63
+ # @param cart_id [String] the cart UUID
64
+ # @param body [Hash] the request body
65
+ #
66
+ # @return [OpenStruct]
67
+ #
68
+ # @example
69
+ # body = {
70
+ # "returnUri" => "http://some.com/return",
71
+ # "cancelUri" => "http://some.com/cancel"
72
+ # }
73
+ # @payment = session.carts.create_payment("158bdcee-178a-4b5f-88ff-1953f5ea8e09/", body)
74
+ #
75
+ def create_payment(cart_id, body)
76
+ response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment", body)
77
+
78
+ handle_response(response, status)
79
+ end
80
+
81
+ #
82
+ # A +POST+ request is used to create an order from a cart and initiate the payment.
83
+ #
84
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/f6c6615b-a9f6-420e-be1d-46339ddc5fda/create-payment-and-order' -i -X POST \
85
+ # -H 'Content-Type: application/json' \
86
+ # -H 'Accept: application/hal+json' \
87
+ # -d '{
88
+ # "returnUri" : "http://some.com/return",
89
+ # "cancelUri" : "http://some.com/cancel",
90
+ # "customerComment" : "Send it fast please!",
91
+ # "salesChannel" : "Storefront",
92
+ # "marketingChannel" : "Google",
93
+ # "marketingSubchannel" : "Search page 2",
94
+ # "testOrder" : false,
95
+ # "termsAndConditionsExplicitlyAccepted" : false
96
+ # }'
97
+ #
98
+ # @param cart_id [String] the cart UUID
99
+ # @param body [Hash] the request body
100
+ #
101
+ # @return [OpenStruct]
102
+ #
103
+ # @example
104
+ # body = {
105
+ # "returnUri" => "http://some.com/return",
106
+ # "cancelUri" => "http://some.com/cancel",
107
+ # "customerComment" => "Send it fast please!",
108
+ # "salesChannel" => "Storefront",
109
+ # "marketingChannel" => "Google",
110
+ # "marketingSubchannel" => "Search page 2",
111
+ # "testOrder" => false,
112
+ # "termsAndConditionsExplicitlyAccepted" => false
113
+ # }
114
+ # @payment = session.carts.create_payment_and_order("f6c6615b-a9f6-420e-be1d-46339ddc5fda", body)
115
+ #
116
+ def create_payment_and_order(cart_id, body)
117
+ response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment-and-order", body)
118
+
119
+ handle_response(response, status)
120
+ end
121
+
122
+ #
123
+ # A +POST+ request is used to create an order from the cart.
124
+ #
125
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/986247da-b78f-422c-a273-917804896974/order' -i -X POST \
126
+ # -H 'Content-Type: application/json' \
127
+ # -d '{"customerComment": "send it fast please",
128
+ # "salesChannel": "DifferentChannel",
129
+ # "marketingChannel": "Google",
130
+ # "marketingSubchannel": "Search page 2",
131
+ # "testOrder": false,
132
+ # "termsAndConditionsExplicitlyAccepted": true
133
+ # }'
134
+ #
135
+ # @param cart_id [String] the cart UUID
136
+ # @param body [Hash] the request body
137
+ #
138
+ # @return [OpenStruct]
139
+ #
140
+ # @example
141
+ # body = {
142
+ # "customerComment" => "send it fast please",
143
+ # "salesChannel" => "DifferentChannel",
144
+ # "marketingChannel" => "Google",
145
+ # "marketingSubchannel" => "Search page 2",
146
+ # "testOrder" => false,
147
+ # "termsAndConditionsExplicitlyAccepted" => true
148
+ # }
149
+ # @order = session.carts.create_order("986247da-b78f-422c-a273-917804896974", body)
150
+ #
151
+ def create_order(cart_id, body)
152
+ response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/order", body)
153
+
154
+ handle_response(response, status)
155
+ end
156
+
157
+ #
158
+ # A +DELETE+ request is used to delete a cart.
159
+ #
160
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/1a58f22f-481a-4993-9947-62c1c2857f87' -i -X DELETE
161
+ #
162
+ # @param cart_id [String] the cart UUID
163
+ #
164
+ # @return true
165
+ #
166
+ # @example
167
+ # session.carts.delete("1a58f22f-481a-4993-9947-62c1c2857f87")
168
+ #
169
+ def delete(cart_id)
170
+ response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}")
171
+
172
+ handle_response(response, status, respond_with_true: true)
173
+ end
174
+
175
+ #
176
+ # A +DELETE+ request is used to delete a line item from the cart.
177
+ #
178
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/3fb55475-f6d2-471a-90ac-ccee7896b9f7/line-items/51c86195-d2b9-4073-9a14-7ddd5a76b6a7' -i -X DELETE
179
+ #
180
+ # @param cart_id [String] the cart UUID
181
+ # @param line_item_id [String] the line item UUID
182
+ #
183
+ # @return true
184
+ #
185
+ # @example
186
+ # @cart = session.carts.delete_line_item("3fb55475-f6d2-471a-90ac-ccee7896b9f7", "51c86195-d2b9-4073-9a14-7ddd5a76b6a7")
187
+ #
188
+ def delete_line_item(cart_id, line_item_id)
189
+ response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/line-items/#{line_item_id}")
190
+
191
+ handle_response(response, status, respond_with_true: true)
192
+ end
193
+
194
+ #
195
+ # A +DELETE+ request is used to remove the shipping address of the cart. After deletion, the shipping address will default to the billing address.
196
+ #
197
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/2fa7dc36-8305-4628-b961-f2c3f7dda47d/shipping-address' -i -X DELETE \
198
+ # -H 'Accept: application/hal+json'
199
+ #
200
+ # @param cart_id [String] the cart UUID
201
+ #
202
+ # @return true
203
+ #
204
+ # @example
205
+ # session.carts.delete_line_item("2fa7dc36-8305-4628-b961-f2c3f7dda47d")
206
+ #
207
+ def delete_shipping_address(cart_id)
208
+ response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/shipping-address")
209
+
210
+ handle_response(response, status, respond_with_true: true)
211
+ end
212
+
213
+ #
214
+ # A +GET+ request is used to retrieve the details of a cart.
215
+ #
216
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/26857145-aeab-4210-9191-3906573a14ae' -i -X GET \
217
+ # -H 'Content-Type: application/json' \
218
+ # -H 'Accept: application/hal+json'
219
+ #
220
+ # @param cart_id [String] the cart UUID
221
+ #
222
+ # @return [OpenStruct]
223
+ #
224
+ # @example
225
+ # @cart = session.carts.find("26857145-aeab-4210-9191-3906573a14ae")
226
+ #
227
+ def find(cart_id)
228
+ response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")
229
+
230
+ handle_response(response, status)
231
+ end
232
+
233
+ #
234
+ # A +GET+ request is used to retrieve the current payment method.
235
+ #
236
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/6d9de289-d6a7-44d6-afb3-c31bb0a792ff/payment-methods/current' -i -X GET \
237
+ # -H 'Content-Type: application/json' \
238
+ # -H 'Accept: application/hal+json'
239
+ # @param cart_id [String] the cart UUID
240
+ #
241
+ # @return [OpenStruct]
242
+ #
243
+ # @example
244
+ # @payment_method = session.carts.payment_method("26857145-aeab-4210-9191-3906573a14ae")
245
+ #
246
+ def payment_method(cart_id)
247
+ response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods/current")
248
+
249
+ handle_response(response, status)
250
+ end
251
+
252
+ #
253
+ # A +GET+ request is used to get the applicable payment methods of a cart.
254
+ # The selectable field indicates if a payment method is currently selectable. Non-selectable payment methods are currently restricted because of rules that apply to a cart.
255
+ # Trying to set such a payment method as the current one of the cart will fail.
256
+ #
257
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/45f9009d-4d2f-43b1-9cd2-ea29ff0d46d6/payment-methods' -i -X GET \
258
+ # -H 'Content-Type: application/json' \
259
+ # -H 'Accept: application/hal+json'
260
+ #
261
+ # @param cart_id [String] the cart UUID
262
+ #
263
+ # @return [OpenStruct]
264
+ #
265
+ # @example
266
+ # @payment_methods = session.carts.payment_methods("45f9009d-4d2f-43b1-9cd2-ea29ff0d46d6")
267
+ #
268
+ def payment_methods(cart_id)
269
+ response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods")
270
+
271
+ handle_response(response, status)
272
+ end
273
+
274
+ #
275
+ # A +PUT+ request is used to replace only one line item in the cart.
276
+ #
277
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/f73629e5-fecf-4474-9b04-6b2fcd4663c4/line-items/2c9c0f38-0b9e-4fa7-bcbe-960098ff63aa' -i -X PUT \
278
+ # -H 'Content-Type: application/json' \
279
+ # -d '{"_type":"PRODUCT","_ref":"f084553c-ea77-4745-b1bd-71c64c8419fd","quantity":2}'
280
+ #
281
+ # @param cart_id [String] the cart UUID
282
+ # @param line_item_id [String] the line item UUID
283
+ # @param body [Hash] the request body
284
+ #
285
+ # @return [OpenStruct]
286
+ #
287
+ # @example
288
+ # body = {
289
+ # "_type" => "PRODUCT",
290
+ # "_ref" => "f084553c-ea77-4745-b1bd-71c64c8419fd",
291
+ # "quantity" => 2
292
+ # }
293
+ # @cart = session.carts.replace_line_item("f73629e5-fecf-4474-9b04-6b2fcd4663c4", "2c9c0f38-0b9e-4fa7-bcbe-960098ff63aa", body)
294
+ #
295
+ def replace_line_item(cart_id, line_item_id, body)
296
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items/#{line_item_id}", body)
297
+
298
+ handle_response(response, status)
299
+ end
300
+
301
+ #
302
+ # A +PUT+ request is used to replace the current line items in the cart with the given list.
303
+ #
304
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/c1436110-e283-49b3-a748-0321efec6d35/line-items' -i -X PUT \
305
+ # -H 'Content-Type: application/json' \
306
+ # -d '[{"_type":"PRODUCT","_ref":"0612362d-9856-4b40-94c6-a36abec0cf8c","quantity":1}]'
307
+ #
308
+ # @param cart_id [String] the cart UUID
309
+ # @param body [String] the array of line items
310
+ #
311
+ # @return [OpenStruct]
312
+ #
313
+ # @example
314
+ # body = [{"_type":"PRODUCT","_ref":"0612362d-9856-4b40-94c6-a36abec0cf8c","quantity":1}]
315
+ # @cart = session.carts.replace_line_item("c1436110-e283-49b3-a748-0321efec6d35", body)
316
+ #
317
+ def replace_line_items(cart_id, body)
318
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items", body)
319
+
320
+ handle_response(response, status)
321
+ end
322
+
323
+ #
324
+ # A +PUT+ request is used to set the billing address of the cart. The billing address is mandatory for a cart being ready to order.
325
+ #
326
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/01da6aa7-8aa2-4383-a496-6611a14afbc9/billing-address' -i -X PUT \
327
+ # -H 'Content-Type: application/json' \
328
+ # -H 'Accept: application/hal+json' \
329
+ # -d '{"salutation":"Mrs","gender":"FEMALE","title":"","firstName":"Astrid","middleName":"Agnes","lastName":"Alster","street":"Alsterwasserweg",
330
+ # "houseNumber":"2","street2":"Erdgeschoss","doorCode":"0185","addressExtension":"Hinterhof","postalCode":"20999","dependentLocality":"Seevetal",
331
+ # "city":"Alsterwasser","country":"DE","state":"Hamburg","email":"a.alsterh@example.com","phone":"(800) 555-0102","mobile":"(800) 555-0103",
332
+ # "vatId":"123456789","taxNumber":"123-34-6789","birthDate":"1985-03-20"}'
333
+ #
334
+ # @param cart_id [String] the cart UUID
335
+ # @param body [Hash] the request body
336
+ #
337
+ # @return [OpenStruct]
338
+ #
339
+ # @example
340
+ # body = {
341
+ # "salutation" => "Mrs",
342
+ # "gender" => "FEMALE",
343
+ # "title" => "",
344
+ # "firstName" => "Astrid",
345
+ # "middleName" => "Agnes",
346
+ # "lastName" => "Alster",
347
+ # "street" => "Alsterwasserweg",
348
+ # "houseNumber" => "2",
349
+ # "street2" => "Erdgeschoss",
350
+ # "doorCode" => "0185",
351
+ # "addressExtension" => "Hinterhof",
352
+ # "postalCode" => "20999",
353
+ # "dependentLocality" => "Seevetal",
354
+ # "city" => "Alsterwasser",
355
+ # "country" => "DE",
356
+ # "state" => "Hamburg",
357
+ # "email" => "a.alsterh@example.com",
358
+ # "phone" => "(800) 555-0102",
359
+ # "mobile" => "(800) 555-0103",
360
+ # "vatId" => "123456789",
361
+ # "taxNumber" => "123-34-6789",
362
+ # "birthDate" => "1985-03-20"
363
+ # }
364
+ # @cart = session.carts.set_billing_address("01da6aa7-8aa2-4383-a496-6611a14afbc9", body)
365
+ #
366
+ def set_billing_address(cart_id, body)
367
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/billing-address", body)
368
+
369
+ handle_response(response, status)
370
+ end
371
+
372
+ #
373
+ # A +PUT+ request is used to set the current payment method of the cart.
374
+ #
375
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/750c8a68-ef58-4955-b05f-29e35fa19687/payment-methods/current' -i -X PUT \
376
+ # -H 'Content-Type: text/uri-list' \
377
+ # -H 'Accept: application/json' \
378
+ # -d 'https://api-shop.beyondshop.cloud/api/payment-methods/6498f339-7fe6-43d4-8e2a-6da68d7cdfe3'
379
+ #
380
+ # @param cart_id [String] the cart UUID
381
+ # @param payment_method_id [String] the payment method UUID
382
+ #
383
+ # @return [OpenStruct]
384
+ #
385
+ # @example
386
+ # @cart = session.carts.set_payment_method("750c8a68-ef58-4955-b05f-29e35fa19687", "6498f339-7fe6-43d4-8e2a-6da68d7cdfe3")
387
+ #
388
+ def set_payment_method(cart_id, payment_method_id)
389
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/current",
390
+ "#{@session.api_url}/payment-methods/#{payment_method_id}")
391
+
392
+ handle_response(response, status)
393
+ end
394
+
395
+ #
396
+ # A +PUT+ request is used to set the payment method to the current default payment method. The default payment method is the one with the highest priority of the applicable payment methods.
397
+ #
398
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/d1efcb74-ab96-43c5-b404-9c1f927dc3d2/payment-methods/default' -i -X PUT \
399
+ # -H 'Content-Type: application/json' \
400
+ # -H 'Accept: application/json'
401
+ #
402
+ # @param cart_id [String] the cart UUID
403
+ #
404
+ # @return [OpenStruct]
405
+ #
406
+ # @example
407
+ # @cart = session.carts.set_payment_method_to_default("d1efcb74-ab96-43c5-b404-9c1f927dc3d2")
408
+ #
409
+ def set_payment_method_to_default(cart_id)
410
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/default")
411
+
412
+ handle_response(response, status)
413
+ end
414
+
415
+ #
416
+ # A +PUT+ request is used to set the shipping address of the cart. If a shipping address is not set, it will default to the billing address.
417
+ #
418
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/01da6aa7-8aa2-4383-a496-6611a14afbc9/shipping-address' -i -X PUT \
419
+ # -H 'Content-Type: application/json' \
420
+ # -H 'Accept: application/hal+json' \
421
+ # -d '{"salutation":"Mrs","gender":"FEMALE","title":"","firstName":"Astrid","middleName":"Agnes","lastName":"Alster","street":"Alsterwasserweg",
422
+ # "houseNumber":"2","street2":"Erdgeschoss","doorCode":"0185","addressExtension":"Hinterhof","postalCode":"20999","dependentLocality":"Seevetal",
423
+ # "city":"Alsterwasser","country":"DE","state":"Hamburg","email":"a.alsterh@example.com","phone":"(800) 555-0102","mobile":"(800) 555-0103",
424
+ # "vatId":"123456789","taxNumber":"123-34-6789","birthDate":"1985-03-20"}'
425
+ #
426
+ # @param cart_id [String] the cart UUID
427
+ # @param body [Hash] the request body
428
+ #
429
+ # @return [OpenStruct]
430
+ #
431
+ # @example
432
+ # body = {
433
+ # "salutation" => "Mrs",
434
+ # "gender" => "FEMALE",
435
+ # "title" => "",
436
+ # "firstName" => "Astrid",
437
+ # "middleName" => "Agnes",
438
+ # "lastName" => "Alster",
439
+ # "street" => "Alsterwasserweg",
440
+ # "houseNumber" => "2",
441
+ # "street2" => "Erdgeschoss",
442
+ # "doorCode" => "0185",
443
+ # "addressExtension" => "Hinterhof",
444
+ # "postalCode" => "20999",
445
+ # "dependentLocality" => "Seevetal",
446
+ # "city" => "Alsterwasser",
447
+ # "country" => "DE",
448
+ # "state" => "Hamburg",
449
+ # "email" => "a.alsterh@example.com",
450
+ # "phone" => "(800) 555-0102",
451
+ # "mobile" => "(800) 555-0103",
452
+ # "vatId" => "123456789",
453
+ # "taxNumber" => "123-34-6789",
454
+ # "birthDate" => "1985-03-20"
455
+ # }
456
+ # @cart = session.carts.set_shipping_address("01da6aa7-8aa2-4383-a496-6611a14afbc9", body)
457
+ #
458
+ def set_shipping_address(cart_id, body)
459
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-address", body)
460
+
461
+ handle_response(response, status)
462
+ end
463
+
464
+ #
465
+ # A +PUT+ request is used to set the current shipping method of the cart.
466
+ #
467
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba/shipping-methods/current' -i -X PUT \
468
+ # -H 'Content-Type: text/uri-list' \
469
+ # -H 'Accept: application/json' \
470
+ # -d 'https://api-shop.beyondshop.cloud/api/shipping-zones/59e26c99-ef1d-4ee8-a79f-d078cd6dfe24/shipping-methods/f3d3ce8d-eeab-44b6-81bb-67a4f1d7a57f'
471
+ #
472
+ # @param cart_id [String] the cart UUID
473
+ # @param shipping_zone_id [String] the shipping zone UUID
474
+ # @param shipping_method_id [String] the shipping method UUID
475
+ #
476
+ # @return [OpenStruct]
477
+ #
478
+ # @example
479
+ # @cart = session.carts.set_shipping_method("a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba", "59e26c99-ef1d-4ee8-a79f-d078cd6dfe24", "f3d3ce8d-eeab-44b6-81bb-67a4f1d7a57f")
480
+ #
481
+ def set_shipping_method(cart_id, shipping_zone_id, shipping_method_id)
482
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
483
+ "#{session.api_url}/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")
484
+
485
+ handle_response(response, status)
486
+ end
487
+
488
+ #
489
+ # A +PUT+ request is used to set the shipping method to the current default shipping method.
490
+ # The default shipping method is the one with the highest priority of the applicable shipping methods.
491
+ #
492
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/64efe22b-2699-4032-a2c9-c94a2e4fa425/shipping-methods/default' -i -X PUT \
493
+ # -H 'Content-Type: application/json' \
494
+ # -H 'Accept: application/json'
495
+ #
496
+ # @param cart_id [String] the cart UUID
497
+ #
498
+ # @return [OpenStruct]
499
+ #
500
+ # @example
501
+ # @cart = session.carts.set_shipping_method_to_default("a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba")
502
+ #
503
+ def set_shipping_method_to_default(cart_id)
504
+ response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
505
+ "#{session.api_url}/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")
506
+
507
+ handle_response(response, status)
508
+ end
509
+
510
+ #
511
+ # A +GET+ request is used to get the current shipping method.
512
+ #
513
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/9093a339-66fd-4cc1-9dcf-d23003c38b41/shipping-methods/current' -i -X GET \
514
+ # -H 'Content-Type: application/json' \
515
+ # -H 'Accept: application/hal+json'
516
+ #
517
+ # @param cart_id [String] the cart UUID
518
+ #
519
+ # @return [OpenStruct]
520
+ #
521
+ # @example
522
+ # @shipping_method = session.carts.shipping_method("9093a339-66fd-4cc1-9dcf-d23003c38b41")
523
+ #
524
+ def shipping_method(cart_id)
525
+ response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")
526
+ handle_response(response, status)
527
+ end
528
+
529
+ # A +GET+ request is used to get the applicable shipping method of a cart.
530
+ #
531
+ # $ curl 'https://api-shop.beyondshop.cloud/api/carts/05a547a0-80dc-4a8c-b9b6-aa028b6ef7d8/shipping-methods' -i -X GET \
532
+ # -H 'Content-Type: application/json' \
533
+ # -H 'Accept: application/hal+json'
534
+ #
535
+ # @param cart_id [String] the cart UUID
536
+ #
537
+ # @return [OpenStruct]
538
+ #
539
+ # @example
540
+ # @cart = session.carts.shipping_methods("05a547a0-80dc-4a8c-b9b6-aa028b6ef7d8")
541
+ #
542
+ def shipping_methods(cart_id)
543
+ response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")
544
+ handle_response(response, status)
545
+ end
546
+ end
547
+ end