Skip to content

Commit ff47c70

Browse files
committed
feat: implement update webhook config endpoint
1 parent bf57303 commit ff47c70

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type Client interface {
6060

6161
// Webhooks
6262
GetWebhookConfig(ctx context.Context) (*GetWebhookConfigResponse, error)
63+
UpdateWebhookConfig(
64+
ctx context.Context,
65+
request *UpdateWebhookConfigRequest,
66+
) (*UpdateWebhookConfigResponse, error)
6367
}
6468

6569
// clientImpl to the Monta Partner API.
@@ -185,6 +189,11 @@ func doDelete(ctx context.Context, client *clientImpl, path string) error {
185189
return err
186190
}
187191

192+
// Template method to execute PUT requests towards monta.
193+
func doPut[T any](ctx context.Context, client *clientImpl, path string, body io.Reader) (*T, error) {
194+
return execute[T](ctx, client, http.MethodPut, path, nil, &http.Header{"content-type": {"application/json"}}, body)
195+
}
196+
188197
// Template method to execute requests towards monta.
189198
func execute[T any](
190199
ctx context.Context,

client_webhooks.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package monta
22

33
import (
4+
"bytes"
45
"context"
6+
"encoding/json"
57
"net/url"
68
)
79

@@ -21,3 +23,36 @@ func (c *clientImpl) GetWebhookConfig(ctx context.Context) (*GetWebhookConfigRes
2123
query := url.Values{}
2224
return doGet[GetWebhookConfigResponse](ctx, c, path, query)
2325
}
26+
27+
// UpdateWebhookConfigRequest is the request input to the [Client.UpdateWebhookConfig] method.
28+
type UpdateWebhookConfigRequest struct {
29+
// A HTTPS URL to send the webhook payload to when an event occurs.
30+
WebhookURL string `json:"webhookUrl"`
31+
// A cryptoghrapic secret used to sign the webhook payload.
32+
WebhookSecret string `json:"webhookSecret"`
33+
// A list of event type to subscribe to. Use ["*"] to subscribe to all.
34+
EventTypes []*WebhookEventType `json:"eventTypes"`
35+
}
36+
37+
// UpdateWebhookConfigResponse is the response output from the [Client.UpdateWebhookConfig] method.
38+
type UpdateWebhookConfigResponse struct {
39+
// A HTTPS URL to send the webhook payload to when an event occurs.
40+
WebhookURL string `json:"webhookUrl"`
41+
// A cryptoghrapic secret used to sign the webhook payload.
42+
WebhookSecret string `json:"webhookSecret"`
43+
// A list of event type to subscribe to. Use of ["*"] means subscribe to all.
44+
EventTypes []*string `json:"eventTypes"`
45+
}
46+
47+
// UpdateWebhookConfig to update your webhook config.
48+
func (c *clientImpl) UpdateWebhookConfig(
49+
ctx context.Context,
50+
request *UpdateWebhookConfigRequest,
51+
) (*UpdateWebhookConfigResponse, error) {
52+
path := "/v1/webhooks/config"
53+
var requestBody bytes.Buffer
54+
if err := json.NewEncoder(&requestBody).Encode(&request); err != nil {
55+
return nil, err
56+
}
57+
return doPut[UpdateWebhookConfigResponse](ctx, c, path, &requestBody)
58+
}

0 commit comments

Comments
 (0)