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 .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Layout/LineLength:
Metrics/ClassLength:
Max: 169

Metrics/ModuleLength:
Max: 169

Metrics/MethodLength:
Max: 14

Expand Down
4 changes: 4 additions & 0 deletions examples/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
puts "\nWebhook event: #{webhook_event[:id]}"
puts "Status: #{webhook_event[:status]}"

# Replay a webhook event
replayed_event = Resend::Webhooks.replay_event(webhook[:id], event_id)
puts "\nReplayed webhook event: #{replayed_event[:id]}"

# List delivery attempts for a webhook event
attempts = Resend::Webhooks.list_event_attempts(webhook[:id], event_id, limit: 10)
puts "\nDelivery attempts: #{attempts[:data].length}"
Expand Down
16 changes: 16 additions & 0 deletions lib/resend/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def get_event(webhook_id, event_id)
Resend::Request.new(path, {}, "get").perform
end

# Replay a webhook event
#
# Queues one more delivery of the event to the webhook. Manual replays do not schedule automatic retries.
#
# @param webhook_id [String] The webhook ID
# @param event_id [String] The webhook event ID
#
# @return [Hash] The replayed webhook event id and object type
#
# @example
# Resend::Webhooks.replay_event("4dd369bc-aa82-4ff3-97de-514ae3000ee0", "msg_123")
def replay_event(webhook_id, event_id)
path = "webhooks/#{webhook_id}/events/#{event_id}/replay"
Resend::Request.new(path, {}, "post").perform
end

# Retrieve delivery attempts for a webhook event
#
# @param webhook_id [String] The webhook ID
Expand Down
12 changes: 12 additions & 0 deletions spec/webhooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
end
end

describe "replay_event" do
it "replays a webhook event" do
request = instance_double(Resend::Request)
expect(Resend::Request).to receive(:new)
.with("webhooks/webhook_123/events/msg_1srOrx2ZWZBpBUvZwXKQmoEYga2/replay", {}, "post")
.and_return(request)
expect(request).to receive(:perform)

Resend::Webhooks.replay_event("webhook_123", "msg_1srOrx2ZWZBpBUvZwXKQmoEYga2")
Comment thread
gabrielmfern marked this conversation as resolved.
end
end

describe "list_event_attempts" do
it "lists webhook event attempts with pagination" do
request = instance_double(Resend::Request)
Expand Down