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

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:



262
263
264
265
# File 'lib/courier/resources/journeys.rb', line 262

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

Instance Attribute Details

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



7
8
9
# File 'lib/courier/resources/journeys.rb', line 7

def templates
  @templates
end

Instance Method Details

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

Archive a journey. Archived journeys cannot be invoked. Existing journey runs continue to completion.

Parameters:

Returns:

  • (nil)

See Also:



108
109
110
111
112
113
114
115
# File 'lib/courier/resources/journeys.rb', line 108

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:, request_options: {}) ⇒ Courier::Models::CancelJourneyResponse::TokenBranch, Courier::Models::CancelJourneyResponse::RunIDBranch

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

Cancel journey runs. The request body must include EXACTLY ONE of cancelation_token (cancels every run associated with the token) or run_id (cancels a single tenant-scoped run). Supplying both or neither returns a 400. A run_id that does not match a run for the tenant returns 404. Cancelation is idempotent: a run that has already finished (PROCESSED/ERROR) or was already CANCELED is left unchanged and its current status is returned.

Parameters:

Returns:

See Also:



136
137
138
139
140
141
142
143
144
145
# File 'lib/courier/resources/journeys.rb', line 136

def cancel(params)
  parsed, options = Courier::JourneyCancelParams.dump_request(params)
  @client.request(
    method: :post,
    path: "journeys/cancel",
    body: parsed[:cancel_journey_request],
    model: Courier::CancelJourneyResponse,
    options: options
  )
end

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

Create a journey. Defaults to DRAFT state; pass state: "PUBLISHED" to publish on create. Send nodes are not allowed on POST. The standard flow is: create the journey shell here, add notification templates with POST /journeys/{templateId}/templates, then wire them into the journey with PUT /journeys/{templateId}. Call POST /journeys/{templateId}/publish to publish a draft after the fact.



31
32
33
34
35
36
37
38
39
40
# File 'lib/courier/resources/journeys.rb', line 31

def create(params)
  parsed, options = Courier::JourneyCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "journeys",
    body: parsed,
    model: Courier::JourneyResponse,
    options: options
  )
end

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

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

Invoke a journey by id or alias to start a new run. The response includes a runId identifying the run.

Parameters:

  • template_id (String)

    A unique identifier representing the journey to be invoked. Accepts a Journey ID

  • data (Hash{Symbol=>Object})

    Data payload passed to the journey. The expected shape can be predefined using t

  • profile (Hash{Symbol=>Object})

    Profile data for the user. Can contain contact information (email, phone_number)

  • user_id (String)

    A unique identifier for the user. If not provided, the system will attempt to re

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

Returns:

See Also:



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

def invoke(template_id, params = {})
  parsed, options = Courier::JourneyInvokeParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["journeys/%1$s/invoke", template_id],
    body: parsed,
    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.

Get the list of journeys.

Parameters:

Returns:

See Also:



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

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

List published versions of a journey, ordered most recent first.

Parameters:

Returns:

See Also:



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

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, request_options: {}) ⇒ Courier::Models::JourneyResponse

Publish the current draft as a new version. Body is optional; pass { "version": "vN" } to roll back to a prior version instead. Returns 404 if the journey has no draft to publish.

Parameters:

  • template_id (String)

    Journey id

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

Returns:

See Also:



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

def publish(template_id, params = {})
  parsed, options = Courier::JourneyPublishParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["journeys/%1$s/publish", template_id],
    body: parsed,
    model: Courier::JourneyResponse,
    options: options
  )
end

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

Replace the journey draft. Updates the working draft only; call POST /journeys/{templateId}/publish to make it live, or pass state: "PUBLISHED" in this request to publish immediately. Send-node template ids must already exist and be scoped to this journey, and node ids must not be claimed by another journey.



248
249
250
251
252
253
254
255
256
257
# File 'lib/courier/resources/journeys.rb', line 248

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:



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

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