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 86 87 |
# File 'lib/email_fuse/webhooks.rb', line 82 def get(webhook_id) raise ArgumentError, "webhook_id is required" if webhook_id.nil? || webhook_id.to_s.empty? 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
123 124 125 126 127 128 |
# File 'lib/email_fuse/webhooks.rb', line 123 def remove(webhook_id) raise ArgumentError, "webhook_id is required" if webhook_id.nil? || webhook_id.to_s.empty? path = "webhooks/#{webhook_id}" EmailFuse::Request.new(path, {}, "delete").perform end |
.update(params = {}) ⇒ Hash
Update an existing webhook configuration
106 107 108 109 110 111 112 113 |
# File 'lib/email_fuse/webhooks.rb', line 106 def update(params = {}) params = params.dup # Don't mutate caller's hash webhook_id = params.delete(:webhook_id) raise ArgumentError, ":webhook_id is required" if webhook_id.nil? || webhook_id.to_s.empty? 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/email_fuse/webhooks.rb', line 152 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 |