Class: BeyondApi::ShippingZones

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/shipping_zones.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

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

#initialize

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.

Examples:

@shipping_zones = session.shipping_zones.all(size: 20, page: 0)

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:



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" ]
}'

Examples:

body = {
  "name" => "BE-NL-LU",
  "serviceableCountries" => [ "BE", "NL", "LU" ]
}
@shipping_zone = session.shipping_zones.create(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shpz:c



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"
  }
}'

Examples:

body = {
  "name" => "Standard Shipping 2",
  "description" => "Standard Shipping",
  "taxClass" => "REGULAR",
  "freeShippingValue" => {
    "taxModel" => "GROSS",
    "currency" => "EUR",
    "amount" => 400
  },
  "fixedPrice" => {
    "taxModel" => "GROSS",
    "currency" => "EUR",
    "amount" => "19.99"
  }
}
@shipping_method = session.shipping_zones.create_shipping_method("905e981c-1489-45af-9138-0a7dc1f0b085", body)

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shpz:u



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>'

Examples:

session.shipping_zones.delete("c871b402-b6d9-4c6d-b76c-440f61175805")

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

Returns:

  • true

Scopes:

  • shpz:d



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>'

Examples:

session.shipping_zones.delete_shipping_method("61c14c3c-ce26-4524-9713-f2ede7ff22fa", "d2eee203-a1c6-4035-8e7a-74bb77cfde47")

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • shipping_method_id (String)

    the shipping method UUID

Returns:

  • true

Scopes:

  • shpz:u



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.

Examples:

@shipping_zone = session.shipping_zones.find("27914098-c1f6-46aa-9e78-c7ac873e25b3")

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

Returns:

  • (OpenStruct)

Scopes:



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_countriesOpenStruct

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'

Examples:

@serviceable_countries = session.shipping_zones.find_serviceable_countries

Returns:

  • (OpenStruct)


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>'

Examples:

@shipping_method = session.shipping_zones.shipping_method("61780dd6-0150-4fcf-953c-d10c52bab4ab", "13bd1fc9-706c-4774-923a-484a41aaab89")

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • shipping_method_id (String)

    the shipping method UUID

Returns:

  • (OpenStruct)

Scopes:

  • shpz:r



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>'

Examples:

@shipping_methods = session.shipping_zones.shipping_methods("8cc24465-3573-4eca-8323-b076bb724080", { size: 20, page: 0 })

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:

  • shpz:r



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'

Examples:

shipping_zone_ids = ["9fa80513-be11-494f-ac01-61832e0d7808", "f0911d4c-1ab0-4bbd-88e3-cb675cbb7da7", "ef2e7cb7-820e-4d62-b361-12240f635164"]
session.shipping_zones.sort(shipping_zone_ids)

Parameters:

  • shipping_zone_ids (Array)

    the list of shipping zone UUIDs

Returns:

  • (OpenStruct)

Scopes:

  • shpz:u



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>'

Examples:

session.shipping_zones.sort_shipping_methods(shipping_zone_id)

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

Returns:

  • (OpenStruct)

Scopes:

  • shpz:r



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" ]
}'

Examples:

body = {
  "name" => "BENELUX region",
  "serviceableCountries" => [ "BE", "NL", "LU", "DE" ]
}
@shipping_zone = session.shipping_zones.update("727b3cbf-01b1-442a-bd5c-94c51901f090", body)

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • body (String)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shpz:u



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
    }
  }'

Examples:

body = {
  "name" : "Express",
  "description" : "Shipping overnight. Delivery on the next day.",
  "taxClass" : "REGULAR",
  "freeShippingValue" : {
    "currency" : "EUR",
    "amount" : 200
  },
  "fixedPrice" : {
    "taxModel" : "GROSS",
    "currency" : "EUR",
    "amount" : 25
  }
}
@shipping_method = session.shipping_zones.update_shipping_method("c4137d8b-3dd1-4b73-91f0-32f1433c8195", "25df7018-a7a2-4903-85fa-6a3a73ae40b2", body)

Parameters:

  • shipping_zone_id (String)

    the shipping zone UUID

  • shipping_method_id (String)

    the shipping method UUID

  • body (String)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shpz:u



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