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,324 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class ShippingZones < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +GET+ request is used to list all shipping zones in a paged way.
11
+ #
12
+ # @beyond_api.scopes +shpz:r+
13
+ #
14
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X GET \
15
+ # -H 'Authorization: Bearer <Access token>'
16
+ #
17
+ # @option params [Integer] :size the page size
18
+ # @option params [Integer] :page the page number
19
+ #
20
+ # @return [OpenStruct]
21
+ #
22
+ # @example
23
+ # @shipping_zones = session.shipping_zones.all(size: 20, page: 0)
24
+ #
25
+ def all(params = {})
26
+ response, status = BeyondApi::Request.get(@session, "/shipping-zones", params)
27
+
28
+ handle_response(response, status)
29
+ end
30
+
31
+ #
32
+ # A +POST+ request is used to create a shipping zone.
33
+ #
34
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X POST \
35
+ # -H 'Content-Type: application/json' \
36
+ # -H 'Authorization: Bearer <Access token>' \
37
+ # -d '{
38
+ # "name" : "BE-NL-LU",
39
+ # "serviceableCountries" : [ "BE", "NL", "LU" ]
40
+ # }'
41
+ #
42
+ # @beyond_api.scopes +shpz:c+
43
+ #
44
+ # @param body [Hash] the request body
45
+ #
46
+ # @return [OpenStruct]
47
+ #
48
+ # @example
49
+ # body = {
50
+ # "name" => "BE-NL-LU",
51
+ # "serviceableCountries" => [ "BE", "NL", "LU" ]
52
+ # }
53
+ # @shipping_zone = session.shipping_zones.create(body)
54
+ #
55
+ def create(body)
56
+ response, status = BeyondApi::Request.post(@session, "/shipping-zones", body)
57
+
58
+ handle_response(response, status)
59
+ end
60
+
61
+ #
62
+ # A +POST+ request is used to create a shipping method in a shipping zone.
63
+ #
64
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/905e981c-1489-45af-9138-0a7dc1f0b085/shipping-methods' -i -X POST \
65
+ # -H 'Content-Type: application/json' \
66
+ # -H 'Authorization: Bearer <Access token>' \
67
+ # -d '{
68
+ # "name" : "Standard Shipping 2",
69
+ # "description" : "Standard Shipping",
70
+ # "taxClass" : "REGULAR",
71
+ # "freeShippingValue" : {
72
+ # "taxModel" : "GROSS",
73
+ # "currency" : "EUR",
74
+ # "amount" : 400
75
+ # },
76
+ # "fixedPrice" : {
77
+ # "taxModel" : "GROSS",
78
+ # "currency" : "EUR",
79
+ # "amount" : "19.99"
80
+ # }
81
+ # }'
82
+ #
83
+ # @beyond_api.scopes +shpz:u+
84
+ #
85
+ # @param shipping_zone_id [String] the shipping zone UUID
86
+ # @param body [Hash] the request body
87
+ #
88
+ # @return [OpenStruct]
89
+ #
90
+ # @example
91
+ # body = {
92
+ # "name" => "Standard Shipping 2",
93
+ # "description" => "Standard Shipping",
94
+ # "taxClass" => "REGULAR",
95
+ # "freeShippingValue" => {
96
+ # "taxModel" => "GROSS",
97
+ # "currency" => "EUR",
98
+ # "amount" => 400
99
+ # },
100
+ # "fixedPrice" => {
101
+ # "taxModel" => "GROSS",
102
+ # "currency" => "EUR",
103
+ # "amount" => "19.99"
104
+ # }
105
+ # }
106
+ # @shipping_zone = session.shipping_zones.create("905e981c-1489-45af-9138-0a7dc1f0b085", body)
107
+ #
108
+ def create_shipping_method(shipping_zone_id, body)
109
+ response, status = BeyondApi::Request.post(@session, "/shipping-zones/#{shipping_zone_id}/shipping-methods", body)
110
+
111
+ handle_response(response, status)
112
+ end
113
+
114
+ #
115
+ # A +DELETE+ request is used to delete a shipping zone. You cannot delete the shipping zone if it contains the last shipping method of a shop.
116
+ #
117
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/c871b402-b6d9-4c6d-b76c-440f61175805' -i -X DELETE \
118
+ # -H 'Authorization: Bearer <Access token>'
119
+ #
120
+ # @beyond_api.scopes +shpz:d+
121
+ #
122
+ # @param shipping_zone_id [String] the shipping zone UUID
123
+ #
124
+ # @return true
125
+ #
126
+ # @example
127
+ # session.shipping_zones.delete("c871b402-b6d9-4c6d-b76c-440f61175805")
128
+ #
129
+ def delete(shipping_zone_id)
130
+ response, status = BeyondApi::Request.delete(@session, "/shipping-zones/#{shipping_zone_id}")
131
+
132
+ handle_response(response, status, respond_with_true: true)
133
+ end
134
+
135
+ #
136
+ # A +DELETE+ request is used to delete a shipping method in a shipping zone. You cannot delete the last shipping method of a shop.
137
+ #
138
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/61c14c3c-ce26-4524-9713-f2ede7ff22fa/shipping-methods/d2eee203-a1c6-4035-8e7a-74bb77cfde47' -i -X DELETE \
139
+ # -H 'Authorization: Bearer <Access token>'
140
+ #
141
+ # @beyond_api.scopes +shpz:u+
142
+ #
143
+ # @param shipping_zone_id [String] the shipping zone UUID
144
+ # @param shipping_method_id [String] the shipping method UUID
145
+ #
146
+ # @return true
147
+ #
148
+ # @example
149
+ # session.shipping_zones.delete_shipping_method("61c14c3c-ce26-4524-9713-f2ede7ff22fa", "d2eee203-a1c6-4035-8e7a-74bb77cfde47")
150
+ #
151
+ def delete_shipping_method(shipping_zone_id, shipping_method_id)
152
+ response, status = BeyondApi::Request.delete(@session, "/shipping-zones/#{shipping_zone_id}/shipping_methods/#{shipping_method_id}")
153
+
154
+ handle_response(response, status, respond_with_true: true)
155
+ end
156
+
157
+ #
158
+ # A +GET+ request is used to retrieve the details of a shipping zone.
159
+ #
160
+ # @beyond_api.scopes +shpz:r+
161
+ #
162
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/27914098-c1f6-46aa-9e78-c7ac873e25b3' -i -X GET \
163
+ # -H 'Accept: application/hal+json' \
164
+ # -H 'Authorization: Bearer <Access token>'
165
+ #
166
+ # @param shipping_zone_id [String] the shipping zone UUID
167
+ #
168
+ # @return [OpenStruct]
169
+ #
170
+ # @example
171
+ # @shipping_zone = session.shipping_zones.find("27914098-c1f6-46aa-9e78-c7ac873e25b3")
172
+ #
173
+ def find(shipping_zone_id)
174
+ response, status = BeyondApi::Request.get(@session, "/shipping-zones/#{shipping_zone_id}")
175
+
176
+ handle_response(response, status)
177
+ end
178
+
179
+ #
180
+ # A +GET+ request is used to find the serviceable countries.
181
+ #
182
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/search/find-all-serviceable-countries' -i -X GET \
183
+ # -H 'Accept: application/hal+json'
184
+ #
185
+ # @return [OpenStruct]
186
+ #
187
+ # @example
188
+ # @serviceable_countries = session.shipping_zones.find_serviceable_countries
189
+ #
190
+ def find_serviceable_countries
191
+ response, status = BeyondApi::Request.get(@session, "/shipping-zones/search/find-all-serviceable-countries")
192
+
193
+ handle_response(response, status)
194
+ end
195
+
196
+ # A +GET+ request is used to retrieve the details of a shipping method in a shipping zone.
197
+ #
198
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/61780dd6-0150-4fcf-953c-d10c52bab4ab/shipping-methods/13bd1fc9-706c-4774-923a-484a41aaab89' -i -X GET \
199
+ # -H 'Accept: application/hal+json' \
200
+ # -H 'Authorization: Bearer <Access token>'
201
+ #
202
+ # @beyond_api.scopes +shpz:r+
203
+ #
204
+ # @param shipping_zone_id [String] the shipping zone UUID
205
+ # @param shipping_method_id [String] the shipping method UUID
206
+ #
207
+ # @return [OpenStruct]
208
+ #
209
+ # @example
210
+ # @shipping_method = session.shipping_zones.shipping_method("61780dd6-0150-4fcf-953c-d10c52bab4ab", "13bd1fc9-706c-4774-923a-484a41aaab89")
211
+ #
212
+ def shipping_method(shipping_zone_id, shipping_method_id)
213
+ response, status = BeyondApi::Request.get(@session, "/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")
214
+
215
+ handle_response(response, status)
216
+ end
217
+
218
+ #
219
+ # A +GET+ request is used to list all shipping-methods of a shipping zone in a paged way.
220
+ #
221
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/8cc24465-3573-4eca-8323-b076bb724080/shipping-methods' -i -X GET \
222
+ # -H 'Accept: application/hal+json' \
223
+ # -H 'Authorization: Bearer <Access token>'
224
+ #
225
+ # @beyond_api.scopes +shpz:r+
226
+ #
227
+ # @param shipping_zone_id [String] the shipping zone UUID
228
+ # @option params [Integer] :size the page size
229
+ # @option params [Integer] :page the page number
230
+ #
231
+ # @return [OpenStruct]
232
+ #
233
+ # @example
234
+ # @shipping_methods = session.shipping_zones.shipping_methods("8cc24465-3573-4eca-8323-b076bb724080", { size: 20, page: 0 })
235
+ #
236
+ def shipping_methods(shipping_zone_id, params = {})
237
+ response, status = BeyondApi::Request.get(@session, "/shipping-zones/#{shipping_zone_id}/shipping-methods", params)
238
+
239
+ handle_response(response, status)
240
+ end
241
+
242
+ #
243
+ # A `PUT` request is used to sort the shipping zones. This is done by passing the self-links of the shipping zones in the desired order.all
244
+ # The request must contain URIs for all shipping zones of the given page.
245
+ #
246
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X PUT \
247
+ # -H 'Content-Type: text/uri-list' \
248
+ # -H 'Authorization: Bearer <Access token>' \
249
+ # -d 'https://api-shop.beyondshop.cloud/api/shipping-zones/9fa80513-be11-494f-ac01-61832e0d7808
250
+ # https://api-shop.beyondshop.cloud/api/shipping-zones/f0911d4c-1ab0-4bbd-88e3-cb675cbb7da7
251
+ # https://api-shop.beyondshop.cloud/api/shipping-zones/ef2e7cb7-820e-4d62-b361-12240f635164'
252
+ #
253
+ # @beyond_api.scopes +shpz:u+
254
+ #
255
+ # @param shipping_zone_ids [Array] the list of shipping zone UUIDs
256
+ #
257
+ # @return [OpenStruct]
258
+ #
259
+ # @example
260
+ # shipping_zone_ids = ["9fa80513-be11-494f-ac01-61832e0d7808", "f0911d4c-1ab0-4bbd-88e3-cb675cbb7da7", "ef2e7cb7-820e-4d62-b361-12240f635164"]
261
+ # session.shipping_zones.sort(shipping_zone_ids)
262
+ #
263
+ def sort(shipping_zone_ids)
264
+ body = shipping_zone_ids.map { |shipping_zone_id| "#{session.api_url}/shipping-zones/#{id}" }
265
+ response, status = BeyondApi::Request.put(@session, "/shipping-zones", body)
266
+
267
+ handle_response(response, status, respond_with_true: true)
268
+ end
269
+
270
+ #
271
+ # A +PUT+ request is used to sort the shipping methods inside a shipping zone.
272
+ # This is done by passing the self-links of the shipping methods in the desired order. The request must contain URIs for all shipping methods of this shipping zone.
273
+ #
274
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/e54af33b-fadc-4524-8eec-7e0b3e20f625/shipping-methods' -i -X PUT \
275
+ # -H 'Accept: application/hal+json' \
276
+ # -H 'Authorization: Bearer <Access token>'
277
+ #
278
+ # @beyond_api.scopes +shpz:r+
279
+ #
280
+ # @param shipping_zone_id [String] the shipping zone UUID
281
+ #
282
+ # @return [OpenStruct]
283
+ #
284
+ # @example
285
+ # session.shipping_zones.sort_shipping_methods(shipping_zone_id)
286
+ #
287
+ def sort_shipping_methods(shipping_zone_id)
288
+ response, status = BeyondApi::Request.put(@session, "/shipping-zones/#{shipping_zone_id}/shipping-methods")
289
+
290
+ handle_response(response, status)
291
+ end
292
+
293
+ #
294
+ # A +PUT+ request is used to update a shipping zone.
295
+ #
296
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/727b3cbf-01b1-442a-bd5c-94c51901f090' -i -X PUT \
297
+ # -H 'Content-Type: application/json' \
298
+ # -H 'Authorization: Bearer <Access token>' \
299
+ # -d '{
300
+ # "name" : "BENELUX region",
301
+ # "serviceableCountries" : [ "BE", "NL", "LU", "DE" ]
302
+ # }'
303
+ #
304
+ # @beyond_api.scopes +shpz:u+
305
+ #
306
+ # @param shipping_zone_id [String] the shipping zone UUID
307
+ # @param body [String] the request body
308
+ #
309
+ # @return [OpenStruct]
310
+ #
311
+ # @example
312
+ # body = {
313
+ # "name" => "BENELUX region",
314
+ # "serviceableCountries" => [ "BE", "NL", "LU", "DE" ]
315
+ # }
316
+ # @shipping_zone = session.shipping_zones.update("727b3cbf-01b1-442a-bd5c-94c51901f090", body)
317
+ #
318
+ def update(shipping_zone_id, body)
319
+ response, status = BeyondApi::Request.put(@session, "/shipping-zones/#{shipping_zone_id}", body)
320
+
321
+ handle_response(response, status)
322
+ end
323
+ end
324
+ end
@@ -0,0 +1,561 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class Shop < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +GET+ request is used to retrieve the details of a shop’s address.
11
+ #
12
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/address' -i -X GET \
13
+ # -H 'Authorization: Bearer <Access token>'
14
+ #
15
+ # @beyond_api.scopes +shad:r+
16
+ #
17
+ # @return [OpenStruct]
18
+ #
19
+ # @example
20
+ # session.shop.address
21
+ #
22
+ def address
23
+ response, status = BeyondApi::Request.get(@session, "/shop/address")
24
+
25
+ handle_response(response, status)
26
+ end
27
+
28
+ #
29
+ # A +GET+ request is used to retrieve a particular shop attribute by its name.
30
+ #
31
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X GET \
32
+ # -H 'Authorization: Bearer <Access token>'
33
+ #
34
+ # @beyond_api.scopes +shat:r+
35
+ #
36
+ # @param attribute_name [String] the attribute name
37
+ #
38
+ # @return [OpenStruct]
39
+ #
40
+ # @example
41
+ # @shop_attribute = session.shop.attribute("second-unknown-attribute-name")
42
+ #
43
+ def attribute(attribute_name)
44
+ response, status = BeyondApi::Request.get(@session, "/shop/attributes/#{attribute_name}")
45
+
46
+ handle_response(response, status)
47
+ end
48
+
49
+ #
50
+ # A +GET+ request is used to retrieve a list of all shop attributes.
51
+ #
52
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X GET \
53
+ # -H 'Authorization: Bearer <Access token>'
54
+ #
55
+ # @beyond_api.scopes +shat:r+
56
+ #
57
+ # @option params [Integer] :size the page size
58
+ # @option params [Integer] :page the page number
59
+ #
60
+ # @return [OpenStruct]
61
+ #
62
+ # @example
63
+ # @shop_attributes = session.shop.attributes(size: 5, page: 1)
64
+ #
65
+ def attributes(params = {})
66
+ response, status = BeyondApi::Request.get(@session, "/shop/attributes", params)
67
+
68
+ handle_response(response, status)
69
+ end
70
+
71
+ #
72
+ # A +POST+ request is used to close a shop.
73
+ #
74
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/close' -i -X POST \
75
+ # -H 'Content-Type: application/json' \
76
+ # -H 'Authorization: Bearer <Access token>'
77
+ #
78
+ # @beyond_api.scopes +shcl:c+
79
+ #
80
+ # @return true
81
+ #
82
+ # @example
83
+ # session.shop.close
84
+ #
85
+ def close
86
+ response, status = BeyondApi::Request.post(@session, "/shop/close")
87
+
88
+ handle_response(response, status, respond_with_true: true)
89
+ end
90
+
91
+ #
92
+ # A +POST+ request is used to create a shop attribute.
93
+ #
94
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X POST \
95
+ # -H 'Content-Type: application/json' \
96
+ # -H 'Authorization: Bearer <Access token>' \
97
+ # -d '{
98
+ # "name" : "second-unknown-attribute-name",
99
+ # "value" : "correct-value",
100
+ # "public" : false
101
+ # }'
102
+ #
103
+ # @beyond_api.scopes +shat:c+
104
+ #
105
+ # @param body [Hash] the request body
106
+ #
107
+ # @return [OpenStruct]
108
+ #
109
+ # @example
110
+ # body = {
111
+ # "name" => "second-unknown-attribute-name",
112
+ # "value" => "correct-value",
113
+ # "public" => false
114
+ # }
115
+ #
116
+ # session.shop.create_attribute(body)
117
+ #
118
+ def create_attribute(body)
119
+ response, status = BeyondApi::Request.post(@session, "/shop/attributes", body)
120
+
121
+ handle_response(response, status)
122
+ end
123
+
124
+ #
125
+ # A +POST+ request is used to create a shop image.
126
+ #
127
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X POST \
128
+ # -H 'Content-Type: application/json' \
129
+ # -H 'Accept: application/hal+json' \
130
+ # -H 'Authorization: Bearer <Access token>' \
131
+ # -d '{
132
+ # "dataUri" : "file.png?hash=212-2323-4343",
133
+ # "label" : "logo"
134
+ # }'
135
+ #
136
+ # @beyond_api.scopes +shim:c+
137
+ #
138
+ # @param body [Hash] the request body
139
+ #
140
+ # @return true
141
+ #
142
+ # @example
143
+ # body = {
144
+ # "dataUri" => "file.png?hash=212-2323-4343",
145
+ # "label" => "logo"
146
+ # }
147
+ #
148
+ # session.shop.create_image(body)
149
+ #
150
+ def create_image(body)
151
+ response, status = BeyondApi::Request.post(@session, "/shop/images", body)
152
+
153
+ handle_response(response, status, respond_with_true: true)
154
+ end
155
+
156
+ #
157
+ # A +GET+ request is used to retrieve the details of a shop.
158
+ #
159
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop' -i -X GET \
160
+ # -H 'Accept: application/hal+json'
161
+ #
162
+ # @return [OpenStruct]
163
+ #
164
+ # @example
165
+ # session.shop.current
166
+ #
167
+ def current
168
+ response, status = BeyondApi::Request.get(@session, "/shop")
169
+
170
+ handle_response(response, status)
171
+ end
172
+
173
+ #
174
+ # A +DELETE+ request is used to delete an shop attribute.
175
+ #
176
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X DELETE \
177
+ # -H 'Authorization: Bearer <Access token>'
178
+ #
179
+ # @beyond_api.scopes +shat:d+
180
+ #
181
+ # @param attribute_name [String] the attribute name
182
+ #
183
+ # @return true
184
+ #
185
+ # @example
186
+ # session.shop.delete_attribute("second-unknown-attribute-name")
187
+ #
188
+ def delete_attribute(attribute_name)
189
+ response, status = BeyondApi::Request.delete(@session, "/shop/attributes/#{attribute_name}")
190
+
191
+ handle_response(response, status, respond_with_true: true)
192
+ end
193
+
194
+ #
195
+ # A +DELETE+ request is used to delete a shop image.
196
+ #
197
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/6a7646dc-7f26-4730-a98f-52f9b63978fb' -i -X DELETE \
198
+ # -H 'Content-Type: application/json' \
199
+ # -H 'Accept: application/hal+json' \
200
+ # -H 'Authorization: Bearer <Access token>'
201
+ #
202
+ # @beyond_api.scopes +shim:d+
203
+ #
204
+ # @param image_id [String] the image UUID
205
+ #
206
+ # @return true
207
+ #
208
+ # @example
209
+ # session.shop.delete_image("6a7646dc-7f26-4730-a98f-52f9b63978fb")
210
+ #
211
+ def delete_image(image_id)
212
+ response, status = BeyondApi::Request.delete(@session, "/shop/images/#{image_id}")
213
+
214
+ handle_response(response, status, respond_with_true: true)
215
+ end
216
+
217
+ #
218
+ # A +GET+ request is used to retrieve a single shop image.
219
+ #
220
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/2feee7ac-f1cb-4faf-9488-f3ce07394141' -i -X GET \
221
+ # -H 'Accept: application/hal+json'
222
+ #
223
+ # @param image_id [String] the image UUID
224
+ #
225
+ # @return [OpenStruct]
226
+ #
227
+ # @example
228
+ # session.shop.image("2feee7ac-f1cb-4faf-9488-f3ce07394141")
229
+ #
230
+ def image(image_id)
231
+ response, status = BeyondApi::Request.get(@session, "/shop/images/#{image_id}")
232
+
233
+ handle_response(response, status)
234
+ end
235
+
236
+ #
237
+ # A +GET+ request is used to retrieve the images of a shop.
238
+ #
239
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X GET \
240
+ # -H 'Accept: application/hal+json'
241
+ #
242
+ # @option params [Integer] :size the page size
243
+ # @option params [Integer] :page the page number
244
+ #
245
+ # @return [OpenStruct]
246
+ #
247
+ # @example
248
+ # session.shop.images(size: 5, page: 1)
249
+ #
250
+ def images(params = {})
251
+ response, status = BeyondApi::Request.get(@session, "/shop/images", params)
252
+
253
+ handle_response(response, status)
254
+ end
255
+
256
+ #
257
+ # A +GET+ request is used to retrieve a specific part of the legal content information.
258
+ #
259
+ # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/right-of-withdrawal' -i -X GET \
260
+ # -H 'Content-Type: application/json' \
261
+ # -H 'Accept: application/json'
262
+ #
263
+ # @param legal_content_type [String] the legal content type
264
+ #
265
+ # @return [OpenStruct]
266
+ #
267
+ # @example
268
+ # session.shop.legal_content("right-of-withdrawal")
269
+ #
270
+ def legal_content(legal_content_type)
271
+ response, status = BeyondApi::Request.get(@session, "/legal-content/right-of-withdrawal")
272
+
273
+ handle_response(response, status)
274
+ end
275
+
276
+ #
277
+ # A +GET+ request is used to retrieve the legal content of a shop.
278
+ #
279
+ # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content' -i -X GET \
280
+ # -H 'Content-Type: application/json' \
281
+ # -H 'Accept: application/json'
282
+ #
283
+ # @option params [Integer] :size the page size
284
+ # @option params [Integer] :page the page number
285
+ #
286
+ # @return [OpenStruct]
287
+ #
288
+ # @example
289
+ # session.shop.legal_contents(size: 5, page: 1)
290
+ #
291
+ def legal_contents(params = {})
292
+ response, status = BeyondApi::Request.get(@session, "/legal-content")
293
+
294
+ handle_response(response, status)
295
+ end
296
+
297
+ #
298
+ # A +GET+ request is used to retrieve the details of the legal resource.
299
+ #
300
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X GET \
301
+ # -H 'Authorization: Bearer <Access token>'
302
+ #
303
+ # @beyond_api.scopes +legl:r+
304
+ #
305
+ # @return [OpenStruct]
306
+ #
307
+ # @example
308
+ # session.shop.legal_details
309
+ #
310
+ def legal_details
311
+ response, status = BeyondApi::Request.get(@session, "/shop/legal")
312
+
313
+ handle_response(response, status)
314
+ end
315
+
316
+ #
317
+ # A +POST+ request is used to open a shop.
318
+ #
319
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/open' -i -X POST \
320
+ # -H 'Content-Type: application/json' \
321
+ # -H 'Authorization: Bearer <Access token>'
322
+ #
323
+ # @beyond_api.scopes +shcl:c+
324
+ #
325
+ # @return true
326
+ #
327
+ # @example
328
+ # session.shop.open
329
+ #
330
+ def open
331
+ response, status = BeyondApi::Request.post(@session, "/shop/open")
332
+
333
+ handle_response(response, status, respond_with_true: true)
334
+ end
335
+
336
+ #
337
+ # A +GET+ request is issued to search for shop images by label.
338
+ #
339
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/search/find-by-label?label=logo' -i -X GET \
340
+ # -H 'Accept: application/hal+json'
341
+ #
342
+ # @param label [String] the image label
343
+ #
344
+ # @return [OpenStruct]
345
+ #
346
+ # @example
347
+ # session.shop.search_images_by_label("logo")
348
+ #
349
+ def search_images_by_label(label)
350
+ response, status = BeyondApi::Request.get(@session, "/shop/images/search/find-by-label", { label: label })
351
+
352
+ handle_response(response, status)
353
+ end
354
+
355
+ #
356
+ # A +PATCH+ request is used to change attributes of a shop.
357
+ #
358
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop' -i -X PATCH \
359
+ # -H 'Content-Type: application/json' \
360
+ # -H 'Accept: application/hal+json' \
361
+ # -H 'Authorization: Bearer <Access token>' \
362
+ # -d '{
363
+ # "name" : "anotherName",
364
+ # "closedShopMessage" : "This shop is opening soon.",
365
+ # "primaryHostname" : "cornershop.amazingdiscounts.xyz",
366
+ # "fallbackHostname" : "cornershop.beyondshop.cloud",
367
+ # "tax" : {
368
+ # "taxModel" : "GROSS",
369
+ # "vatExempted" : false
370
+ # },
371
+ # "currencies" : [ "EUR", "USD", "GBP" ],
372
+ # "defaultCurrency" : "USD",
373
+ # "locales" : [ "en-GB", "de-DE" ],
374
+ # "defaultLocale" : "en-GB",
375
+ # "closedByMerchant" : false
376
+ # }'
377
+ #
378
+ # @beyond_api.scopes +shop:u+
379
+ #
380
+ # @param body [Hash] the request body
381
+ #
382
+ # @return [OpenStruct]
383
+ #
384
+ # @example
385
+ # body = {
386
+ # "name" => "anotherName",
387
+ # "closedShopMessage" => "This shop is opening soon.",
388
+ # "primaryHostname" => "cornershop.amazingdiscounts.xyz",
389
+ # "fallbackHostname" => "cornershop.beyondshop.cloud",
390
+ # "tax" => {
391
+ # "taxModel" => "GROSS",
392
+ # "vatExempted" => false
393
+ # },
394
+ # "currencies" => [ "EUR", "USD", "GBP" ],
395
+ # "defaultCurrency" => "USD",
396
+ # "locales" => [ "en-GB", "de-DE" ],
397
+ # "defaultLocale" => "en-GB",
398
+ # "closedByMerchant" => false
399
+ # }
400
+ #
401
+ # session.shop.update(body)
402
+ #
403
+ def update(body)
404
+ response, status = BeyondApi::Request.patch(@session, "/shop")
405
+
406
+ handle_response(response, status)
407
+ end
408
+
409
+ #
410
+ # A +PATCH+ request is used to patch a shop’s address partially with json content type.
411
+ #
412
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/address' -i -X PATCH \
413
+ # -H 'Content-Type: application/json' \
414
+ # -H 'Accept: application/hal+json' \
415
+ # -H 'Authorization: Bearer <Access token>' \
416
+ # -d '{
417
+ # "city" : "Barcelona"
418
+ # }'
419
+ #
420
+ # @beyond_api.scopes +shad:u+
421
+ #
422
+ # @param body [Hash] the request body
423
+ #
424
+ # @return [OpenStruct]
425
+ #
426
+ # @example
427
+ # body = {
428
+ # "city" => "Barcelona"
429
+ # }
430
+ #
431
+ # session.shop.update_address(body)
432
+ #
433
+ def update_address(body)
434
+ response, status = BeyondApi::Request.patch(@session, "/shop/address", body)
435
+
436
+ handle_response(response, status)
437
+ end
438
+
439
+ #
440
+ # A +PUT+ request is used to update a shop attribute. This operation is idempotent and will create a new shop attribute if required.
441
+ #
442
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X PUT \
443
+ # -H 'Content-Type: application/json' \
444
+ # -H 'Authorization: Bearer <Access token>' \
445
+ # -d '{
446
+ # "value" : "new-value",
447
+ # "public" : false
448
+ # }'
449
+ #
450
+ # @beyond_api.scopes +shat:u+
451
+ #
452
+ # @param attribute_name [String] the attribute name
453
+ # @param body [Hash] the request body
454
+ #
455
+ # @return [OpenStruct]
456
+ #
457
+ # @example
458
+ # body = {
459
+ # "value" => "new-value",
460
+ # "public" => false
461
+ # }
462
+ #
463
+ # session.shop.update_attribute("second-unknown-attribute-name", body)
464
+ #
465
+ def update_attribute(attribute_name, body)
466
+ response, status = BeyondApi::Request.put(@session, "/shop/attributes/#{attribute_name}", body)
467
+
468
+ handle_response(response, status)
469
+ end
470
+
471
+ #
472
+ # 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.
473
+ #
474
+ # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/legal-notice' -i -X PUT \
475
+ # -H 'Content-Type: application/json' \
476
+ # -H 'Accept: application/json' \
477
+ # -H 'Authorization: Bearer <Access token>' \
478
+ # -d '{
479
+ # "content" : "new legal content"
480
+ # }'
481
+ #
482
+ # @beyond_api.scopes +lcnt:u+
483
+ #
484
+ # @param body [Hash] the request body
485
+ #
486
+ # @return [OpenStruct]
487
+ #
488
+ # @example
489
+ # session.shop.update_legal_content(body)
490
+ #
491
+ def update_legal_content(body)
492
+ response, status = BeyondApi::Request.put(@session, "/legal-content/legal-notice")
493
+
494
+ handle_response(response, status)
495
+ end
496
+
497
+ #
498
+ # A +PATCH+ request is used to update a legal resource partially with json content type.
499
+ #
500
+ # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X PATCH \
501
+ # -H 'Content-Type: application/json' \
502
+ # -H 'Accept: application/hal+json' \
503
+ # -H 'Authorization: Bearer <Access token>' \
504
+ # -d '{
505
+ # "vatId" : "GB 111111111"
506
+ # }'
507
+ #
508
+ # @beyond_api.scopes +legl:u+
509
+ #
510
+ # @param body [Hash] the request body
511
+ #
512
+ # @return [OpenStruct]
513
+ #
514
+ # @example
515
+ # body = {
516
+ # "vatId" => "GB 111111111"
517
+ # }
518
+ #
519
+ # session.shop.update_legal_details(body)
520
+ #
521
+ def update_legal_details(body)
522
+ response, status = BeyondApi::Request.patch(@session, "/shop/legal")
523
+
524
+ handle_response(response, status)
525
+ end
526
+
527
+ #
528
+ # A +POST+ request is used to upload a shop image. The body of the request must contain the content of the image.
529
+ #
530
+ # $ curl --data-binary '@/home/epages/sample.png' 'https://api-shop.beyondshop.cloud/api/shop/images?fileName=sample.png&label=invoice logo' -X POST \
531
+ # -H 'Content-Type: image/png' \
532
+ # -H 'Authorization: Bearer <Access token>'
533
+ #
534
+ # @beyond_api.scopes +shim:c+
535
+ #
536
+ # @param image_path [String] the image path
537
+ # @param image_name [String] the image name
538
+ # @param label [String] the image label
539
+ #
540
+ # @return true
541
+ #
542
+ # @example
543
+ # session.shop.upload_image("/home/epages/sample.png", "sample.png", "invoice logo")
544
+ #
545
+ def upload_image(image_path, image_name, label)
546
+ content_type = case File.extname(image_path)
547
+ when ".png"
548
+ "image/png"
549
+ when ".jpg", ".jpeg"
550
+ "image/jpeg"
551
+ when ".gif"
552
+ "image/gif"
553
+ end
554
+ image_binary = File.binread(image_path)
555
+
556
+ response, status = BeyondApi::Request.upload(@session, "/shop/images", image_binary, content_type, { file_name: image_name, label: label })
557
+
558
+ handle_response(response, status, respond_with_true: true)
559
+ end
560
+ end
561
+ end