Skip to content

Commit a60e99b

Browse files
authored
feat: send/scheduled_at broadcasts (#155)
1 parent e6649bf commit a60e99b

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/resend/broadcasts.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class << self
77
# https://resend.com/docs/api-reference/broadcasts/create-broadcast
88
# @note Supports both segment_id and audience_id. At least one is required.
99
# audience_id is deprecated - use segment_id instead.
10+
# @note When send: true is passed, the broadcast is sent immediately instead of
11+
# creating a draft. When using send: true, you can also include scheduled_at
12+
# to schedule the broadcast. Passing scheduled_at without send: true is an error.
1013
def create(params = {})
1114
if params[:audience_id] && !params[:segment_id]
1215
warn "[DEPRECATION] Using audience_id in broadcasts is deprecated. Use segment_id instead."

spec/broadcasts_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,37 @@
4242
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
4343
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
4444
end
45+
46+
it "should create and send broadcast with send: true" do
47+
resp = {
48+
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
49+
}
50+
params = {
51+
segment_id: "123123",
52+
from: "onboarding@resend.dev",
53+
subject: "Hello World",
54+
html: "<p>Hello</p>",
55+
send: true
56+
}
57+
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
58+
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
59+
end
60+
61+
it "should create and schedule broadcast with send: true and scheduled_at" do
62+
resp = {
63+
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
64+
}
65+
params = {
66+
segment_id: "123123",
67+
from: "onboarding@resend.dev",
68+
subject: "Hello World",
69+
html: "<p>Hello</p>",
70+
send: true,
71+
scheduled_at: "in 1 min"
72+
}
73+
allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
74+
expect(Resend::Broadcasts.create(params)[:id]).to eql("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
75+
end
4576
end
4677

4778
describe "update" do

0 commit comments

Comments
 (0)