Class: Courier::Resources::Tenants::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/tenants/templates.rb,
lib/courier/resources/tenants/templates/versions.rb,
sig/courier/resources/tenants/templates.rbs,
sig/courier/resources/tenants/templates/versions.rbs

Overview

Manage the templates and template versions scoped to a single tenant, including the ones authored in the embedded designer.

Defined Under Namespace

Classes: Versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Templates

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Templates.

Parameters:



181
182
183
184
# File 'lib/courier/resources/tenants/templates.rb', line 181

def initialize(client:)
  @client = client
  @versions = Courier::Resources::Tenants::Templates::Versions.new(client: client)
end

Instance Attribute Details

#versions ⇒ Courier::Resources::Tenants::Templates::Versions (readonly)

Manage the templates and template versions scoped to a single tenant, including the ones authored in the embedded designer.



12
13
14
# File 'lib/courier/resources/tenants/templates.rb', line 12

def versions
  @versions
end

Instance Method Details

#delete(template_id, tenant_id:, request_options: {}) ⇒ nil

Deletes a tenant's notification template by id. Sends for that tenant then use the workspace template registered under the same id.

Parameters:

  • template_id (String) —

    Id of the template to remove from the tenant.

  • tenant_id (String) —

    Id of the tenant that owns the template.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/courier/resources/tenants/templates.rb', line 84

def delete(template_id, params)
  parsed, options = Courier::Tenants::TemplateDeleteParams.dump_request(params)
  tenant_id =
    parsed.delete(:tenant_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["tenants/%1$s/templates/%2$s", tenant_id, template_id],
    model: NilClass,
    options: options
  )
end

#list(tenant_id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::Tenants::TemplateListResponse

Lists a tenant's notification templates, each carrying its version and published timestamp. Paged.

Parameters:

  • tenant_id (String) —

    Id of the tenant for which to retrieve the templates.

  • cursor (String, nil) —

    Continue the pagination with the next cursor

  • limit (Integer, nil) —

    The number of templates to return (defaults to 20, maximum value of 100)

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/courier/resources/tenants/templates.rb', line 58

def list(tenant_id, params = {})
  parsed, options = Courier::Tenants::TemplateListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["tenants/%1$s/templates", tenant_id],
    query: query,
    model: Courier::Models::Tenants::TemplateListResponse,
    options: options
  )
end

#publish(template_id, tenant_id:, version: nil, request_options: {}) ⇒ Courier::Models::PostTenantTemplatePublishResponse

Some parameter documentations has been truncated, see Models::Tenants::TemplatePublishParams for more details.

Publishes a version of a tenant's notification template, making it the content that tenant's sends render from until you publish another.

Parameters:

  • template_id (String) —

    Path param: Id of the template to be published.

  • tenant_id (String) —

    Path param: Id of the tenant that owns the template.

  • version (String) —

    Body param: The version of the template to publish (e.g., "v1", "v2", "latest").

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/courier/resources/tenants/templates.rb', line 117

def publish(template_id, params)
  parsed, options = Courier::Tenants::TemplatePublishParams.dump_request(params)
  tenant_id =
    parsed.delete(:tenant_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["tenants/%1$s/templates/%2$s/publish", tenant_id, template_id],
    body: parsed,
    model: Courier::PostTenantTemplatePublishResponse,
    options: options
  )
end

#replace(template_id, tenant_id:, template:, published: nil, request_options: {}) ⇒ Courier::Models::PutTenantTemplateResponse

Some parameter documentations has been truncated, see Models::Tenants::TemplateReplaceParams for more details.

Creates or updates a notification template scoped to one tenant, letting a tenant override the content the workspace template would send.

This is an upsert: it creates when the tenant has no template under template_id, and updates when it does. On the create half, content must place its elements inside a channel block — { "type": "channel", "channel": "email", "elements": [...] } — or the request returns 400. The template designer renders only the channel block matching the tab it draws, so content stored without one cannot be opened. An empty elements array is accepted, as is the { title, body } shorthand, which has no elements to wrap. Updates are not checked, so tenant templates already stored without a wrapper stay editable.

Parameters:

  • template_id (String) —

    Path param: Id of the template to be created or updated.

  • tenant_id (String) —

    Path param: Id of the tenant for which to create or update the template.

  • template (Courier::Models::TenantTemplateInput) —

    Body param: Template configuration for creating or updating a tenant notificatio

  • published (Boolean) —

    Body param: Whether to publish the template immediately after saving. When true,

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/courier/resources/tenants/templates.rb', line 163

def replace(template_id, params)
  parsed, options = Courier::Tenants::TemplateReplaceParams.dump_request(params)
  tenant_id =
    parsed.delete(:tenant_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["tenants/%1$s/templates/%2$s", tenant_id, template_id],
    body: parsed,
    model: Courier::PutTenantTemplateResponse,
    options: options
  )
end

#retrieve(template_id, tenant_id:, request_options: {}) ⇒ Courier::Models::BaseTemplateTenantAssociation

Returns a tenant's notification template with its content, version, and created, updated, and published timestamps.

Parameters:

  • template_id (String) —

    Id of the template to be retrieved.

  • tenant_id (String) —

    Id of the tenant for which to retrieve the template.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/courier/resources/tenants/templates.rb', line 28

def retrieve(template_id, params)
  parsed, options = Courier::Tenants::TemplateRetrieveParams.dump_request(params)
  tenant_id =
    parsed.delete(:tenant_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["tenants/%1$s/templates/%2$s", tenant_id, template_id],
    model: Courier::BaseTemplateTenantAssociation,
    options: options
  )
end