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

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:



144
145
146
147
# File 'lib/courier/resources/tenants/templates.rb', line 144

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

Instance Attribute Details

#versionsCourier::Resources::Tenants::Templates::Versions (readonly)



8
9
10
# File 'lib/courier/resources/tenants/templates.rb', line 8

def versions
  @versions
end

Instance Method Details

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

List Templates in Tenant

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:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/courier/resources/tenants/templates.rb', line 52

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 specific version of a notification template for a tenant.

The template must already exist in the tenant’s notification map. If no version is specified, defaults to publishing the “latest” version.

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:



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

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 for a tenant.

If the template already exists for the tenant, it will be updated (200). Otherwise, a new template is created (201).

Optionally publishes the template immediately if the ‘published` flag is set to true.

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:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/courier/resources/tenants/templates.rb', line 126

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

Get a Template in Tenant

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:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/courier/resources/tenants/templates.rb', line 23

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