beyond_api 0.9.0.pre → 0.12.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eb69d55a6ff81113a94022f031b7c09c6dd0e51a4337d48dc698d5aa6a79153
4
- data.tar.gz: 3b782cea11e4d0533827192fc8141519b487d034bf194657f05e01c04895458c
3
+ metadata.gz: 49750d84cced44e6e76b41d1202138d51410cb51afc3df6ba47bbaf599afd34f
4
+ data.tar.gz: c6ccb9edbc9d0042f0c8e220b66afa8f2d559cc3c1a6e0208989da6281e0900c
5
5
  SHA512:
6
- metadata.gz: 705ebbe6fb68e9a8e4b456978d9d05af02ed03cf96c5002ad384037cda169a9074a99aa71e57e3e83a9e9651aa2662d21eeb7b2a11ac4c60e53a97fe7d35b59e
7
- data.tar.gz: fbba10e64cdb172ee326d1092841c2212683377a3f8325b3bcce1340cf76e149edb8ab2dfe0f9a3e5ea158b3dedc64915c19cf6ff8fe71293bdc3e89321fc19c
6
+ metadata.gz: d4cfcc2e6e8e0aa7e400fe6190eda04a23810896339cc2a8dbde720f32996c1f49d3d7d24fa54ebb0cb012ce07a60e6802b44af6e214e9d086a046f64e84f53b
7
+ data.tar.gz: 41b39da7d2ccfef54b4802b56f419d09620c9c18d4f26a81268db15a94ec8a60daae280cc933a4c475799b3e574eda73eea69fae9d675f6112dcc168868db379
@@ -1,3 +1,46 @@
1
+ ### v0.12.1.pre
2
+
3
+ * bug-fixes
4
+ * Fix camelize function for hashes containing arrays
5
+
6
+ ### v0.12.0.pre
7
+
8
+ * features
9
+ * Add locations methods
10
+ * `Locations#all`
11
+ * `Locations#create`
12
+ * `Locations#delete`
13
+ * `Locations#find`
14
+ * `Locations#update`
15
+
16
+ * enhancements
17
+ * Use `autoload` instead of `require`
18
+
19
+ ### v0.11.1.pre
20
+
21
+ * bug-fixes
22
+ * Use `BeyondApi::Error` for authentication errors
23
+
24
+ ### v0.11.0.pre
25
+
26
+ * enhancements
27
+ * Improve error handling class
28
+ * Improve `BeyondApi::Error` class
29
+
30
+ ### v0.10.0.pre
31
+
32
+ * features
33
+ * Add optional `paginated: false` parameter to `session.categories_view.all(paginated: false)`
34
+ * Add optional `paginated: false` parameter to `session.categories.all(paginated: false)`
35
+ * Add optional `paginated: false` parameter to `session.customers.all(paginated: false)`
36
+ * Add optional `paginated: false` parameter to `session.orders.all(paginated: false)`
37
+ * Add optional `paginated: false` parameter to `session.payment_methods.all(paginated: false)`
38
+ * Add optional `paginated: false` parameter to `session.products_view.all(paginated: false)`
39
+ * Add optional `paginated: false` parameter to `session.script_tags.all(paginated: false)`
40
+ * Add optional `paginated: false` parameter to `session.shipping_zones.all(paginated: false)`
41
+ * Add optional `paginated: false` parameter to `session.users.all(paginated: false)`
42
+ * Add optional `paginated: false` parameter to `session.webhook_subscriptions.all(paginated: false)`
43
+
1
44
  ### v0.9.0.pre
2
45
 
