Class: BeyondApi::ShippingZones
- Includes:
- Utils
- Defined in:
- lib/beyond_api/resources/shipping_zones.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(params = {}) ⇒ OpenStruct
A
GET
request is used to list all shipping zones in a paged way. -
#create(body) ⇒ OpenStruct
A
POST
request is used to create a shipping zone. -
#create_shipping_method(shipping_zone_id, body) ⇒ OpenStruct
A
POST
request is used to create a shipping method in a shipping zone. -
#delete(shipping_zone_id) ⇒ Object
A
DELETE
request is used to delete a shipping zone. -
#delete_shipping_method(shipping_zone_id, shipping_method_id) ⇒ Object
A
DELETE
request is used to delete a shipping method in a shipping zone. -
#find(shipping_zone_id) ⇒ OpenStruct
A
GET
request is used to retrieve the details of a shipping zone. -
#find_serviceable_countries ⇒ OpenStruct
A
GET
request is used to find the serviceable countries. -
#shipping_method(shipping_zone_id, shipping_method_id) ⇒ OpenStruct
A
GET
request is used to retrieve the details of a shipping method in a shipping zone. -
#shipping_methods(shipping_zone_id, params = {}) ⇒ OpenStruct
A
GET
request is used to list all shipping-methods of a shipping zone in a paged way. -
#sort(shipping_zone_ids) ⇒ OpenStruct
A
PUT
request is used to sort the shipping zones. -
#sort_shipping_methods(shipping_zone_id) ⇒ OpenStruct
A
PUT
request is used to sort the shipping methods inside a shipping zone. -
#update(shipping_zone_id, body) ⇒ OpenStruct
A
PUT
request is used to update a shipping zone. -
#update_shipping_method(shipping_zone_id, shipping_method_id, body) ⇒ OpenStruct
A
PUT
request is used to update a shipping method in a shipping zone.
Methods included from Utils
#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct
Methods inherited from Base
Constructor Details
This class inherits a constructor from BeyondApi::Base
Instance Method Details
#all(params = {}) ⇒ OpenStruct
A GET
request is used to list all shipping zones in a paged way.
26 27 28 29 30 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 26 def all(params = {}) path = "/shipping-zones" handle_all_request(path, :shipping_zones, params) end |
#create(body) ⇒ OpenStruct
A POST
request is used to create a shipping zone.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"name" : "BE-NL-LU",
"serviceableCountries" : [ "BE", "NL", "LU" ]
}'
56 57 58 59 60 61 62 63 64 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 56 def create(body) path = "/shipping-zones" response, status = BeyondApi::Request.post(@session, path, body) handle_response(response, status) end |
#create_shipping_method(shipping_zone_id, body) ⇒ OpenStruct
A POST
request is used to create a shipping method in a shipping zone.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/905e981c-1489-45af-9138-0a7dc1f0b085/shipping-methods' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"name" : "Standard Shipping 2",
"description" : "Standard Shipping",
"taxClass" : "REGULAR",
"freeShippingValue" : {
"taxModel" : "GROSS",
"currency" : "EUR",
"amount" : 400
},
"fixedPrice" : {
"taxModel" : "GROSS",
"currency" : "EUR",
"amount" : "19.99"
}
}'
113 114 115 116 117 118 119 120 121 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 113 def create_shipping_method(shipping_zone_id, body) path = "/shipping-zones/#{shipping_zone_id}/shipping-methods" response, status = BeyondApi::Request.post(@session, path, body) handle_response(response, status) end |
#delete(shipping_zone_id) ⇒ Object
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.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/c871b402-b6d9-4c6d-b76c-440f61175805' -i -X DELETE \
-H 'Authorization: Bearer <Access token>'
138 139 140 141 142 143 144 145 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 138 def delete(shipping_zone_id) path = "/shipping-zones/#{shipping_zone_id}" response, status = BeyondApi::Request.delete(@session, path) handle_response(response, status, respond_with_true: true) end |
#delete_shipping_method(shipping_zone_id, shipping_method_id) ⇒ Object
A DELETE
request is used to delete a shipping method in a shipping zone. You cannot delete the last shipping method of a shop.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/61c14c3c-ce26-4524-9713-f2ede7ff22fa/shipping-methods/d2eee203-a1c6-4035-8e7a-74bb77cfde47' -i -X DELETE \
-H 'Authorization: Bearer <Access token>'
163 164 165 166 167 168 169 170 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 163 def delete_shipping_method(shipping_zone_id, shipping_method_id) path = "/shipping-zones/#{shipping_zone_id}/shipping_methods/#{shipping_method_id}" response, status = BeyondApi::Request.delete(@session, path) handle_response(response, status, respond_with_true: true) end |
#find(shipping_zone_id) ⇒ OpenStruct
A GET
request is used to retrieve the details of a shipping zone.
188 189 190 191 192 193 194 195 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 188 def find(shipping_zone_id) path = "/shipping-zones/#{shipping_zone_id}" response, status = BeyondApi::Request.get(@session, path) handle_response(response, status) end |
#find_serviceable_countries ⇒ OpenStruct
A GET
request is used to find the serviceable countries.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/search/find-all-serviceable-countries' -i -X GET \
-H 'Accept: application/hal+json'
208 209 210 211 212 213 214 215 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 208 def find_serviceable_countries path = "/shipping-zones/search/find-all-serviceable-countries" response, status = BeyondApi::Request.get(@session, path) handle_response(response, status) end |
#shipping_method(shipping_zone_id, shipping_method_id) ⇒ OpenStruct
A GET
request is used to retrieve the details of a shipping method in a shipping zone.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/61780dd6-0150-4fcf-953c-d10c52bab4ab/shipping-methods/13bd1fc9-706c-4774-923a-484a41aaab89' -i -X GET \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
233 234 235 236 237 238 239 240 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 233 def shipping_method(shipping_zone_id, shipping_method_id) path = "/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}" response, status = BeyondApi::Request.get(@session, path) handle_response(response, status) end |
#shipping_methods(shipping_zone_id, params = {}) ⇒ OpenStruct
A GET
request is used to list all shipping-methods of a shipping zone in a paged way.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/8cc24465-3573-4eca-8323-b076bb724080/shipping-methods' -i -X GET \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
260 261 262 263 264 265 266 267 268 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 260 def shipping_methods(shipping_zone_id, params = {}) path = "/shipping-zones/#{shipping_zone_id}/shipping-methods" response, status = BeyondApi::Request.get(@session, path, params) handle_response(response, status) end |
#sort(shipping_zone_ids) ⇒ OpenStruct
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 The request must contain URIs for all shipping zones of the given page.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones' -i -X PUT \
-H 'Content-Type: text/uri-list' \
-H 'Authorization: Bearer <Access token>' \
-d 'https://api-shop.beyondshop.cloud/api/shipping-zones/9fa80513-be11-494f-ac01-61832e0d7808
https://api-shop.beyondshop.cloud/api/shipping-zones/f0911d4c-1ab0-4bbd-88e3-cb675cbb7da7
https://api-shop.beyondshop.cloud/api/shipping-zones/ef2e7cb7-820e-4d62-b361-12240f635164'
291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 291 def sort(shipping_zone_ids) path = "/shipping-zones" body = shipping_zone_ids.map { |id| "#{session.api_url}/shipping-zones/#{id}" } response, status = BeyondApi::Request.put(@session, path, body) handle_response(response, status, respond_with_true: true) end |
#sort_shipping_methods(shipping_zone_id) ⇒ OpenStruct
A PUT
request is used to sort the shipping methods inside a shipping zone. 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.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/e54af33b-fadc-4524-8eec-7e0b3e20f625/shipping-methods' -i -X PUT \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
320 321 322 323 324 325 326 327 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 320 def sort_shipping_methods(shipping_zone_id) path = "/shipping-zones/#{shipping_zone_id}/shipping-methods" response, status = BeyondApi::Request.put(@session, path) handle_response(response, status) end |
#update(shipping_zone_id, body) ⇒ OpenStruct
A PUT
request is used to update a shipping zone.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/727b3cbf-01b1-442a-bd5c-94c51901f090' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"name" : "BENELUX region",
"serviceableCountries" : [ "BE", "NL", "LU", "DE" ]
}'
354 355 356 357 358 359 360 361 362 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 354 def update(shipping_zone_id, body) path = "/shipping-zones/#{shipping_zone_id}" response, status = BeyondApi::Request.put(@session, path, body) handle_response(response, status) end |
#update_shipping_method(shipping_zone_id, shipping_method_id, body) ⇒ OpenStruct
A PUT
request is used to update a shipping method in a shipping zone.
$ curl 'https://api-shop.beyondshop.cloud/api/shipping-zones/c4137d8b-3dd1-4b73-91f0-32f1433c8195/shipping-methods/25df7018-a7a2-4903-85fa-6a3a73ae40b2' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"name" : "Express",
"description" : "Shipping overnight. Delivery on the next day.",
"taxClass" : "REGULAR",
"freeShippingValue" : {
"currency" : "EUR",
"amount" : 200
},
"fixedPrice" : {
"taxModel" : "GROSS",
"currency" : "EUR",
"amount" : 25
}
}'
410 411 412 413 414 415 416 417 418 |
# File 'lib/beyond_api/resources/shipping_zones.rb', line 410 def update_shipping_method(shipping_zone_id, shipping_method_id, body) path = "/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}" response, status = BeyondApi::Request.put(@session, path, body) handle_response(response, status) end |