Skip to content

Commit d7ac07c

Browse files
author
Unai Abrisketa
committed
Add path variable
1 parent ba3a4a1 commit d7ac07c

File tree

14 files changed

+332
-105
lines changed

14 files changed

+332
-105
lines changed

lib/beyond_api/resources/orders.rb

Lines changed: 99 additions & 33 deletions
Large diffs are not rendered by default.

lib/beyond_api/resources/product_attribute_definitions.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class ProductAttributeDefinitions < Base
2424
# @product_attribute_definitions = session.product_attribute_definitions.all(size: 100, page: 0)
2525
#
2626
def all(params = {})
27-
handle_all_request("/product-attribute-definitions", :product_attribute_definitions, params)
27+
path = "/product-attribute-definitions"
28+
29+
handle_all_request(path, :product_attribute_definitions, params)
2830
end
2931

3032
#
@@ -56,7 +58,11 @@ def all(params = {})
5658
# @product_attribute_definition = session.product_attribute_definitions.create(body)
5759
#
5860
def create(body)
59-
response, status = BeyondApi::Request.post(@session, "/product-attribute-definitions", body)
61+
path = "/product-attribute-definitions"
62+
63+
response, status = BeyondApi::Request.post(@session,
64+
path,
65+
body)
6066

6167
handle_response(response, status)
6268
end
@@ -77,7 +83,10 @@ def create(body)
7783
# session.product_attribute_definitions.delete("color")
7884
#
7985
def delete(product_attribute_name)
80-
response, status = BeyondApi::Request.delete(@session, "/product-attribute-definitions/#{product_attribute_name}")
86+
path = "/product-attribute-definitions/#{product_attribute_name}"
87+
88+
response, status = BeyondApi::Request.delete(@session,
89+
path)
8190

8291
handle_response(response, status, respond_with_true: true)
8392
end
@@ -98,7 +107,10 @@ def delete(product_attribute_name)
98107
# @product_attribute_definition = session.product_attribute_definitions.find("filling_capacity")
99108
#
100109
def find(product_attribute_name)
101-
response, status = BeyondApi::Request.get(@session, "/product-attribute-definitions/#{product_attribute_name}")
110+
path = "/product-attribute-definitions/#{product_attribute_name}"
111+
112+
response, status = BeyondApi::Request.get(@session,
113+
path)
102114

103115
handle_response(response, status)
104116
end

lib/beyond_api/resources/products.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Products < Base
4343
# @products = session.products.all(size: 100, page: 0)
4444
#
4545
def all(params = {})
46-
handle_all_request("/products", :products, params)
46+
path = "/products"
47+
48+
handle_all_request(path, :products, params)
4749
end
4850

4951
#
@@ -166,8 +168,10 @@ def all(params = {})
166168
# @product = session.products.create(body)
167169
#
168170
def create(body)
171+
path = "/products"
172+
169173
response, status = BeyondApi::Request.post(@session,
170-
"/products",
174+
path,
171175
body)
172176

173177
handle_response(response, status)
@@ -190,8 +194,10 @@ def create(body)
190194
# session.products.delete("c06c61af-f99a-4698-90fa-8c3199ca732f")
191195
#
192196
def delete(product_id)
197+
path = "/products/#{product_id}"
198+
193199
response, status = BeyondApi::Request.delete(@session,
194-
"/products/#{product_id}")
200+
path)
195201

196202
handle_response(response, status, respond_with_true: true)
197203
end
@@ -214,8 +220,10 @@ def delete(product_id)
214220
# @product = session.products.find("75ebcb57-aefb-4963-8225-060c528e070d")
215221
#
216222
def find(product_id)
223+
path = "/products/#{product_id}"
224+
217225
response, status = BeyondApi::Request.get(@session,
218-
"/products/#{product_id}")
226+
path)
219227

