Module: Novu::Api::Layouts

Included in:
Client
Defined in:
lib/novu/api/layouts.rb

Overview

Module Novu::Api::Layouts provides an API for managing layouts in the Novu application.

This module includes methods for creating, retrieving, updating, and deleting layouts. It also includes methods for setting and getting the default layout.

For more information on the Novu API(api.novu.co/api#/Layouts), see docs.novu.co/api/layout-creation/.

Instance Method Summary collapse

Instance Method Details

#create_layout(body) ⇒ _id: "_id", number

Creates a new layout.

@bodyparams:

Parameters:

  • `name` (String)

    User defined custom name and provided by the user that will name the Layout created.

  • `content` (String)

    User defined content for the layout.

  • `description` (String(optional))

    User description of the layout.

  • `variables` (Array(optional))

    User defined variables to render in the layout placeholders.

  • `isDefault` (Boolean(optional))

    User defined variables to render in the layout placeholders.

Returns:

  • (_id: "_id")

    The created layout id.

  • (number)

    status - The status code. Returns 201 if the layout has been successfully created.



23
24
25
# File 'lib/novu/api/layouts.rb', line 23

def create_layout(body)
  post("/layouts", body: body)
end

#delete_layout(layout_id) ⇒ Hash, number

Execute a soft delete of a layout given a certain ID.

@pathparams:

Parameters:

  • `layout_id` (Integer)

    The ID of the layout to delete.

Returns:

  • (Hash)

    The retrieved layout.

  • (number)

    status

    • Returns 204 if the layout has been deleted correctly.

    • Returns 404 if the layout with the layoutId provided does not exist in the database so it can not be deleted.

    • Returns 409 if either you are trying to delete a layout that is being used or a layout that is the default in the environment.



67
68
69
# File 'lib/novu/api/layouts.rb', line 67

def delete_layout(layout_id)
  delete("/layouts/#{layout_id}")
end

#layout(layout_id) ⇒ Hash, number

Retrieves the layout with the given ID.

Parameters:

  • `layout_id` (Integer)

    The ID of the layout to retrieve.

Returns:

  • (Hash)

    The retrieved layout.

  • (number)

    status

    • Returns 200 if the layout with the layoutId provided exists in the database.

    • Returns 404 The layout with the layoutId provided does not exist in the database.



53
54
55
# File 'lib/novu/api/layouts.rb', line 53

def layout(layout_id)
  get("/layouts/#{layout_id}")
end

#layouts(query = {}) ⇒ Hash, number

Returns a list of layouts that can be paginated using the ‘page` query parameter and filtered by the environment where it is executed from the organization the user belongs to.

@queryparams:

Parameters:

  • `page` (Integer(optional))

    Number of page for the pagination.

  • `pageSize` (Integer(optional))

    Size of page for the pagination.

  • `sortBy` (String(optional))

    Sort field. Currently only supported ‘createdAt`.

  • `orderBy` (Integer(optional))

    Direction of the sorting query param. Either ascending (1) or descending (-1).

Returns:

  • (Hash)

    The list of layouts that match the criteria of the query params are successfully returned.

  • (number)

    status

    • Returns 200 if successful

    • Returns 400 if Page size can not be larger than the page size limit.



40
41
42
# File 'lib/novu/api/layouts.rb', line 40

def layouts(query = {})
  get("/layouts", query: query)
end

#make_default_layout(layout_id) ⇒ number

Sets the default layout for the environment and updates to non default to the existing default layout (if any).

@pathparams:

Parameters:

  • `layout_id` (Integer)

    The ID of the layout to set the default.

Returns:

  • (number)

    status

    • Returns 204 if the selected layout has been set as the default for the environment.

    • Returns 404 if the layout with the layoutId provided does not exist in the database so it can not be set as the default for the environment.



101
102
103
# File 'lib/novu/api/layouts.rb', line 101

def make_default_layout(layout_id)
  post("/layouts/#{layout_id}/default")
end

#update_layout(layout_id, body) ⇒ Hash, number

Update the name, content and variables of a layout. Also change it to be default or no.

@pathparams:

Parameters:

  • `layout_id` (Integer)

    The ID of the layout to update.

  • `name` (String(optional))

    User defined custom name and provided by the user that will name the Layout updated.

  • `description` (String(optional))

    User defined description of the layout.

  • `content` (String(optional))

    User defined content for the layout.

  • `variables` (Array(optional))

    User defined variables to render in the layout placeholders.

  • `isDefault` (Boolean(optional))

    Variable that defines if the layout is chosen as default when creating a layout.

Returns:

  • (Hash)

    The updated layout.

  • (number)

    status

    • Returns 200 if the layout with the layoutId provided has been updated correctly.

    • Returns 400 if the payload provided or the URL param are not right.

    • Returns 404 if the layout with the layoutId provided does not exist in the database so it can not be updated.

    • Returns 409 if one default layout is needed. If you are trying to turn a default layout as not default, you should turn a different layout as default first and automatically it will be done by the system.



89
90
91
# File 'lib/novu/api/layouts.rb', line 89

def update_layout(layout_id, body)
  patch("/layouts/#{layout_id}", body: body)
end