Class: Courier::Resources::Broadcasts

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

Overview

Create a one-off send to a list or audience, author its content, then send it immediately or schedule it for later.

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:



294
295
296
# File 'lib/courier/resources/broadcasts.rb', line 294

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:

  • broadcast_id (String)

    The broadcast to archive.

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

Returns:

See Also:



117
118
119
120
121
122
123
124
# File 'lib/courier/resources/broadcasts.rb', line 117

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:

  • broadcast_id (String)

    The broadcast to cancel.

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

Returns:

See Also:



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

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:



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

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

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

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

Parameters:

  • broadcast_id (String)

    The broadcast to copy. The duplicate is created as a new draft and this broadcas

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

Returns:

See Also:



162
163
164
165
166
167
168
169
# File 'lib/courier/resources/broadcasts.rb', line 162

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:



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/courier/resources/broadcasts.rb', line 93

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:



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

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:

  • broadcast_id (String)

    The broadcast to retrieve, identified by the id returned when it was created.

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

Returns:

See Also:



45
46
47
48
49
50
51
52
# File 'lib/courier/resources/broadcasts.rb', line 45

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)

    The broadcast whose content you want to read.

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



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

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)

    The broadcast to schedule.

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



253
254
255
256
257
258
259
260
261
262
# File 'lib/courier/resources/broadcasts.rb', line 253

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:



280
281
282
283
284
285
286
287
288
289
# File 'lib/courier/resources/broadcasts.rb', line 280

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)

    The broadcast to rename.

  • name (String)

    New human-readable name.

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

Returns:

See Also:



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

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