Class: BeyondApi::Categories
- Includes:
- Utils
- Defined in:
- lib/beyond_api/resources/categories.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(params = {}) ⇒ OpenStruct
A
GET
request is used to list all available categories in a paged manner. -
#create(body) ⇒ OpenStruct
A
POST
request is used to create a category. -
#delete(category_id) ⇒ Object
A
DELETE
request is used to delete a category. -
#find(category_id) ⇒ OpenStruct
A
GET
request is used to retrieve the details of a category. -
#patch(category_id, body) ⇒ OpenStruct
A
PATCH
request is used to update a category partially with json patch content type. -
#update(category_id, body) ⇒ OpenStruct
A
PUT
request is issued to update all category properties with application/json content type.
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 available categories in a paged manner.
$ curl 'https://api-shop.beyondshop.cloud/api/categories' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
28 29 30 |
# File 'lib/beyond_api/resources/categories.rb', line 28 def all(params = {}) handle_all_request("/categories", :categories, params) end |
#create(body) ⇒ OpenStruct
A POST
request is used to create a category.
$ curl 'https://api-shop.beyondshop.cloud/api/categories' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access token>' \
-d '{"name":"Power Bars","label":"power-bar","type":"SMART","query":{"bool":{"filter":{"term":{"tags":"power-bar"}}}}}'
55 56 57 58 59 |
# File 'lib/beyond_api/resources/categories.rb', line 55 def create(body) response, status = BeyondApi::Request.post(@session, "/categories", body) handle_response(response, status) end |
#delete(category_id) ⇒ Object
A DELETE
request is used to delete a category.
$ curl 'https://api-shop.beyondshop.cloud/api/categories/f461fb56-1984-4ade-bd4e-007c273cc923' -i -X DELETE \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
77 78 79 80 81 |
# File 'lib/beyond_api/resources/categories.rb', line 77 def delete(category_id) response, status = BeyondApi::Request.delete(@session, "/categories/#{category_id}") handle_response(response, status, respond_with_true: true) end |
#find(category_id) ⇒ OpenStruct
A GET
request is used to retrieve the details of a category.
$ curl 'https://api-shop.beyondshop.cloud/api/categories/27a94b71-9b17-4f06-9596-fbbf4d18021f' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
100 101 102 103 104 |
# File 'lib/beyond_api/resources/categories.rb', line 100 def find(category_id) response, status = BeyondApi::Request.get(@session, "/categories/#{category_id}") handle_response(response, status) end |
#patch(category_id, body) ⇒ OpenStruct
A PATCH
request is used to update a category partially with json patch content type.
$ curl 'https://api-shop.beyondshop.cloud/api/categories/49250b7a-79a8-48d0-a71c-fc417965928d' -i -X PATCH \
-H 'Content-Type: application/json-patch+json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>' \
-d '{"name":"patched name","type":"MANUAL","query":{"bool":{"filter":[{"terms":{"id":["6c449297-65fc-41aa-a49c-68a3561b33e5","6c449297-65fc-41aa-a49c-68a3561b33e6"]}}]}}}'
130 131 132 133 134 |
# File 'lib/beyond_api/resources/categories.rb', line 130 def patch(category_id, body) response, status = BeyondApi::Request.patch(@session, "/categories/#{category_id}", body) handle_response(response, status) end |
#update(category_id, body) ⇒ OpenStruct
A PUT
request is issued to update all category properties with application/json content type.
$ curl 'https://api-shop.beyondshop.cloud/api/categories/cb2058dc-871a-4e64-83ac-39a0be9e6f82' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>' \
-d '{"name":"updated name","label":"updated-name","type":"MANUAL","query":{"bool":{"filter":[{"terms":{"id":["6c449297-65fc-41aa-a49c-68a3561b33e5","6c449297-65fc-41aa-a49c-68a3561b33e6"]}}]}}}'
161 162 163 164 165 |
# File 'lib/beyond_api/resources/categories.rb', line 161 def update(category_id, body) response, status = BeyondApi::Request.put(@session, "/categories/#{category_id}", body) handle_response(response, status) end |