3
46
  * bug-fixes
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.9.0.pre)
4
+ beyond_api (0.12.1.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -1,14 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BeyondApi
4
- class Error
5
- attr_reader :error_id, :details, :message, :trace_id
4
+ class Error < StandardError
5
+ attr_reader :error_id, :details, :trace_id, :full_message, :status_code, :error, :error_description
6
6
 
7
- def initialize(data)
8
- @error_id = data['errorId']
9
- @details = data['details']
10
- @message = data['message']
11
- @trace_id = data['traceId']
7
+ def initialize(data, status_code = nil)
8
+ @error_id = data['errorId']
9
+ @details = data['details']
10
+ @trace_id = data['traceId']
11
+ @error = data['error']
12
+ @error_description = data['error_description']
13
+ @full_message = data
14
+ @status_code = status_code
15
+
16
+ super(data['message'] || data['error_description'])
12
17
  end
13
18
  end
14
19
  end
@@ -4,7 +4,14 @@ class Hash
4
4
  def deep_transform_keys(&block)
5
5
  result = {}
6
6
  each do |key, value|
7
- result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
7
+ result[yield(key)] = case value
8
+ when Hash
9
+ value.deep_transform_keys(&block)
10
+ when Array
11
+ value.camelize_keys
12
+ else
13
+ value
14
+ end
8
15
  end
9
16
  result
10
17
  end
@@ -16,6 +16,7 @@ module BeyondApi
16
16
  #
17
17
  # @beyond_api.scopes +catg:r+
18
18
  #
19
+ # @option params [Boolean] :paginated
19
20
  # @option params [Integer] :size the page size
20
21
  # @option params [Integer] :page the page number
21
22
  #
@@ -25,9 +26,7 @@ module BeyondApi
25
26
  # @categories = session.categories.all(size: 100, page: 0)
26
27
  #
27
28
  def all(params = {})
28
- response, status = BeyondApi::Request.get(@session, "/categories", params)
29
-
30
- handle_response(response, status)
29
+ handle_all_request("/categories", :categories, params)
31
30
  end
32
31
 
33
32
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  # -H 'Accept: application/hal+json'
15
15
  #
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @categories = session.categories_view.all(size: 100, page: 0)
24
25
  #
25
26
  def all(params = {})
26
- response, status = BeyondApi::Request.get(@session, "/product-view/categories", params)
27
-
28
- handle_response(response, status)
27
+ handle_all_request("/product-view/categories", :categories, params)
29
28
  end
30
29
 
31
30
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  #
15
15
  # @beyond_api.scopes +cust:r+
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @customers = session.customers.all(size: 20, page: 0)
24
25
  #
25
26
  def all(params = {})
26
- response, status = BeyondApi::Request.get(@session, "/customers", params)
27
-
28
- handle_response(response, status)
27
+ handle_all_request("/customers", :customers, params)
29
28
  end
30
29
 
31
30
  #
@@ -57,6 +57,7 @@ module BeyondApi
57
57
  #
58
58
  # @beyond_api.scopes +ordr:r+
59
59
  #
60
+ # @option params [Boolean] :paginated
60
61
  # @option params [Integer] :size the page size
61
62
  # @option params [Integer] :page the page number
62
63
  #
@@ -66,9 +67,7 @@ module BeyondApi
66
67
  # @orders = session.orders.all(size: 100, page: 0)
67
68
  #
68
69
  def all(params = {})
69
- response, status = BeyondApi::Request.get(@session, "/orders", params)
70
-
71
- handle_response(response, status)
70
+ handle_all_request("/orders", :orders, params)
72
71
  end
73
72
 
74
73
  #
@@ -38,6 +38,7 @@ module BeyondApi
38
38
  #
39
39
  # @beyond_api.scopes +pymt:r+
40
40
  #
41
+ # @option params [Boolean] :paginated
41
42
  # @option params [Integer] :size the page size
42
43
  # @option params [Integer] :page the page number
43
44
  #
@@ -47,9 +48,7 @@ module BeyondApi
47
48
  # @payment_methods = session.payment_methods.all(size: 100, page: 0)
48
49
  #
49
50
  def all(params = {})
50
- response, status = BeyondApi::Request.get(@session, "/payment-methods", params)
51
-
52
- handle_response(response, status)
51
+ handle_all_request("/payment-methods", :payment_methods, params)
53
52
  end
54
53
 
55
54
  #
@@ -24,19 +24,7 @@ module BeyondApi
24
24
  # @product_attribute_definitions = session.product_attribute_definitions.all(size: 100, page: 0)
25
25
  #
26
26
  def all(params = {})
27
- if params[:paginated] == false
28
- result = all_paginated(page: 0, size: 1000)
29
-
30
- (1..result[:page][:total_pages] - 1).each do |page|
31
- result[:embedded][:product_attribute_definition].concat(all_paginated(page: page, size: 1000)[:embedded][:product_attribute_definitions])
32
- end
33
-
34
- result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
35
-
36
- result
37
- else
38
- all_paginated(params)
39
- end
27
+ handle_all_request("/product-attribute-definitions", :product_attribute_definitions, params)
40
28
  end
41
29
 
42
30
  #
@@ -114,12 +102,5 @@ module BeyondApi
114
102
 
115
103
  handle_response(response, status)
116
104
  end
117
-
118
- private
119
-
120
- def all_paginated(params = {})
121
- response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions", params)
122
- handle_response(response, status)
123
- end
124
105
  end
125
106
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "beyond_api/utils"
4
- require "beyond_api/resources/products/attachments"
5
- require "beyond_api/resources/products/availability"
6
- require "beyond_api/resources/products/cross_sells"
7
- require "beyond_api/resources/products/custom_attributes"
8
- require "beyond_api/resources/products/images"
9
- require "beyond_api/resources/products/searches"
10
- require "beyond_api/resources/products/variation_properties"
11
- require "beyond_api/resources/products/videos"
12
4
 
13
5
  module BeyondApi
6
+ autoload :ProductAttachments, "beyond_api/resources/products/attachments"
7
+ autoload :ProductAvailability, "beyond_api/resources/products/availability"
8
+ autoload :ProductCrossSells, "beyond_api/resources/products/cross_sells"
9
+ autoload :ProductCustomAttributes, "beyond_api/resources/products/custom_attributes"
10
+ autoload :ProductImages, "beyond_api/resources/products/images"
11
+ autoload :ProductSearches, "beyond_api/resources/products/searches"
12
+ autoload :ProductVariationProperties, "beyond_api/resources/products/variation_properties"
13
+ autoload :ProductVideos, "beyond_api/resources/products/videos"
14
+
14
15
  class Products < Base
15
16
  include BeyondApi::ProductAttachments
16
17
  include BeyondApi::ProductAvailability
@@ -42,19 +43,7 @@ module BeyondApi
42
43
  # @products = session.products.all(size: 100, page: 0)
43
44
  #
44
45
  def all(params = {})
45
- if params[:paginated] == false
46
- result = all_paginated(page: 0, size: 1000)
47
-
48
- (1..result[:page][:total_pages] - 1).each do |page|
49
- result[:embedded][:products].concat(all_paginated(page: page, size: 1000)[:embedded][:products])
50
- end
51
-
52
- result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
53
-
54
- result
55
- else
56
- all_paginated(params)
57
- end
46
+ handle_all_request("/products", :products, params)
58
47
  end
59
48
 
60
49
  #
@@ -293,13 +282,5 @@ module BeyondApi
293
282
  alias_method :create_variation, :create
294
283
  alias_method :find_variation, :find
295
284
  alias_method :update_variation, :update
296
-
297
- private
298
-
299
- def all_paginated(params = {})
300
- response, status = BeyondApi::Request.get(@session, "/products", params)
301
-
302
- handle_response(response, status)
303
- end
304
285
  end
305
286
  end
@@ -13,6 +13,7 @@ module BeyondApi
13
13
  # -H 'Content-Type: application/json' \
14
14
  # -H 'Accept: application/hal+json'
15
15
  #
16
+ # @option params [Boolean] :paginated
16
17
  # @option params [Integer] :size the page size
17
18
  # @option params [Integer] :page the page number
18
19
  #
@@ -22,9 +23,7 @@ module BeyondApi
22
23
  # @products = session.products_view.all(page: 0, size: 100)
23
24
  #
24
25
  def all(params = {})
25
- response, status = BeyondApi::Request.get(@session, "/product-view/products", params)
26
-
27
- handle_response(response, status)
26
+ handle_all_request("/product-view/products", :products, params)
28
27
  end
29
28
 
30
29
  #
@@ -12,6 +12,7 @@ module BeyondApi
12
12
  # $ curl 'https://api-shop.beyondshop.cloud/api/script-tags' -i -X GET \
13
13
  # -H 'Authorization: Bearer <Access token>'
14
14
  #
15
+ # @option params [Boolean] :paginated
15
16
  # @option params [Integer] :size the page size
16
17
  # @option params [Integer] :page the page number
17
18
  #
@@ -21,9 +22,7 @@ module BeyondApi
21
22
  # @script_tags = session.script_tags.all(size: 20, page: 0)
22
23
  #
23
24
  def all(params = {})
24
- response, status = BeyondApi::Request.get(@session, "/script-tags", params)
25
-
26
- handle_response(response, status)
25
+ handle_all_request("/script-tags", :script_tags, params)
27
26
  end
28
27
 
29
28
  #
@@ -14,6 +14,7 @@ module BeyondApi
14
14
  # $ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X GET \
15
15
  # -H 'Authorization: Bearer <Access token>'
16
16
  #
17
+ # @option params [Boolean] :paginated
17
18
  # @option params [Integer] :size the page size
18
19
  # @option params [Integer] :page the page number
19
20
  #
@@ -23,9 +24,7 @@ module BeyondApi
23
24
  # @shipping_zones = session.shipping_zones.all(size: 20, page: 0)
24
25
  #
25
26
  def all(params = {})
26
- response, status = BeyondApi::Request.get(@session, "/shipping-zones", params)
27
-
28
- handle_response(response, status)
27
+ handle_all_request("/shipping-zones", :shipping_zones, params)
29
28
  end
30
29
 
31
30
  #
@@ -3,133 +3,20 @@
3
3
  require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
+ autoload :ShopAddress, "beyond_api/resources/shops/address"
7
+ autoload :ShopAttributes, "beyond_api/resources/shops/attributes"
8
+ autoload :ShopImages, "beyond_api/resources/shops/images"
9
+ autoload :ShopLegals, "beyond_api/resources/shops/legals"
10
+ autoload :ShopLocations, "beyond_api/resources/shops/locations"
11
+
6
12
  class Shop < Base
13
+ include BeyondApi::ShopAddress
14
+ include BeyondApi::ShopAttributes
15
+ include BeyondApi::ShopImages
16
+ include BeyondApi::ShopLegals
17
+ include BeyondApi::ShopLocations
7
18
  include BeyondApi::Utils
8
19
 
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
- #
14
- # @return [OpenStruct]
15
- #
16
- # @example
17
- # session.shop.address
18
- #
19
- def address
20
- response, status = BeyondApi::Request.get(@session, "/shop/address")
21
-
22
- handle_response(response, status)
23
- end
24
-
25
- #
26
- # A +GET+ request is used to retrieve a particular shop attribute by its name.
27
- #
28
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X GET \
29
- # -H 'Authorization: Bearer <Access token>'
30
- #
31
- # @beyond_api.scopes +shat:r+
32
- #
33
- # @param attribute_name [String] the attribute name
34
- #
35
- # @return [OpenStruct]
36
- #
37
- # @example
38
- # @shop_attribute = session.shop.attribute("second-unknown-attribute-name")
39
- #
40
- def attribute(attribute_name)
41
- response, status = BeyondApi::Request.get(@session, "/shop/attributes/#{attribute_name}")
42
-
43
- handle_response(response, status)
44
- end
45
-
46
- #
47
- # A +GET+ request is used to retrieve a list of all shop attributes.
48
- #
49
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X GET \
50
- # -H 'Authorization: Bearer <Access token>'
51
- #
52
- # @beyond_api.scopes +shat:r+
53
- #
54
- # @option params [Integer] :size the page size
55
- # @option params [Integer] :page the page number
56
- #
57
- # @return [OpenStruct]
58
- #
59
- # @example
60
- # @shop_attributes = session.shop.attributes(size: 5, page: 1)
61
- #
62
- def attributes(params = {})
63
- response, status = BeyondApi::Request.get(@session, "/shop/attributes", params)
64
-
65
- handle_response(response, status)
66
- end
67
-
68
- #
69
- # A +POST+ request is used to create a shop attribute.
70
- #
71
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X POST \
72
- # -H 'Content-Type: application/json' \
73
- # -H 'Authorization: Bearer <Access token>' \
74
- # -d '{
75
- # "name" : "second-unknown-attribute-name",
76
- # "value" : "correct-value",
77
- # "public" : false
78
- # }'
79
- #
80
- # @beyond_api.scopes +shat:c+
81
- #
82
- # @param body [Hash] the request body
83
- #
84
- # @return [OpenStruct]
85
- #
86
- # @example
87
- # body = {
88
- # "name" => "second-unknown-attribute-name",
89
- # "value" => "correct-value",
90
- # "public" => false
91
- # }
92
- #
93
- # session.shop.create_attribute(body)
94
- #
95
- def create_attribute(body)
96
- response, status = BeyondApi::Request.post(@session, "/shop/attributes", body)
97
-
98
- handle_response(response, status)
99
- end
100
-
101
- #
102
- # A +POST+ request is used to create a shop image.
103
- #
104
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X POST \
105
- # -H 'Content-Type: application/json' \
106
- # -H 'Accept: application/hal+json' \
107
- # -H 'Authorization: Bearer <Access token>' \
108
- # -d '{
109
- # "dataUri" : "file.png?hash=212-2323-4343",
110
- # "label" : "logo"
111
- # }'
112
- #
113
- # @beyond_api.scopes +shim:c+
114
- #
115
- # @param body [Hash] the request body
116
- #
117
- # @return true
118
- #
119
- # @example
120
- # body = {
121
- # "data_uri" => "file.png?hash=212-2323-4343",
122
- # "label" => "logo"
123
- # }
124
- #
125
- # session.shop.create_image(body)
126
- #
127
- def create_image(body)
128
- response, status = BeyondApi::Request.post(@session, "/shop/images", body)
129
-
130
- handle_response(response, status, respond_with_true: true)
131
- end
132
-
133
20
  #
134
21
  # A +GET+ request is used to retrieve the details of a shop.
135
22
  #
@@ -147,168 +34,6 @@ module BeyondApi
147
34
  handle_response(response, status)
148
35
  end
149
36
 
150
- #
151
- # A +DELETE+ request is used to delete an shop attribute.
152
- #
153
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X DELETE \
154
- # -H 'Authorization: Bearer <Access token>'
155
- #
156
- # @beyond_api.scopes +shat:d+
157
- #
158
- # @param attribute_name [String] the attribute name
159
- #
160
- # @return true
161
- #
162
- # @example
163
- # session.shop.delete_attribute("second-unknown-attribute-name")
164
- #
165
- def delete_attribute(attribute_name)
166
- response, status = BeyondApi::Request.delete(@session, "/shop/attributes/#{attribute_name}")
167
-
168
- handle_response(response, status, respond_with_true: true)
169
- end
170
-
171
- #
172
- # A +DELETE+ request is used to delete a shop image.
173
- #
174
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/6a7646dc-7f26-4730-a98f-52f9b63978fb' -i -X DELETE \
175
- # -H 'Content-Type: application/json' \
176
- # -H 'Accept: application/hal+json' \
177
- # -H 'Authorization: Bearer <Access token>'
178
- #
179
- # @beyond_api.scopes +shim:d+
180
- #
181
- # @param image_id [String] the image UUID
182
- #
183
- # @return true
184
- #
185
- # @example
186
- # session.shop.delete_image("6a7646dc-7f26-4730-a98f-52f9b63978fb")
187
- #
188
- def delete_image(image_id)
189
- response, status = BeyondApi::Request.delete(@session, "/shop/images/#{image_id}")
190
-
191
- handle_response(response, status, respond_with_true: true)
192
- end
193
-
194
- #
195
- # A +GET+ request is used to retrieve a single shop image.
196
- #
197
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/2feee7ac-f1cb-4faf-9488-f3ce07394141' -i -X GET \
198
- # -H 'Accept: application/hal+json'
199
- #
200
- # @param image_id [String] the image UUID
201
- #
202
- # @return [OpenStruct]
203
- #
204
- # @example
205
- # @image = session.shop.image("2feee7ac-f1cb-4faf-9488-f3ce07394141")
206
- #
207
- def image(image_id)
208
- response, status = BeyondApi::Request.get(@session, "/shop/images/#{image_id}")
209
-
210
- handle_response(response, status)
211
- end
212
-
213
- #
214
- # A +GET+ request is used to retrieve the images of a shop.
215
- #
216
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X GET \
217
- # -H 'Accept: application/hal+json'
218
- #
219
- # @option params [Integer] :size the page size
220
- # @option params [Integer] :page the page number
221
- #
222
- # @return [OpenStruct]
223
- #
224
- # @example
225
- # @images = session.shop.images(size: 5, page: 1)
226
- #
227
- def images(params = {})
228
- response, status = BeyondApi::Request.get(@session, "/shop/images", params)
229
-
230
- handle_response(response, status)
231
- end
232
-
233
- #
234
- # A +GET+ request is used to retrieve a specific part of the legal content information.
235
- #
236
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/right-of-withdrawal' -i -X GET \
237
- # -H 'Content-Type: application/json' \
238
- # -H 'Accept: application/json'
239
- #
240
- # @param legal_content_type [String] the legal content type
241
- #
242
- # @return [OpenStruct]
243
- #
244
- # @example
245
- # @legal_content = session.shop.legal_content("right-of-withdrawal")
246
- #
247
- def legal_content(legal_content_type)
248
- response, status = BeyondApi::Request.get(@session, "/legal-content/#{legal_content_type}")
249
-
250
- handle_response(response, status)
251
- end
252
-
253
- #
254
- # A +GET+ request is used to retrieve the legal content of a shop.
255
- #
256
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content' -i -X GET \
257
- # -H 'Content-Type: application/json' \
258
- # -H 'Accept: application/json'
259
- #
260
- # @option params [Integer] :size the page size
261
- # @option params [Integer] :page the page number
262
- #
263
- # @return [OpenStruct]
264
- #
265
- # @example
266
- # @legal_content = session.shop.legal_contents(size: 5, page: 1)
267
- #
268
- def legal_contents(params = {})
269
- response, status = BeyondApi::Request.get(@session, "/legal-content", params)
270
-
271
- handle_response(response, status)
272
- end
273
-
274
- #
275
- # A +GET+ request is used to retrieve the details of the legal resource.
276
- #
277
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X GET \
278
- # -H 'Authorization: Bearer <Access token>'
279
- #
280
- # @beyond_api.scopes +legl:r+
281
- #
282
- # @return [OpenStruct]
283
- #
284
- # @example
285
- # @legal_details = session.shop.legal_details
286
- #
287
- def legal_details
288
- response, status = BeyondApi::Request.get(@session, "/shop/legal")
289
-
290
- handle_response(response, status)
291
- end
292
-
293
- #
294
- # A +GET+ request is issued to search for shop images by label.
295
- #
296
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/search/find-by-label?label=logo' -i -X GET \
297
- # -H 'Accept: application/hal+json'
298
- #
299
- # @param label [String] the image label
300
- #
301
- # @return [OpenStruct]
302
- #
303
- # @example
304
- # session.shop.search_images_by_label("logo")
305
- #
306
- def search_images_by_label(label)
307
- response, status = BeyondApi::Request.get(@session, "/shop/images/search/find-by-label", { label: label })
308
-
309
- handle_response(response, status)
310
- end
311
-
312
37
  #
313
38
  # A +PATCH+ request is used to change attributes of a shop.
314
39
  #
@@ -360,157 +85,5 @@ module BeyondApi
360
85
 
361
86
  handle_response(response, status)
362
87
  end
363
-
364
- #
365
- # A +PATCH+ request is used to patch a shop’s address partially with json content type.
366
- #
367
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/address' -i -X PATCH \
368
- # -H 'Content-Type: application/json' \
369
- # -H 'Accept: application/hal+json' \
370
- # -H 'Authorization: Bearer <Access token>' \
371
- # -d '{
372
- # "city" : "Barcelona"
373
- # }'
374
- #
375
- # @beyond_api.scopes +shad:u+
376
- #
377
- # @param body [Hash] the request body
378
- #
379
- # @return [OpenStruct]
380
- #
381
- # @example
382
- # body = {
383
- # "city" => "Barcelona"
384
- # }
385
- #
386
- # session.shop.update_address(body)
387
- #
388
- def update_address(body)
389
- response, status = BeyondApi::Request.patch(@session, "/shop/address", body)
390
-
391
- handle_response(response, status)
392
- end
393
-
394
- #
395
- # A +PUT+ request is used to update a shop attribute. This operation is idempotent and will create a new shop attribute if required.
396
- #
397
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X PUT \
398
- # -H 'Content-Type: application/json' \
399
- # -H 'Authorization: Bearer <Access token>' \
400
- # -d '{
401
- # "value" : "new-value",
402
- # "public" : false
403
- # }'
404
- #
405
- # @beyond_api.scopes +shat:u+
406
- #
407
- # @param attribute_name [String] the attribute name
408
- # @param body [Hash] the request body
409
- #
410
- # @return [OpenStruct]
411
- #
412
- # @example
413
- # body = {
414
- # "value" => "new-value",
415
- # "public" => false
416
- # }
417
- #
418
- # session.shop.update_attribute("second-unknown-attribute-name", body)
419
- #
420
- def update_attribute(attribute_name, body)
421
- response, status = BeyondApi::Request.put(@session, "/shop/attributes/#{attribute_name}", body)
422
-
423
- handle_response(response, status)
424
- end
425
-
426
- #
427
- # 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.
428
- #
429
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/legal-notice' -i -X PUT \
430
- # -H 'Content-Type: application/json' \
431
- # -H 'Accept: application/json' \
432
- # -H 'Authorization: Bearer <Access token>' \
433
- # -d '{
434
- # "content" : "new legal content"
435
- # }'
436
- #
437
- # @beyond_api.scopes +lcnt:u+
438
- #
439
- # @param body [Hash] the request body
440
- #
441
- # @return [OpenStruct]
442
- #
443
- # @example
444
- # session.shop.update_legal_content(body)
445
- #
446
- def update_legal_content(body)
447
- response, status = BeyondApi::Request.put(@session, "/legal-content/legal-notice")
448
-
449
- handle_response(response, status)
450
- end
451
-
452
- #
453
- # A +PATCH+ request is used to update a legal resource partially with json content type.
454
- #
455
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X PATCH \
456
- # -H 'Content-Type: application/json' \
457
- # -H 'Accept: application/hal+json' \
458
- # -H 'Authorization: Bearer <Access token>' \
459
- # -d '{
460
- # "vatId" : "GB 111111111"
461
- # }'
462
- #
463
- # @beyond_api.scopes +legl:u+
464
- #
465
- # @param body [Hash] the request body
466
- #
467
- # @return [OpenStruct]
468
- #
469
- # @example
470
- # body = {
471
- # "vat_id" => "GB 111111111"
472
- # }
473
- #
474
- # session.shop.update_legal_details(body)
475
- #
476
- def update_legal_details(body)
477
- response, status = BeyondApi::Request.patch(@session, "/shop/legal")
478
-
479
- handle_response(response, status)
480
- end
481
-
482
- #
483
- # A +POST+ request is used to upload a shop image. The body of the request must contain the content of the image.
484
- #
485
- # $ curl --data-binary '@/home/epages/sample.png' 'https://api-shop.beyondshop.cloud/api/shop/images?fileName=sample.png&label=invoice logo' -X POST \
486
- # -H 'Content-Type: image/png' \
487
- # -H 'Authorization: Bearer <Access token>'
488
- #
489
- # @beyond_api.scopes +shim:c+
490
- #
491
- # @param image_path [String] the image path
492
- # @param image_name [String] the image name
493
- # @param label [String] the image label
494
- #
495
- # @return true
496
- #
497
- # @example
498
- # session.shop.upload_image("/home/epages/sample.png", "sample.png", "invoice logo")
499
- #
500
- def upload_image(image_path, image_name, label)
501
- content_type = case File.extname(image_path)
502
- when ".png"
503
- "image/png"
504
- when ".jpg", ".jpeg"
505
- "image/jpeg"
506
- when ".gif"
507
- "image/gif"
508
- end
509
- image_binary = File.binread(image_path)
510
-
511
- response, status = BeyondApi::Request.upload(@session, "/shop/images", image_binary, content_type, { file_name: image_name, label: label })
512
-
513
- handle_response(response, status, respond_with_true: true)
514
- end
515
88
  end
516
89
  end