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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
resend (1.14.0)
resend (1.15.0)
base64
httparty (>= 0.22.0)

Expand Down
5 changes: 5 additions & 0 deletions examples/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
updated_webhook = Resend::Webhooks.update(update_params)
puts "\nUpdated webhook: #{updated_webhook[:id]}"

# Rotate the webhook signing secret
rotated_webhook = Resend::Webhooks.rotate_signing_secret(webhook[:id])
puts "\nRotated signing secret for webhook: #{rotated_webhook[:id]}"
puts "New signing secret: #{rotated_webhook[:signing_secret]}"

# List all webhooks
webhooks = Resend::Webhooks.list
puts "\nTotal webhooks: #{webhooks[:data].length}"
Expand Down
2 changes: 1 addition & 1 deletion lib/resend/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Resend
VERSION = "1.14.0"
VERSION = "1.15.0"
end
15 changes: 15 additions & 0 deletions lib/resend/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ def update(params = {})
Resend::Request.new(path, params, "patch").perform
end

# Rotate the signing secret of a webhook
#
# Generates a new signing secret for the webhook. The previous secret keeps working for 24 hours.
#
# @param webhook_id [String] The webhook ID
#
# @return [Hash] The webhook object containing id, object type, and the new signing_secret
#
# @example
# Resend::Webhooks.rotate_signing_secret("4dd369bc-aa82-4ff3-97de-514ae3000ee0")
def rotate_signing_secret(webhook_id)
Comment thread
gabrielmfern marked this conversation as resolved.
path = "webhooks/#{webhook_id}/signing-secret/rotate"
Resend::Request.new(path, {}, "post").perform
end

# Remove an existing webhook
#
# @param webhook_id [String] The webhook ID
Expand Down
21 changes: 21 additions & 0 deletions spec/webhooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@
end
end

describe "rotate_signing_secret" do
it "rotates the webhook signing secret" do
resp = {
"object": "webhook",
"id": "4dd369bc-aa82-4ff3-97de-514ae3000ee0",
"signing_secret": "whsec_yyyyyyyyyy"
}
request = instance_double(Resend::Request)
expect(Resend::Request).to receive(:new)
.with("webhooks/4dd369bc-aa82-4ff3-97de-514ae3000ee0/signing-secret/rotate", {}, "post")
.and_return(request)
expect(request).to receive(:perform).and_return(resp)

result = Resend::Webhooks.rotate_signing_secret("4dd369bc-aa82-4ff3-97de-514ae3000ee0")

expect(result[:object]).to eql("webhook")
expect(result[:id]).to eql("4dd369bc-aa82-4ff3-97de-514ae3000ee0")
expect(result[:signing_secret]).to eql("whsec_yyyyyyyyyy")
end
end

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