Class: Courier::Resources::Journeys::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/journeys/templates.rb

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:



331
332
333
# File 'lib/courier/resources/journeys/templates.rb', line 331

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(notification_id, template_id:, request_options: {}) ⇒ nil

Archive the journey-scoped notification template. Archived templates cannot be sent.

Parameters:

  • notification_id (String)

    Notification template id

  • template_id (String)

    Journey id

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

Returns:

  • (nil)

See Also:



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/courier/resources/journeys/templates.rb', line 109

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

#create(template_id, channel:, notification:, provider_key: nil, state: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Create a notification template scoped to this journey. Defaults to ‘DRAFT` state; pass `state: “PUBLISHED”` to publish on create.

Parameters:

Returns:

See Also:



27
28
29
30
31
32
33
34
35
36
# File 'lib/courier/resources/journeys/templates.rb', line 27

def create(template_id, params)
  parsed, options = Courier::Journeys::TemplateCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["journeys/%1$s/templates", template_id],
    body: parsed,
    model: Courier::JourneyTemplateGetResponse,
    options: options
  )
end

#list(template_id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateListResponse

List notification templates scoped to this journey. Journey-scoped notification templates can only be referenced from ‘send` nodes within the same journey.

Parameters:

  • template_id (String)

    Journey id

  • cursor (String)

    Pagination cursor from a prior response.

  • limit (Integer)

    Page size. Minimum 1, maximum 100.

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

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/courier/resources/journeys/templates.rb', line 83

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

#list_versions(notification_id, template_id:, request_options: {}) ⇒ Courier::Models::NotificationTemplateVersionListResponse

List published versions of the journey-scoped notification template, ordered most recent first.

Parameters:

  • notification_id (String)

    Notification template id

  • template_id (String)

    Journey id

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

Returns:

See Also:



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/courier/resources/journeys/templates.rb', line 137

def list_versions(notification_id, params)
  parsed, options = Courier::Journeys::TemplateListVersionsParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates/%2$s/versions", template_id, notification_id],
    model: Courier::NotificationTemplateVersionListResponse,
    options: options
  )
end

#publish(notification_id, template_id:, version: nil, request_options: {}) ⇒ nil

Publish the current draft of the journey-scoped notification template as a new version. Optionally roll back to a prior version by passing ‘{ “version”: “vN” }`.

Parameters:

  • notification_id (String)

    Path param: Notification template id

  • template_id (String)

    Path param: Journey id

  • version (String)

    Body param

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

Returns:

  • (nil)

See Also:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/courier/resources/journeys/templates.rb', line 168

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

#put_content(notification_id, template_id:, content:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse

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

Replace the elemental content of a journey-scoped notification template. Overwrites all elements in the template draft with the provided content.

Parameters:

Returns:

See Also:



204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/courier/resources/journeys/templates.rb', line 204

def put_content(notification_id, params)
  parsed, options = Courier::Journeys::TemplatePutContentParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["journeys/%1$s/templates/%2$s/content", template_id, notification_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#put_locale(locale_id, template_id:, notification_id:, elements:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse

Set locale-specific content overrides for a journey-scoped notification template. Each element override must reference an existing element by ID.

Parameters:

Returns:

See Also:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/courier/resources/journeys/templates.rb', line 239

def put_locale(locale_id, params)
  parsed, options = Courier::Journeys::TemplatePutLocaleParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  notification_id =
    parsed.delete(:notification_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["journeys/%1$s/templates/%2$s/locales/%3$s", template_id, notification_id, locale_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#replace(notification_id, template_id:, notification:, state: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Replace the journey-scoped notification template draft.

Parameters:

Returns:

See Also:



275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/courier/resources/journeys/templates.rb', line 275

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

#retrieve(notification_id, template_id:, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Fetch a journey-scoped notification template by id. Pass ‘?version=draft` (default `published`) to retrieve the working draft, or `?version=vN` for a historical version.

Parameters:

  • notification_id (String)

    Notification template id

  • template_id (String)

    Journey id

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

Returns:

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/courier/resources/journeys/templates.rb', line 53

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

#retrieve_content(notification_id, template_id:, version: nil, request_options: {}) ⇒ Courier::Models::NotificationContentGetResponse

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

Retrieve the elemental content of a journey-scoped notification template. The response contains the versioned elements along with their content checksums, which can be used to detect changes between versions. Pass ‘?version=draft` (default `published`) to retrieve the working draft, or `?version=vN` for a historical version.

Parameters:

  • notification_id (String)

    Path param: Notification template id

  • template_id (String)

    Path param: Journey id

  • version (String)

    Query param: Accepts ‘draft`, `published`, or a version string (e.g., `v001`). D

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

Returns:

See Also:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/courier/resources/journeys/templates.rb', line 312

def retrieve_content(notification_id, params)
  parsed, options = Courier::Journeys::TemplateRetrieveContentParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates/%2$s/content", template_id, notification_id],
    query: query,
    model: Courier::NotificationContentGetResponse,
    options: options
  )
end