Class: Courier::Resources::Journeys

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

Overview

Build, version, publish, invoke, and cancel multi-step notification workflows, along with the templates scoped to them.

Defined Under Namespace

Classes: Templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Journeys

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

Parameters:



291
292
293
294
# File 'lib/courier/resources/journeys.rb', line 291

def initialize(client:)
  @client = client
  @templates = Courier::Resources::Journeys::Templates.new(client: client)
end

Instance Attribute Details

#templatesCourier::Resources::Journeys::Templates (readonly)

Build, version, publish, invoke, and cancel multi-step notification workflows, along with the templates scoped to them.



11
12
13
# File 'lib/courier/resources/journeys.rb', line 11

def templates
  @templates
end

Instance Method Details

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

Archives a journey so it can no longer be invoked. Runs already in flight continue to completion, so archiving never strands a user mid-sequence.

Parameters:

Returns:

  • (nil)

See Also:



119
120
121
122
123
124
125
126
# File 'lib/courier/resources/journeys.rb', line 119

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

#cancel(cancel_journey_request:, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::CancelJourneyResponse::TokenBranch, Courier::Models::CancelJourneyResponse::RunIDBranch

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

Cancels in-flight journey runs, either every run sharing a cancelation token or one run by id. Use it to stop a sequence when the event resolves.

Parameters:

Returns:

See Also:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/courier/resources/journeys.rb', line 147

def cancel(params)
  parsed, options = Courier::JourneyCancelParams.dump_request(params)
  @client.request(
    method: :post,
    path: "journeys/cancel",
    headers: parsed.except(:cancel_journey_request).transform_keys(
      idempotency_key: "idempotency-key",
      x_idempotency_expiration: "x-idempotency-expiration"
    ),
    body: parsed[:cancel_journey_request],
    model: Courier::CancelJourneyResponse,
    options: options
  )
end

#create(name:, nodes:, enabled: nil, state: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::JourneyResponse

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

Creates a journey from a set of nodes, in draft state unless you pass a published state. Send nodes cannot be included until their templates exist.

Parameters:

Returns:

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/courier/resources/journeys.rb', line 38

def create(params)
  parsed, options = Courier::JourneyCreateParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: "journeys",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::JourneyResponse,
    options: options
  )
end

#invoke(template_id, data: nil, profile: nil, user_id: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::JourneysInvokeResponse

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

Starts a journey run for one user and returns a runId. Runs execute asynchronously, so the response arrives before any message is sent.

Parameters:

  • template_id (String)

    Path param: A unique identifier representing the journey to be invoked. Accepts

  • data (Hash{Symbol=>Object})

    Body param: Data payload passed to the journey. The expected shape can be predef

  • profile (Hash{Symbol=>Object})

    Body param: Profile data for the user. Can contain contact information (email, p

  • user_id (String)

    Body param: A unique identifier for the user. If not provided, the system will a

  • idempotency_key (String)

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String)

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

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

Returns:

See Also:



187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/courier/resources/journeys.rb', line 187

def invoke(template_id, params = {})
  parsed, options = Courier::JourneyInvokeParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["journeys/%1$s/invoke", template_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::JourneysInvokeResponse,
    options: options
  )
end

#list(cursor: nil, version: nil, request_options: {}) ⇒ Courier::Models::JourneysListResponse

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

Lists the workspace's journeys, each carrying a name, state, and enabled flag. Paged by cursor.

Parameters:

Returns:

See Also:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/courier/resources/journeys.rb', line 95

def list(params = {})
  parsed, options = Courier::JourneyListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "journeys",
    query: query,
    model: Courier::JourneysListResponse,
    options: options
  )
end

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

Lists a journey's published versions, most recent first, so you have a version id to roll back to. Paged by cursor.

Parameters:

Returns:

See Also:



213
214
215
216
217
218
219
220
# File 'lib/courier/resources/journeys.rb', line 213

def list_versions(template_id, params = {})
  @client.request(
    method: :get,
    path: ["journeys/%1$s/versions", template_id],
    model: Courier::JourneyVersionsListResponse,
    options: params[:request_options]
  )
end

#publish(template_id, version: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::JourneyResponse

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

Publishes a journey's current draft as a new version, making it live for new runs. Pass a version instead to roll back to an earlier one.

Parameters:

  • template_id (String)

    Path param: Journey id

  • version (String)

    Body param

  • idempotency_key (String)

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String)

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

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

Returns:

See Also:



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

def publish(template_id, params = {})
  parsed, options = Courier::JourneyPublishParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["journeys/%1$s/publish", template_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::JourneyResponse,
    options: options
  )
end

#replace(template_id, name:, nodes:, enabled: nil, state: nil, request_options: {}) ⇒ Courier::Models::JourneyResponse

Replaces a journey's working draft, leaving the published version live until you publish. Reach for this when editing a journey already running.



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

def replace(template_id, params)
  parsed, options = Courier::JourneyReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["journeys/%1$s", template_id],
    body: parsed,
    model: Courier::JourneyResponse,
    options: options
  )
end

#retrieve(template_id, version: nil, request_options: {}) ⇒ Courier::Models::JourneyResponse

Fetch a journey by id. Pass ?version=draft (default published) to retrieve the working draft, or ?version=vN to retrieve a historical version.

Parameters:

  • template_id (String)

    Journey id

  • version (String)

    Version selector: draft, published (default), or vN.

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

Returns:

See Also:



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/courier/resources/journeys.rb', line 66

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