220228
handle_response(response, status)
221229
end
@@ -251,7 +259,11 @@ def find(product_id)
251259
# @product = session.products.update("b69e3f47-03b8-40d2-843c-ae89a3d9bcdd", body)
252260
#
253261
def update(product_id, body)
254-
response, status = BeyondApi::Request.patch(@session, "/products/#{product_id}", body)
262+
path = "/products/#{product_id}"
263+
264+
response, status = BeyondApi::Request.patch(@session,
265+
path,
266+
body)
255267

256268
handle_response(response, status)
257269
end
@@ -275,8 +287,10 @@ def update(product_id, body)
275287
# session.products.assign_variation_images_differentiator("f205294b-17dc-4f75-8b5e-5df72abb96df", "491fedf4-37a9-4bcf-98b8-cff2f82879b7")
276288
#
277289
def assign_variation_attribute_as_differentiator(product_id, variation_attribute_id)
290+
path = "/products/#{product_id}/variation-attributes/#{variation_attribute_id}/make-differentiator"
291+
278292
response, status = BeyondApi::Request.post(@session,
279-
"/products/#{product_id}/variation-attributes/#{variation_attribute_id}/make-differentiator")
293+
path)
280294

281295
handle_response(response, status, respond_with_true: true)
282296
end

lib/beyond_api/resources/products_view.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class ProductsView < Base
2323
# @products = session.products_view.all(page: 0, size: 100)
2424
#
2525
def all(params = {})
26-
handle_all_request("/product-view/products", :products, params)
26+
path = "/product-view/products"
27+
28+
handle_all_request(path, :products, params)
2729
end
2830

2931
#
@@ -39,8 +41,10 @@ def all(params = {})
3941
# @tags = session.products_view.available_tags
4042
#
4143
def available_tags
44+
path = "/product-view/products/search/find-available-tags"
45+
4246
response, status = BeyondApi::Request.get(@session,
43-
"/product-view/products/search/find-available-tags")
47+
path)
4448

4549
handle_response(response, status)
4650
end
@@ -61,8 +65,10 @@ def available_tags
6165
# @product = session.products_view.find("f75f8fb2-5a48-4d94-aad6-3d3692c06472")
6266
#
6367
def find(product_id)
68+
path = "/product-view/products/#{product_id}"
69+
6470
response, status = BeyondApi::Request.get(@session,
65-
"/product-view/products/#{product_id}")
71+
path)
6672

6773
handle_response(response, status)
6874
end
@@ -84,8 +90,10 @@ def find(product_id)
8490
# @products = session.products_view.search_by_tag("number0", {page: 0, size: 100})
8591
#
8692
def search_by_tag(tag, params = {})
93+
path = "/product-view/products/search/find-by-tags"
94+
8795
response, status = BeyondApi::Request.get(@session,
88-
"/product-view/products/search/find-by-tags",
96+
path,
8997
params.merge(tag: tag))
9098

9199
handle_response(response, status)
@@ -108,8 +116,10 @@ def search_by_tag(tag, params = {})
108116
# @products = session.products_view.search_by_term("search snippet", {page: 0, size: 100})
109117
#
110118
def search_by_term(term, params = {})
119+
path = "/product-view/products/search/find-by-term"
120+
111121
response, status = BeyondApi::Request.get(@session,
112-
"/product-view/products/search/find-by-term",
122+
path,
113123
params.merge(query: term))
114124

115125
handle_response(response, status)

lib/beyond_api/resources/script_tags.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class ScriptTags < Base
2222
# @script_tags = session.script_tags.all(size: 20, page: 0)
2323
#
2424
def all(params = {})
25-
handle_all_request("/script-tags", :script_tags, params)
25+
path = "/script-tags"
26+
27+
handle_all_request(path, :script_tags, params)
2628
end
2729

2830
#
@@ -39,8 +41,10 @@ def all(params = {})
3941
# @script_tag = session.script_tags.find("df170ab1-13ae-4955-8b51-2478246acf59")
4042
#
4143
def find(script_tag_id)
44+
path = "/script-tags/#{script_tag_id}"
45+
4246
response, status = BeyondApi::Request.get(@session,
43-
"/script-tags/#{script_tag_id}")
47+
path)
4448

