Module: EmailFuse::Webhooks
- Defined in:
- lib/email_fuse/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.
-
.list(params = {}) ⇒ Hash
Retrieve a list of webhooks for the authenticated user.
-
.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 EmailFuse 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/email_fuse/webhooks.rb', line 50 def create(params = {}) path = "webhooks" EmailFuse::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/email_fuse/webhooks.rb', line 82 def get(webhook_id = "") path = "webhooks/#{webhook_id}" EmailFuse::Request.new(path, {}, "get").perform end |
.list(params = {}) ⇒ Hash
Retrieve a list of webhooks for the authenticated user
69 70 71 72 |
# File 'lib/email_fuse/webhooks.rb', line 69 def list(params = {}) path = EmailFuse::PaginationHelper.build_paginated_path("webhooks", params) EmailFuse::Request.new(path, {}, "get").perform end |
.remove(webhook_id = "") ⇒ Hash
Remove an existing webhook
118 119 120 121 |
# File 'lib/email_fuse/webhooks.rb', line 118 def remove(webhook_id = "") path = "webhooks/#{webhook_id}" EmailFuse::Request.new(path, {}, "delete").perform end |
.update(params = {}) ⇒ Hash
Update an existing webhook configuration
104 105 106 107 108 |
# File 'lib/email_fuse/webhooks.rb', line 104 def update(params = {}) webhook_id = params.delete(:webhook_id) path = "webhooks/#{webhook_id}" EmailFuse::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 EmailFuse and hasn’t been tampered with
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/email_fuse/webhooks.rb', line 145 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 |