Class: Inttegro::Resources::MessageTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/inttegro/resources/message_templates.rb

Overview

Client for reusable, app-scoped SMS and email message templates.

Access this resource through Client#message_templates.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ MessageTemplates

Returns a new instance of MessageTemplates.

Parameters:



11
12
13
# File 'lib/inttegro/resources/message_templates.rb', line 11

def initialize(http)
  @http = T.let(http, Inttegro::HTTPClient)
end

Instance Method Details

#archive(template_id:, idempotency_key: nil) ⇒ Inttegro::MessageTemplate

Archive a template so it cannot be changed or used for new sends.

Parameters:

  • template_id (String) —

    unique template identifier

  • idempotency_key (String, nil) (defaults to: nil) —

    explicit key for safely retrying this logical write

Returns:



62
63
64
65
66
67
68
69
# File 'lib/inttegro/resources/message_templates.rb', line 62

def archive(template_id:, idempotency_key: nil)
  @http.post_resource(
    "/message_templates/archive",
    Inttegro::MessageTemplate, :message_template,
    { id: template_id },
    headers: idempotency_headers(idempotency_key)
  )
end

#create(payload, idempotency_key: nil) ⇒ Inttegro::MessageTemplate

Create a reusable message template.

Parameters:

  • payload (Hash, Inttegro::MessageTemplate::CreateRequest) —

    channel, content, and variable fields

  • idempotency_key (String, nil) (defaults to: nil) —

    explicit key for safely retrying this logical write

Returns:



20
21
22
23
24
25
26
27
# File 'lib/inttegro/resources/message_templates.rb', line 20

def create(payload, idempotency_key: nil)
  @http.post_resource(
    "/message_templates/create",
    Inttegro::MessageTemplate, :message_template,
    payload,
    headers: idempotency_headers(idempotency_key)
  )
end

#lookup(template_id:) ⇒ Inttegro::MessageTemplate

Retrieve a message template by identifier.

Parameters:

  • template_id (String) —

    unique template identifier

Returns:



75
76
77
78
79
80
81
# File 'lib/inttegro/resources/message_templates.rb', line 75

def lookup(template_id:)
  @http.post_resource(
    "/message_templates/lookup",
    Inttegro::MessageTemplate, :message_template,
    { id: template_id }
  )
end

#page(payload = {}) ⇒ Inttegro::MessageTemplate::Page

Retrieve templates in newest-updated order.

Parameters:

Returns:



87
88
89
90
91
92
93
# File 'lib/inttegro/resources/message_templates.rb', line 87

def page(payload = {})
  @http.post_resource(
    "/message_templates/page",
    Inttegro::MessageTemplate::Page, :page,
    payload || {}
  )
end

#publish(template_id:, idempotency_key: nil) ⇒ Inttegro::MessageTemplate

Publish the current draft version of a template.

Parameters:

  • template_id (String) —

    unique template identifier

  • idempotency_key (String, nil) (defaults to: nil) —

    explicit key for safely retrying this logical write

Returns:



48
49
50
51
52
53
54
55
# File 'lib/inttegro/resources/message_templates.rb', line 48

def publish(template_id:, idempotency_key: nil)
  @http.post_resource(
    "/message_templates/publish",
    Inttegro::MessageTemplate, :message_template,
    { id: template_id },
    headers: idempotency_headers(idempotency_key)
  )
end

#render_preview(payload) ⇒ Inttegro::MessageTemplate::Preview

Render a draft-aware preview using the supplied variable values.

Parameters:

Returns:



99
100
101
102
103
# File 'lib/inttegro/resources/message_templates.rb', line 99

def render_preview(payload)
  @http.post_model("/message_templates/render_preview", Inttegro::MessageTemplate::Preview,
    payload
  )
end

#update(payload, idempotency_key: nil) ⇒ Inttegro::MessageTemplate

Update a template and create a new draft version.

Parameters:

  • payload (Hash, Inttegro::MessageTemplate::UpdateRequest) —

    template identifier and fields to change

  • idempotency_key (String, nil) (defaults to: nil) —

    explicit key for safely retrying this logical write

Returns:



34
35
36
37
38
39
40
41
# File 'lib/inttegro/resources/message_templates.rb', line 34

def update(payload, idempotency_key: nil)
  @http.post_resource(
    "/message_templates/update",
    Inttegro::MessageTemplate, :message_template,
    payload,
    headers: idempotency_headers(idempotency_key)
  )
end