Skip to content

Commit 63c45d1

Browse files
committed
go: Add operational webhook endpoint API
1 parent a385cc1 commit 63c45d1

File tree

2 files changed

+131
-8
lines changed

2 files changed

+131
-8
lines changed

go/operational_webhook_endpoint.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package svix
2+
3+
import (
4+
"context"
5+
6+
"github.com/svix/svix-webhooks/go/internal/openapi"
7+
)
8+
9+
type (
10+
ListResponseOperationalWebhookEndpointOut = openapi.ListResponseOperationalWebhookEndpointOut
11+
OperationalWebhookEndpointIn = openapi.OperationalWebhookEndpointIn
12+
OperationalWebhookEndpointUpdate = openapi.OperationalWebhookEndpointUpdate
13+
OperationalWebhookEndpointOut = openapi.OperationalWebhookEndpointOut
14+
OperationalWebhookEndpointSecretOut = openapi.OperationalWebhookEndpointSecretOut
15+
OperationalWebhookEndpointSecretIn = openapi.OperationalWebhookEndpointSecretIn
16+
Ordering = openapi.Ordering
17+
)
18+
19+
type OperationalWebhookEndpoint struct {
20+
api *openapi.APIClient
21+
}
22+
23+
type OperationalWebhookEndpointListOptions struct {
24+
Iterator *string
25+
Limit *int32
26+
Order *Ordering
27+
}
28+
29+
func (e *OperationalWebhookEndpoint) List(ctx context.Context, options *OperationalWebhookEndpointListOptions) (*ListResponseOperationalWebhookEndpointOut, error) {
30+
req := e.api.WebhookEndpointAPI.ListOperationalWebhookEndpoint(ctx)
31+
if options != nil {
32+
if options.Iterator != nil {
33+
req = req.Iterator(*options.Iterator)
34+
}
35+
if options.Limit != nil {
36+
req = req.Limit(*options.Limit)
37+
}
38+
if options.Order != nil {
39+
req = req.Order(*options.Order)
40+
}
41+
}
42+
ret, res, err := req.Execute()
43+
if err != nil {
44+
return nil, wrapError(err, res)
45+
}
46+
return ret, nil
47+
}
48+
49+
func (e *OperationalWebhookEndpoint) Create(ctx context.Context, endpointIn *OperationalWebhookEndpointIn) (*OperationalWebhookEndpointOut, error) {
50+
return e.CreateWithOptions(ctx, endpointIn, nil)
51+
}
52+
53+
func (e *OperationalWebhookEndpoint) CreateWithOptions(ctx context.Context, endpointIn *OperationalWebhookEndpointIn, options *PostOptions) (*OperationalWebhookEndpointOut, error) {
54+
req := e.api.WebhookEndpointAPI.CreateOperationalWebhookEndpoint(ctx)
55+
req = req.OperationalWebhookEndpointIn(*endpointIn)
56+
if options != nil {
57+
if options.IdempotencyKey != nil {
58+
req = req.IdempotencyKey(*options.IdempotencyKey)
59+
}
60+
}
61+
ret, res, err := req.Execute()
62+
if err != nil {
63+
return nil, wrapError(err, res)
64+
}
65+
return ret, nil
66+
}
67+
68+
func (e *OperationalWebhookEndpoint) Get(ctx context.Context, endpointId string) (*OperationalWebhookEndpointOut, error) {
69+
req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpoint(ctx, endpointId)
70+
ret, res, err := req.Execute()
71+
if err != nil {
72+
return nil, wrapError(err, res)
73+
}
74+
return ret, nil
75+
}
76+
77+
func (e *OperationalWebhookEndpoint) Update(ctx context.Context, endpointId string, endpointUpdate *OperationalWebhookEndpointUpdate) (*OperationalWebhookEndpointOut, error) {
78+
req := e.api.WebhookEndpointAPI.UpdateOperationalWebhookEndpoint(ctx, endpointId)
79+
req = req.OperationalWebhookEndpointUpdate(*endpointUpdate)
80+
ret, res, err := req.Execute()
81+
if err != nil {
82+
return nil, wrapError(err, res)
83+
}
84+
return ret, nil
85+
}
86+
87+
func (e *OperationalWebhookEndpoint) Delete(ctx context.Context, endpointId string) error {
88+
req := e.api.WebhookEndpointAPI.DeleteOperationalWebhookEndpoint(ctx, endpointId)
89+
res, err := req.Execute()
90+
return wrapError(err, res)
91+
}
92+
93+
func (e *OperationalWebhookEndpoint) GetSecret(ctx context.Context, endpointId string) (*OperationalWebhookEndpointSecretOut, error) {
94+
req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpointSecret(ctx, endpointId)
95+
ret, res, err := req.Execute()
96+
if err != nil {
97+
return nil, wrapError(err, res)
98+
}
99+
return ret, nil
100+
}
101+
102+
func (e *OperationalWebhookEndpoint) RotateSecret(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn) error {
103+
return e.RotateSecretWithOptions(ctx, endpointId, endpointSecretRotateIn, nil)
104+
}
105+
106+
func (e *OperationalWebhookEndpoint) RotateSecretWithOptions(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn, options *PostOptions) error {
107+
req := e.api.WebhookEndpointAPI.RotateOperationalWebhookEndpointSecret(ctx, endpointId)
108+
req = req.OperationalWebhookEndpointSecretIn(*endpointSecretRotateIn)
109+
if options != nil {
110+
if options.IdempotencyKey != nil {
111+
req = req.IdempotencyKey(*options.IdempotencyKey)
112+
}
113+
}
114+
res, err := req.Execute()
115+
if err != nil {
116+
return wrapError(err, res)
117+
}
118+
return nil
119+
}

go/svix.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ type (
2020
HTTPClient *http.Client
2121
}
2222
Svix struct {
23-
Authentication *Authentication
24-
Application *Application
25-
Endpoint *Endpoint
26-
EventType *EventType
27-
Integration *Integration
28-
Message *Message
29-
MessageAttempt *MessageAttempt
30-
Statistics *Statistics
23+
Authentication *Authentication
24+
Application *Application
25+
Endpoint *Endpoint
26+
EventType *EventType
27+
Integration *Integration
28+
Message *Message
29+
MessageAttempt *MessageAttempt
30+
Statistics *Statistics
31+
OperationalWebhookEndpoint *OperationalWebhookEndpoint
3132
}
3233
)
3334

@@ -108,5 +109,8 @@ func New(token string, options *SvixOptions) *Svix {
108109
Statistics: &Statistics{
109110
api: apiClient,
110111
},
112+
OperationalWebhookEndpoint: &OperationalWebhookEndpoint{
113+
api: apiClient,
114+
},
111115
}
112116
}

0 commit comments

Comments
 (0)