Class: BeyondApi::CategoriesView

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

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'

Examples:

@categories = session.categories_view.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)


26
27
28
# File 'lib/beyond_api/resources/categories_view.rb', line 26

def all(params = {})
  handle_all_request("/product-view/categories", :categories, params)
end

#find(category_id) ⇒ OpenStruct

A GET request is used to retrieve the details of a product category.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/23bb1430-6e82-40e4-9a92-4cb404da74a8' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'

Examples:

@category = session.categories_view.find("23bb1430-6e82-40e4-9a92-4cb404da74a8")

Parameters:

  • category_id (String)

    the category UUID

Returns:

  • (OpenStruct)


44
45
46
47
48
49
# File 'lib/beyond_api/resources/categories_view.rb', line 44

def find(category_id)
  response, status = BeyondApi::Request.get(@session,
                                            "/product-view/categories/#{category_id}")

  handle_response(response, status)
end

#preview(body, params = {}) ⇒ OpenStruct

A POST request is read-only and cannot create data. It is used to find products that match the filter criteria. Thus, it can be used to preview all products that are included in a category that shares the respective filter criteria.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/preview?page=0&size=10&sortBy=NEWEST_FIRST' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
  "filters" : [ {
    "key" : "manufacturer",
    "values" : [ "Grape Vineyard" ]
  }, {
    "key" : "all_tags",
    "values" : [ "Power Bar", "Bestseller", "High Protein" ]
  }, {
    "key" : "price_range",
    "min" : 3.7,
    "max" : 13.7
  } ]
}'

Examples:

body = {
  filters => [ 
    {
      key => "manufacturer",
      values => [ "Grape Vineyard" ]
    },
    {
      key => "all_tags",
      values => [ "Power Bar", "Bestseller", "High Protein" ]
    },
    {
      key => "price_range",
      min => 3.7,
      max => 13.7
    } 
  ]
}

@products = session.categories_view.preview(body, { size: 100, page: 0, sort_by: "NEWEST_FIRST" })

Parameters:

  • body (Hash)

    the request body

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

    a customizable set of options

Options Hash (params):

  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

  • :sort_by (String)

    the sorting applied to the list of products

Returns:

  • (OpenStruct)


100
101
102
103
104
105
106
107
# File 'lib/beyond_api/resources/categories_view.rb', line 100

def preview(body, params = {})
  response, status = BeyondApi::Request.post(@session,
                                             "/product-view/categories/preview",
                                             body,
                                             params)

  handle_response(response, status)
end

#products(category_id, params = {}) ⇒ OpenStruct

A GET request is used to list all products of a category.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/681beef2-cd3e-4ce3-8034-4d07c1184447/products' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'

Examples:

@products = session.categories_view.products("681beef2-cd3e-4ce3-8034-4d07c1184447", { size: 100, page: 0 })

Parameters:

  • category_id (String)

    the category 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)


125
126
127
128
129
# File 'lib/beyond_api/resources/categories_view.rb', line 125

def products(category_id, params = {})
  path = "/product-view/categories/#{category_id}/products"

  handle_all_request(path, :products, params)
end

#search_by_label(label) ⇒ OpenStruct

A GET request is used to find a product category by its unique label.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/search/find-by-label?label=power-bar' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'

Examples:

@category = session.categories_view.search_by_label("power-bar")

Parameters:

  • label (String)

    the label of the category

Returns:

  • (OpenStruct)


145
146
147
148
149
150
151
# File 'lib/beyond_api/resources/categories_view.rb', line 145

def search_by_label(label)
  response, status = BeyondApi::Request.get(@session,
                                            "/product-view/categories/search/find-by-label",
                                            { label: label })

  handle_response(response, status)
end

#search_by_product(body, params = {}) ⇒ OpenStruct

A POST request is used to search for categories a new product will be part of using the request body. An existing product can also be part of the call. This endpoint can handle all properties a product can have. This request is read-only and cannot create data.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/search/find-by-product' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'
    -d '{
  "tags" : [ "books" ],
  "manufacturer" : "The Standard Manufacturer",
  "salesPrice" : {
    "amount" : 10.0,
    "currency" : "EUR"
  }
}'

Examples:

body = {
  "tags" => [ "books" ],
  "manufacturer" => "The Standard Manufacturer",
  "sales_price" => {
    "amount" => 10.0,
    "currency" => "EUR"
  }
}

@categories = session.categories_view.search_by_product(body, { size: 100, page: 0 })

Parameters:

  • body (Hash)

    the request body

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

    a customizable set of options

Options Hash (params):

  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)


209
210
211
212
213
214
215
216
# File 'lib/beyond_api/resources/categories_view.rb', line 209

def search_by_product(body, params = {})
  response, status = BeyondApi::Request.post(@session,
                                             "/product-view/categories/search/find-by-product",
                                             body,
                                             params)

  handle_response(response, status)
end

#search_by_product_id(product_id, params = {}) ⇒ OpenStruct

A GET request is used to list all product categories a product is part of using the request parameter productId.

$ curl 'https://api-shop.beyondshop.cloud/api/product-view/categories/search/find-by-product?productId=ba68427f-603c-4741-9185-3b379f7769b5' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json'

Examples:

@category = session.categories_view.search_by_product_id("ba68427f-603c-4741-9185-3b379f7769b5")

Parameters:

  • product_id (String)

    the product UUID of the category

Returns:

  • (OpenStruct)


167
168
169
170
171
172
173
# File 'lib/beyond_api/resources/categories_view.rb', line 167

def search_by_product_id(product_id, params = {})
  response, status = BeyondApi::Request.get(@session,
                                            "/product-view/categories/search/find-by-product",
                                            params.merge(product_id: product_id))

  handle_response(response, status)
end