Class: Courier::Resources::Broadcasts

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Broadcasts

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

Parameters:



285
286
287
# File 'lib/courier/resources/broadcasts.rb', line 285

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(broadcast_id, request_options: {}) ⇒ Courier::Models::Broadcast

Archive a broadcast. This is a soft delete — the archived broadcast is returned and no longer appears in list results.

Parameters:

Returns:

See Also:



113
114
115
116
117
118
119
120
# File 'lib/courier/resources/broadcasts.rb', line 113

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

#cancel(broadcast_id, request_options: {}) ⇒ Courier::Models::Broadcast

Cancel a broadcast's pending schedule, returning it to the draft state. Only valid for a scheduled broadcast.

Parameters:

Returns:

See Also:



133
134
135
136
137
138
139
140
# File 'lib/courier/resources/broadcasts.rb', line 133

def cancel(broadcast_id, params = {})
  @client.request(
    method: :post,
    path: ["broadcasts/%1$s/cancel", broadcast_id],
    model: Courier::Broadcast,
    options: params[:request_options]
  )
end

#create(channel:, name:, request_options: {}) ⇒ Courier::Models::Broadcast

Create a broadcast. Provisions a private notification template for the broadcast and returns the new broadcast in the draft state. Exactly one channel is required.

Parameters:

Returns:

See Also:



21
22
23
24
25
26
27
28
29
30
# File 'lib/courier/resources/broadcasts.rb', line 21

def create(params)
  parsed, options = Courier::BroadcastCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "broadcasts",
    body: parsed,
    model: Courier::Broadcast,
    options: options
  )
end

#duplicate(broadcast_id, request_options: {}) ⇒ Courier::Models::Broadcast

Duplicate a broadcast (and its template) into a new draft named "name (copy)".

Parameters:

Returns:

See Also:



153
154
155
156
157
158
159
160
# File 'lib/courier/resources/broadcasts.rb', line 153

def duplicate(broadcast_id, params = {})
  @client.request(
    method: :post,
    path: ["broadcasts/%1$s/duplicate", broadcast_id],
    model: Courier::Broadcast,
    options: params[:request_options]
  )
end

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

List broadcasts in your workspace. Cursor-paginated; returns broadcasts newest-first.

Parameters:

  • cursor (String, nil)

    Opaque pagination cursor from a previous response. Omit for the first page.

  • limit (Integer)

    Maximum number of results per page.

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

Returns:

See Also:



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/courier/resources/broadcasts.rb', line 90

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

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

Author the broadcast's content by replacing the draft elemental content of its private notification template. The draft is published automatically when the broadcast is sent or scheduled.

Parameters:

Returns:

See Also:



179
180
181
182
183
184
185
186
187
188
# File 'lib/courier/resources/broadcasts.rb', line 179

def put_content(broadcast_id, params)
  parsed, options = Courier::BroadcastPutContentParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["broadcasts/%1$s/content", broadcast_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#retrieve(broadcast_id, request_options: {}) ⇒ Courier::Models::Broadcast

Retrieve a broadcast by ID. Archived broadcasts return 404.

Parameters:

Returns:

See Also:



42
43
44
45
46
47
48
49
# File 'lib/courier/resources/broadcasts.rb', line 42

def retrieve(broadcast_id, params = {})
  @client.request(
    method: :get,
    path: ["broadcasts/%1$s", broadcast_id],
    model: Courier::Broadcast,
    options: params[:request_options]
  )
end

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

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

Retrieve the broadcast's content — the elemental content of its private notification template. Defaults to the working draft, since broadcast content is authored as a draft until the broadcast is sent.

Parameters:

  • broadcast_id (String)
  • version (String)

    Accepts draft, published, or a version string (e.g. v001). Defaults to `dr

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

Returns:

See Also:



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/courier/resources/broadcasts.rb', line 208

def retrieve_content(broadcast_id, params = {})
  parsed, options = Courier::BroadcastRetrieveContentParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["broadcasts/%1$s/content", broadcast_id],
    query: query,
    model: Courier::NotificationContentGetResponse,
    options: options
  )
end

#schedule(broadcast_id, recipient_id:, recipient_type:, scheduled_to:, timezone: nil, request_options: {}) ⇒ Courier::Models::Broadcast

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

Schedule a broadcast for a future send to a list or audience. Publishes the broadcast template first. Not allowed once the broadcast is sending or sent. For an immediate send use POST /broadcasts/broadcastId/send.

Parameters:

  • broadcast_id (String)
  • recipient_id (String)

    ID of the target list or audience.

  • recipient_type (Symbol, Courier::Models::ScheduleBroadcastRequest::RecipientType)

    Whether the broadcast targets a list or an audience.

  • scheduled_to (String)

    Wall-clock timestamp of the future send, no timezone offset (e.g. "2026-07-21T20

  • timezone (String)

    IANA timezone for the scheduled send (e.g. America/New_York).

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

Returns:

See Also:



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

def schedule(broadcast_id, params)
  parsed, options = Courier::BroadcastScheduleParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["broadcasts/%1$s/schedule", broadcast_id],
    body: parsed,
    model: Courier::Broadcast,
    options: options
  )
end

#send_(broadcast_id, recipient_id:, recipient_type:, request_options: {}) ⇒ Courier::Models::Broadcast

Send a broadcast immediately to a list or audience. Publishes the broadcast template first. Not allowed once the broadcast is sending or sent.

Parameters:

Returns:

See Also:



271
272
273
274
275
276
277
278
279
280
# File 'lib/courier/resources/broadcasts.rb', line 271

def send_(broadcast_id, params)
  parsed, options = Courier::BroadcastSendParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["broadcasts/%1$s/send", broadcast_id],
    body: parsed,
    model: Courier::Broadcast,
    options: options
  )
end

#update(broadcast_id, name:, request_options: {}) ⇒ Courier::Models::Broadcast

Update a broadcast's name. Content is edited via the broadcast's notification template, not this endpoint.

Parameters:

  • broadcast_id (String)
  • name (String)

    New human-readable name.

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

Returns:

See Also:



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

def update(broadcast_id, params)
  parsed, options = Courier::BroadcastUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["broadcasts/%1$s", broadcast_id],
    body: parsed,
    model: Courier::Broadcast,
    options: options
  )
end