Class: BeyondApi::Categories

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/categories.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 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>'

Examples:

@categories = session.categories.all(size: 100, 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:

  • catg:r



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

Examples:

body = {
  "name" => "Power Bars",
  "label" => "power-bar",
  "type" => "SMART",
  "query" => { "bool" => { "filter" => { "term" : { "tags" => "power-bar" } } } }
}
@category = session.categories.create(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • catg:c



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

Examples:

session.categories.delete("f461fb56-1984-4ade-bd4e-007c273cc923")

Parameters:

  • category_id (String)

    the category UUID

Returns:

  • true

Scopes:

  • catg:d



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

Examples:

@category = session.categories.find("27a94b71-9b17-4f06-9596-fbbf4d18021f")

Parameters:

  • category_id (String)

    the category UUID

Returns:

  • (OpenStruct)

Scopes:

  • catg:r



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

Examples:

body =  {
  "name" => "patched name",
  "type" => "MANUAL",
  "query" => {"bool" => { "filter" => [ { "terms" => { "id" => [ "6c449297-65fc-41aa-a49c-68a3561b33e5", "6c449297-65fc-41aa-a49c-68a3561b33e6" ] } } ] } }
}
@category = session.categories.update("49250b7a-79a8-48d0-a71c-fc417965928d", body)

Parameters:

  • category_id (String)

    the category UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • catg:u



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

Examples:

body = {
  "name" => "updated name",
  "label" => "updated-name",
  "type" => "MANUAL",
  "query" => { "bool" => { "filter" => [ { "terms" => { "id" => [ "6c449297-65fc-41aa-a49c-68a3561b33e5", "6c449297-65fc-41aa-a49c-68a3561b33e6" ] } } ] } }
}
@category = session.categories.update(category_id, body)

Parameters:

  • category_id (String)

    the category UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • catg:u



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