4549
handle_response(response, status)
4650
end
@@ -66,8 +70,10 @@ def find(script_tag_id)
6670
# @script_tag = session.script_tags.create("https://example.org/js/fancy-script.js")
6771
#
6872
def create(script_tag_url)
73+
path = "/script-tags"
74+
6975
response, status = BeyondApi::Request.post(@session,
70-
"/script-tags",
76+
path,
7177
{ script_url: script_tag_url })
7278

7379
handle_response(response, status)
@@ -89,8 +95,10 @@ def create(script_tag_url)
8995
# session.script_tags.delete("4a9f7776-d74d-4311-8ddb-121bd5407520")
9096
#
9197
def delete(script_tag_id)
98+
path = "/script-tags/#{script_tag_id}"
99+
92100
response, status = BeyondApi::Request.delete(@session,
93-
"/script-tags/#{script_tag_id}")
101+
path)
94102

95103
handle_response(response, status, respond_with_true: true)
96104
end
@@ -117,8 +125,10 @@ def delete(script_tag_id)
117125
# @script_tag = session.script_tags.create("https://example.org/scripts/someOtherScript.js")
118126
#
119127
def update(script_tag_id, script_tag_url)
128+
path = "/script-tags/#{script_tag_id}"
129+
120130
response, status = BeyondApi::Request.put(@session,
121-
"/script-tags/#{script_tag_id}",
131+
path,
122132
{ script_url: script_tag_url })
123133

124134
handle_response(response, status)

lib/beyond_api/resources/shipping_zones.rb

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class ShippingZones < Base
2424
# @shipping_zones = session.shipping_zones.all(size: 20, page: 0)
2525
#
2626
def all(params = {})
27-
handle_all_request("/shipping-zones", :shipping_zones, params)
27+
path = "/shipping-zones"
28+
29+
handle_all_request(path, :shipping_zones, params)
2830
end
2931

3032
#
@@ -52,8 +54,10 @@ def all(params = {})
5254
# @shipping_zone = session.shipping_zones.create(body)
5355
#
5456
def create(body)
57+
path = "/shipping-zones"
58+
5559
response, status = BeyondApi::Request.post(@session,
56-
"/shipping-zones",
60+
path,
5761
body)
5862

5963
handle_response(response, status)
@@ -107,8 +111,10 @@ def create(body)
107111
# @shipping_zone = session.shipping_zones.create_shipping_method("905e981c-1489-45af-9138-0a7dc1f0b085", body)
108112
#
109113
def create_shipping_method(shipping_zone_id, body)
114+
path = "/shipping-zones/#{shipping_zone_id}/shipping-methods"
115+
110116
response, status = BeyondApi::Request.post(@session,
111-
"/shipping-zones/#{shipping_zone_id}/shipping-methods",
117+
path,
112118
body)
113119

114120
handle_response(response, status)
@@ -130,8 +136,10 @@ def create_shipping_method(shipping_zone_id, body)
130136
# session.shipping_zones.delete("c871b402-b6d9-4c6d-b76c-440f61175805")
131137
#
132138
def delete(shipping_zone_id)
139+
path = "/shipping-zones/#{shipping_zone_id}"
140+
133141
response, status = BeyondApi::Request.delete(@session,
134-
"/shipping-zones/#{shipping_zone_id}")
142+
path)
135143

136144
handle_response(response, status, respond_with_true: true)
137145
end
@@ -153,8 +161,10 @@ def delete(shipping_zone_id)
153161
# session.shipping_zones.delete_shipping_method("61c14c3c-ce26-4524-9713-f2ede7ff22fa", "d2eee203-a1c6-4035-8e7a-74bb77cfde47")
154162
#
155163
def delete_shipping_method(shipping_zone_id, shipping_method_id)
164+
path = "/shipping-zones/#{shipping_zone_id}/shipping_methods/#{shipping_method_id}"
165+
156166
response, status = BeyondApi::Request.delete(@session,
157-
"/shipping-zones/#{shipping_zone_id}/shipping_methods/#{shipping_method_id}")
167+
path)
158168

