Class: Telnyx::Resources::EmailTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/email_templates.rb,
sig/telnyx/resources/email_templates.rbs

Overview

Create, list, retrieve, update, delete, and render Liquid email templates.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ EmailTemplates

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 EmailTemplates.

Parameters:



208
209
210
# File 'lib/telnyx/resources/email_templates.rb', line 208

def initialize(client:)
  @client = client
end

Instance Method Details

#create(name:, html_body: nil, subject: nil, text_body: nil, variables: nil, idempotency_key: nil, request_options: {}) ⇒ Telnyx::Models::EmailTemplateResponse

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

Creates a Liquid email template. Variables are auto-extracted when omitted.

Parameters:

  • name (String)

    Body param: Letters, numbers, spaces, hyphens, and underscores only.

  • html_body (String, nil)

    Body param: Liquid template HTML body.

  • subject (String, nil)

    Body param: Liquid template subject.

  • text_body (String, nil)

    Body param: Liquid template text body.

  • variables (Array<String>)

    Body param: Template variables. Auto-extracted from subject/body fields when abs

  • idempotency_key (String)

    Header param: Optional opaque, unquoted key for safely retrying the same logical

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

Returns:

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/telnyx/resources/email_templates.rb', line 31

def create(params)
  parsed, options = Telnyx::EmailTemplateCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "email_templates",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Telnyx::EmailTemplateResponse,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ nil

Delete an email template

Parameters:

  • id (String)

    Email template UUID.

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

Returns:

  • (nil)

See Also:



135
136
137
138
139
140
141
142
# File 'lib/telnyx/resources/email_templates.rb', line 135

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["email_templates/%1$s", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#list(page_cursor: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Models::EmailTemplateListResponse

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

Lists templates sorted newest first by created_at desc, id desc.

Parameters:

  • page_cursor (String)

    Opaque URL-safe Base64 cursor returned by a previous list response.

  • page_size (Integer)

    Number of results to return. Defaults to 25; maximum is 100. Invalid values are

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

Returns:

See Also:



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/telnyx/resources/email_templates.rb', line 112

def list(params = {})
  parsed, options = Telnyx::EmailTemplateListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "email_templates",
    query: query,
    model: Telnyx::Models::EmailTemplateListResponse,
    options: options
  )
end

#render(id, template_variables: nil, request_options: {}) ⇒ Telnyx::Models::EmailTemplateRenderResponse

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

Renders a template using the provided Liquid variables. Missing template_variables defaults to {}.

Parameters:

  • id (String)

    Email template UUID.

  • template_variables (Hash{Symbol=>Object})

    Variables for Liquid template rendering. Non-object values are silently treated

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

Returns:

See Also:



161
162
163
164
165
166
167
168
169
170
# File 'lib/telnyx/resources/email_templates.rb', line 161

def render(id, params = {})
  parsed, options = Telnyx::EmailTemplateRenderParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["email_templates/%1$s/render", id],
    body: parsed,
    model: Telnyx::Models::EmailTemplateRenderResponse,
    options: options
  )
end

#replace(id, html_body: nil, name: nil, subject: nil, text_body: nil, variables: nil, request_options: {}) ⇒ Telnyx::Models::EmailTemplateResponse

Replaces template fields. Behaves identically to PATCH; provided for compatibility with Phoenix resource routes.

Parameters:

  • id (String)

    Email template UUID.

  • html_body (String, nil)

    Liquid template HTML body.

  • name (String)
  • subject (String, nil)

    Liquid template subject.

  • text_body (String, nil)

    Liquid template text body.

  • variables (Array<String>)
  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



194
195
196
197
198
199
200
201
202
203
# File 'lib/telnyx/resources/email_templates.rb', line 194

def replace(id, params = {})
  parsed, options = Telnyx::EmailTemplateReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["email_templates/%1$s", id],
    body: parsed,
    model: Telnyx::EmailTemplateResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Telnyx::Models::EmailTemplateResponse

Get an email template

Parameters:

Returns:

See Also:



55
56
57
58
59
60
61
62
# File 'lib/telnyx/resources/email_templates.rb', line 55

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["email_templates/%1$s", id],
    model: Telnyx::EmailTemplateResponse,
    options: params[:request_options]
  )
end

#update(id, html_body: nil, name: nil, subject: nil, text_body: nil, variables: nil, request_options: {}) ⇒ Telnyx::Models::EmailTemplateResponse

Updates one or more template fields.

Parameters:

  • id (String)

    Email template UUID.

  • html_body (String, nil)

    Liquid template HTML body.

  • name (String)
  • subject (String, nil)

    Liquid template subject.

  • text_body (String, nil)

    Liquid template text body.

  • variables (Array<String>)
  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



85
86
87
88
89
90
91
92
93
94
# File 'lib/telnyx/resources/email_templates.rb', line 85

def update(id, params = {})
  parsed, options = Telnyx::EmailTemplateUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["email_templates/%1$s", id],
    body: parsed,
    model: Telnyx::EmailTemplateResponse,
    options: options
  )
end