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.
-
.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
140 141 142 143 144 |
# File 'lib/resend/webhooks.rb', line 140 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
177 178 179 180 |
# File 'lib/resend/webhooks.rb', line 177 def remove(webhook_id = "") path = "webhooks/#{webhook_id}" Resend::Request.new(path, {}, "delete").perform end |
.update(params = {}) ⇒ Hash
Update an existing webhook configuration
163 164 165 166 167 |
# File 'lib/resend/webhooks.rb', line 163 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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/resend/webhooks.rb', line 204 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 |