Module: Resend::Webhooks
- Defined in:
- lib/resend/webhooks.rb
Overview
Class Method Summary collapse
-
.create(params = {}) ⇒ Hash
Create a new webhook to receive real-time notifications about email events.
-
.get(webhook_id = "") ⇒ Hash
Retrieve a single webhook for the authenticated user.
-
.get_event(webhook_id, event_id) ⇒ Hash
Retrieve a webhook event.
-
.list(params = {}) ⇒ Hash
Retrieve a list of webhooks for the authenticated user.
-
.list_event_attempts(webhook_id, event_id, params = {}) ⇒ Hash
Retrieve delivery attempts for a webhook event.
-
.list_events(webhook_id, params = {}) ⇒ Hash
Retrieve webhook events.
-
.remove(webhook_id = "") ⇒ Hash
Remove an existing webhook.
-
.replay_event(webhook_id, event_id) ⇒ Hash
Replay a webhook event.
-
.rotate_signing_secret(webhook_id) ⇒ Hash
Rotate the signing secret of a webhook.
-
.update(params = {}) ⇒ Hash
Update an existing webhook configuration.
-
.verify(params = {}) ⇒ Boolean
Verify a webhook payload using HMAC-SHA256 signature validation This validates that the webhook request came from Resend and hasn't been tampered with.
Class Method Details
.create(params = {}) ⇒ Hash
Create a new webhook to receive real-time notifications about email events
50 51 52 53 |
# File 'lib/resend/webhooks.rb', line 50 def create(params = {}) path = "webhooks" Resend::Request.new(path, params, "post").perform end |
.get(webhook_id = "") ⇒ Hash
Retrieve a single webhook for the authenticated user
82 83 84 85 |
# File 'lib/resend/webhooks.rb', line 82 def get(webhook_id = "") path = "webhooks/#{webhook_id}" Resend::Request.new(path, {}, "get").perform end |
.get_event(webhook_id, event_id) ⇒ Hash
Retrieve a webhook event
115 116 117 118 |
# File 'lib/resend/webhooks.rb', line 115 def get_event(webhook_id, event_id) path = "webhooks/#{webhook_id}/events/#{event_id}" Resend::Request.new(path, {}, "get").perform end |
.list(params = {}) ⇒ Hash
Retrieve a list of webhooks for the authenticated user
69 70 71 72 |
# File 'lib/resend/webhooks.rb', line 69 def list(params = {}) path = Resend::PaginationHelper.build_paginated_path("webhooks", params) Resend::Request.new(path, {}, "get").perform end |
.list_event_attempts(webhook_id, event_id, params = {}) ⇒ Hash
Retrieve delivery attempts for a webhook event
156 157 158 159 160 |
# File 'lib/resend/webhooks.rb', line 156 def list_event_attempts(webhook_id, event_id, params = {}) base_path = "webhooks/#{webhook_id}/events/#{event_id}/attempts" path = Resend::PaginationHelper.build_paginated_path(base_path, params) Resend::Request.new(path, {}, "get").perform end |
.list_events(webhook_id, params = {}) ⇒ Hash
Retrieve webhook events
101 102 103 104 |
# File 'lib/resend/webhooks.rb', line 101 def list_events(webhook_id, params = {}) path = Resend::PaginationHelper.build_paginated_path("webhooks/#{webhook_id}/events", params) Resend::Request.new(path, {}, "get").perform end |
.remove(webhook_id = "") ⇒ Hash
Remove an existing webhook
208 209 210 211 |
# File 'lib/resend/webhooks.rb', line 208 def remove(webhook_id = "") path = "webhooks/#{webhook_id}" Resend::Request.new(path, {}, "delete").perform end |
.replay_event(webhook_id, event_id) ⇒ Hash
Replay a webhook event
Queues one more delivery of the event to the webhook. Manual replays do not schedule automatic retries.
131 132 133 134 |
# File 'lib/resend/webhooks.rb', line 131 def replay_event(webhook_id, event_id) path = "webhooks/#{webhook_id}/events/#{event_id}/replay" Resend::Request.new(path, {}, "post").perform end |
.rotate_signing_secret(webhook_id) ⇒ Hash
Rotate the signing secret of a webhook
Generates a new signing secret for the webhook. The previous secret keeps working for 24 hours.
195 196 197 198 |
# File 'lib/resend/webhooks.rb', line 195 def rotate_signing_secret(webhook_id) path = "webhooks/#{webhook_id}/signing-secret/rotate" Resend::Request.new(path, {}, "post").perform end |
.update(params = {}) ⇒ Hash
Update an existing webhook configuration
179 180 181 182 183 |
# File 'lib/resend/webhooks.rb', line 179 def update(params = {}) webhook_id = params.delete(:webhook_id) path = "webhooks/#{webhook_id}" Resend::Request.new(path, params, "patch").perform end |
.verify(params = {}) ⇒ Boolean
Verify a webhook payload using HMAC-SHA256 signature validation This validates that the webhook request came from Resend and hasn't been tampered with
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/resend/webhooks.rb', line 235 def verify(params = {}) payload = params[:payload] headers = params[:headers] || {} webhook_secret = params[:webhook_secret] validate_required_params(payload, headers, webhook_secret) (headers[:svix_timestamp]) signed_content = "#{headers[:svix_id]}.#{headers[:svix_timestamp]}.#{payload}" decoded_secret = decode_secret(webhook_secret) expected_signature = generate_signature(decoded_secret, signed_content) verify_signature(headers[:svix_signature], expected_signature) end |