Class: Sendly::WebhooksResource
- Inherits:
-
Object
- Object
- Sendly::WebhooksResource
- Defined in:
- lib/sendly/webhooks_resource.rb
Overview
Webhooks resource for managing webhook endpoints
Instance Method Summary collapse
-
#create(url:, events:, description: nil, mode: nil, metadata: nil) ⇒ Sendly::WebhookCreatedResponse
Create a new webhook endpoint.
-
#delete(webhook_id) ⇒ void
Delete a webhook.
-
#deliveries(webhook_id) ⇒ Array<Sendly::WebhookDelivery>
Get delivery history for a webhook.
-
#event_types ⇒ Array<String>
List available event types.
-
#get(webhook_id) ⇒ Sendly::Webhook
Get a specific webhook by ID.
-
#initialize(client) ⇒ WebhooksResource
constructor
A new instance of WebhooksResource.
-
#list ⇒ Array<Sendly::Webhook>
List all webhooks.
-
#reset_circuit(webhook_id) ⇒ Hash
Reset the circuit breaker for a webhook.
-
#retry_delivery(webhook_id, delivery_id) ⇒ void
Retry a failed delivery.
-
#rotate_secret(webhook_id) ⇒ Sendly::WebhookSecretRotation
Rotate the webhook signing secret.
-
#test(webhook_id) ⇒ Sendly::WebhookTestResult
Test a webhook endpoint.
-
#update(webhook_id, url: nil, events: nil, description: nil, is_active: nil, mode: nil, metadata: nil) ⇒ Sendly::Webhook
Update a webhook configuration.
Constructor Details
#initialize(client) ⇒ WebhooksResource
Returns a new instance of WebhooksResource.
7 8 9 |
# File 'lib/sendly/webhooks_resource.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#create(url:, events:, description: nil, mode: nil, metadata: nil) ⇒ Sendly::WebhookCreatedResponse
Create a new webhook endpoint
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sendly/webhooks_resource.rb', line 27 def create(url:, events:, description: nil, mode: nil, metadata: nil) raise ArgumentError, "Webhook URL must be HTTPS" unless url&.start_with?("https://") raise ArgumentError, "At least one event type is required" if events.nil? || events.empty? body = { url: url, events: events } body[:description] = description if description body[:mode] = mode if mode body[:metadata] = if response = @client.post("/webhooks", body) WebhookCreatedResponse.new(response) end |
#delete(webhook_id) ⇒ void
This method returns an undefined value.
Delete a webhook
88 89 90 91 92 |
# File 'lib/sendly/webhooks_resource.rb', line 88 def delete(webhook_id) validate_webhook_id!(webhook_id) @client.delete("/webhooks/#{webhook_id}") nil end |
#deliveries(webhook_id) ⇒ Array<Sendly::WebhookDelivery>
Get delivery history for a webhook
127 128 129 130 131 |
# File 'lib/sendly/webhooks_resource.rb', line 127 def deliveries(webhook_id) validate_webhook_id!(webhook_id) response = @client.get("/webhooks/#{webhook_id}/deliveries") response.map { |data| WebhookDelivery.new(data) } end |
#event_types ⇒ Array<String>
List available event types
148 149 150 151 |
# File 'lib/sendly/webhooks_resource.rb', line 148 def event_types response = @client.get("/webhooks/event-types") (response["events"] || []).map { |e| e["type"] } end |
#get(webhook_id) ⇒ Sendly::Webhook
Get a specific webhook by ID
52 53 54 55 56 |
# File 'lib/sendly/webhooks_resource.rb', line 52 def get(webhook_id) validate_webhook_id!(webhook_id) response = @client.get("/webhooks/#{webhook_id}") Webhook.new(response) end |
#list ⇒ Array<Sendly::Webhook>
List all webhooks
43 44 45 46 |
# File 'lib/sendly/webhooks_resource.rb', line 43 def list response = @client.get("/webhooks") response.map { |data| Webhook.new(data) } end |
#reset_circuit(webhook_id) ⇒ Hash
Reset the circuit breaker for a webhook
108 109 110 111 |
# File 'lib/sendly/webhooks_resource.rb', line 108 def reset_circuit(webhook_id) validate_webhook_id!(webhook_id) @client.post("/webhooks/#{webhook_id}/reset-circuit") end |
#retry_delivery(webhook_id, delivery_id) ⇒ void
This method returns an undefined value.
Retry a failed delivery
138 139 140 141 142 143 |
# File 'lib/sendly/webhooks_resource.rb', line 138 def retry_delivery(webhook_id, delivery_id) validate_webhook_id!(webhook_id) validate_delivery_id!(delivery_id) @client.post("/webhooks/#{webhook_id}/deliveries/#{delivery_id}/retry") nil end |
#rotate_secret(webhook_id) ⇒ Sendly::WebhookSecretRotation
Rotate the webhook signing secret
117 118 119 120 121 |
# File 'lib/sendly/webhooks_resource.rb', line 117 def rotate_secret(webhook_id) validate_webhook_id!(webhook_id) response = @client.post("/webhooks/#{webhook_id}/rotate-secret") WebhookSecretRotation.new(response) end |
#test(webhook_id) ⇒ Sendly::WebhookTestResult
Test a webhook endpoint
98 99 100 101 102 |
# File 'lib/sendly/webhooks_resource.rb', line 98 def test(webhook_id) validate_webhook_id!(webhook_id) response = @client.post("/webhooks/#{webhook_id}/test") WebhookTestResult.new(response) end |
#update(webhook_id, url: nil, events: nil, description: nil, is_active: nil, mode: nil, metadata: nil) ⇒ Sendly::Webhook
Update a webhook configuration
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sendly/webhooks_resource.rb', line 68 def update(webhook_id, url: nil, events: nil, description: nil, is_active: nil, mode: nil, metadata: nil) validate_webhook_id!(webhook_id) raise ArgumentError, "Webhook URL must be HTTPS" if url && !url.start_with?("https://") body = {} body[:url] = url unless url.nil? body[:events] = events unless events.nil? body[:description] = description unless description.nil? body[:is_active] = is_active unless is_active.nil? body[:mode] = mode unless mode.nil? body[:metadata] = unless .nil? response = @client.patch("/webhooks/#{webhook_id}", body) Webhook.new(response) end |