-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebhooks_api.rb
More file actions
50 lines (42 loc) · 1.35 KB
/
Copy pathwebhooks_api.rb
File metadata and controls
50 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'mailtrap'
account_id = 3229
client = Mailtrap::Client.new(api_key: 'your-api-key')
webhooks_api = Mailtrap::WebhooksAPI.new(account_id, client)
# Create an `email_sending` webhook
webhook = webhooks_api.create(
url: 'https://example.com/mailtrap/webhooks',
webhook_type: 'email_sending',
payload_format: 'json',
sending_stream: 'transactional',
event_types: %w[delivery bounce],
domain_id: 435
)
# => #<struct Mailtrap::Webhook id=1, url="https://example.com/mailtrap/webhooks", ..., signing_secret="a1b2c3...">
# Create an `audit_log` webhook
webhooks_api.create(
url: 'https://example.com/mailtrap/audit-log',
webhook_type: 'audit_log'
)
# Create an `inbound_receiving` webhook (linked to an inbound inbox)
webhooks_api.create(
url: 'https://example.com/mailtrap/inbound',
webhook_type: 'inbound_receiving',
payload_format: 'json',
inbound_inbox_id: 42
)
# List all webhooks
webhooks_api.list
# => [#<struct Mailtrap::Webhook id=1, ...>, #<struct Mailtrap::Webhook id=2, ...>]
# Get a single webhook
webhooks_api.get(webhook.id)
# => #<struct Mailtrap::Webhook id=1, ...>
# Update webhook
webhooks_api.update(
webhook.id,
active: false,
event_types: %w[delivery bounce unsubscribe]
)
# => #<struct Mailtrap::Webhook id=1, active=false, ...>
# Delete webhook
webhooks_api.delete(webhook.id)
# => #<struct Mailtrap::Webhook id=1, ...>