159169
handle_response(response, status, respond_with_true: true)
160170
end
@@ -176,8 +186,10 @@ def delete_shipping_method(shipping_zone_id, shipping_method_id)
176186
# @shipping_zone = session.shipping_zones.find("27914098-c1f6-46aa-9e78-c7ac873e25b3")
177187
#
178188
def find(shipping_zone_id)
189+
path = "/shipping-zones/#{shipping_zone_id}"
190+
179191
response, status = BeyondApi::Request.get(@session,
180-
"/shipping-zones/#{shipping_zone_id}")
192+
path)
181193

182194
handle_response(response, status)
183195
end
@@ -194,8 +206,10 @@ def find(shipping_zone_id)
194206
# @serviceable_countries = session.shipping_zones.find_serviceable_countries
195207
#
196208
def find_serviceable_countries
209+
path = "/shipping-zones/search/find-all-serviceable-countries"
210+
197211
response, status = BeyondApi::Request.get(@session,
198-
"/shipping-zones/search/find-all-serviceable-countries")
212+
path)
199213

200214
handle_response(response, status)
201215
end
@@ -217,8 +231,10 @@ def find_serviceable_countries
217231
# @shipping_method = session.shipping_zones.shipping_method("61780dd6-0150-4fcf-953c-d10c52bab4ab", "13bd1fc9-706c-4774-923a-484a41aaab89")
218232
#
219233
def shipping_method(shipping_zone_id, shipping_method_id)
234+
path = "/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}"
235+
220236
response, status = BeyondApi::Request.get(@session,
221-
"/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")
237+
path)
222238

223239
handle_response(response, status)
224240
end
@@ -242,8 +258,10 @@ def shipping_method(shipping_zone_id, shipping_method_id)
242258
# @shipping_methods = session.shipping_zones.shipping_methods("8cc24465-3573-4eca-8323-b076bb724080", { size: 20, page: 0 })
243259
#
244260
def shipping_methods(shipping_zone_id, params = {})
261+
path = "/shipping-zones/#{shipping_zone_id}/shipping-methods"
262+
245263
response, status = BeyondApi::Request.get(@session,
246-
"/shipping-zones/#{shipping_zone_id}/shipping-methods",
264+
path,
247265
params)
248266

249267
handle_response(response, status)
@@ -271,10 +289,12 @@ def shipping_methods(shipping_zone_id, params = {})
271289
# session.shipping_zones.sort(shipping_zone_ids)
272290
#
273291
def sort(shipping_zone_ids)
292+
path = "/shipping-zones"
293+
274294
body = shipping_zone_ids.map { |id| "#{session.api_url}/shipping-zones/#{id}" }
275295

276296
response, status = BeyondApi::Request.put(@session,
277-
"/shipping-zones",
297+
path,
278298
body)
279299

280300
handle_response(response, status, respond_with_true: true)
@@ -298,8 +318,10 @@ def sort(shipping_zone_ids)
298318
# session.shipping_zones.sort_shipping_methods(shipping_zone_id)
299319
#
300320
def sort_shipping_methods(shipping_zone_id)
321+
path = "/shipping-zones/#{shipping_zone_id}/shipping-methods"
322+
301323
response, status = BeyondApi::Request.put(@session,
302-
"/shipping-zones/#{shipping_zone_id}/shipping-methods")
324+
path)
303325

304326
handle_response(response, status)
305327
end
@@ -330,8 +352,10 @@ def sort_shipping_methods(shipping_zone_id)
330352
# @shipping_zone = session.shipping_zones.update("727b3cbf-01b1-442a-bd5c-94c51901f090", body)
331353
#
332354
def update(shipping_zone_id, body)
355+
path = "/shipping-zones/#{shipping_zone_id}"
356+
333357
response, status = BeyondApi::Request.put(@session,
334-
"/shipping-zones/#{shipping_zone_id}",
358+
path,
335359
body)
336360

337361
handle_response(response, status)

0 commit comments

Comments
 (0)