Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/resend/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class << self
# https://resend.com/docs/api-reference/broadcasts/create-broadcast
# @note Supports both segment_id and audience_id. At least one is required.
# audience_id is deprecated - use segment_id instead.
# @note When send: true is passed, the broadcast is sent immediately instead of
# creating a draft. When using send: true, you can also include scheduled_at
# to schedule the broadcast. Passing scheduled_at without send: true is an error.
def create(params = {})
if params[:audience_id] && !params[:segment_id]
warn "[DEPRECATION] Using audience_id in broadcasts is deprecated. Use segment_id instead."
Expand Down
31 changes: 31 additions & 0 deletions spec/broadcasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
end

it "should create and send broadcast with send: true" do
resp = {
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
}
params = {
segment_id: "123123",
from: "onboarding@resend.dev",
subject: "Hello World",
html: "<p>Hello</p>",
send: true
}
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
end

it "should create and schedule broadcast with send: true and scheduled_at" do
resp = {
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
}
params = {
segment_id: "123123",
from: "onboarding@resend.dev",
subject: "Hello World",
html: "<p>Hello</p>",
send: true,
scheduled_at: "in 1 min"
}
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
end
end

describe "update" do
Expand Down