Class: Courier::Resources::Journeys

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

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:



232
233
234
235
# File 'lib/courier/resources/journeys.rb', line 232

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

#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:



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

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:



160
161
162
163
164
165
166
167
# File 'lib/courier/resources/journeys.rb', line 160

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:



184
185
186
187
188
189
190
191
192
193
# File 'lib/courier/resources/journeys.rb', line 184

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.



218
219
220
221
222
223
224
225
226
227
# File 'lib/courier/resources/journeys.rb', line 218

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