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:



218
219
220
# File 'lib/courier/resources/journeys/templates.rb', line 218

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

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

Replace the journey-scoped notification template draft.

Parameters:

Returns:

See Also:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/courier/resources/journeys/templates.rb', line 200

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