-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_webhooks.go
43 lines (37 loc) · 1.35 KB
/
client_webhooks.go
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
package monta
import (
"bytes"
"context"
"encoding/json"
"net/url"
)
const webhooksConfigBasePath = "/v1/webhooks/config"
// WebhookConfig is the request for and response from Get and Update WebhookConfig methods.
type WebhookConfig struct {
// A HTTPS URL to send the webhook payload to when an event occurs.
WebhookURL string `json:"webhookUrl"`
// A cryptoghrapic secret used to sign the webhook payload.
WebhookSecret string `json:"webhookSecret"`
// List of entity types in plural to subscribe to. Use ["*"] to subscribe to all.
EventTypes []*WebhookEntityPluralType `json:"eventTypes"`
}
// GetWebhookConfig to get your webhook config.
func (c *clientImpl) GetWebhookConfig(ctx context.Context) (*WebhookConfig, error) {
query := url.Values{}
return doGet[WebhookConfig](ctx, c, webhooksConfigBasePath, query)
}
// UpdateWebhookConfig to update your webhook config.
func (c *clientImpl) UpdateWebhookConfig(
ctx context.Context,
request *WebhookConfig,
) (*WebhookConfig, error) {
var requestBody bytes.Buffer
if err := json.NewEncoder(&requestBody).Encode(&request); err != nil {
return nil, err
}
return doPut[WebhookConfig](ctx, c, webhooksConfigBasePath, &requestBody)
}
// DeleteWebhookConfig to delete a webhook config.
func (c *clientImpl) DeleteWebhookConfig(ctx context.Context) error {
return doDelete(ctx, c, webhooksConfigBasePath)
}