Skip to content

Commit

Permalink
go: Add operational webhook endpoint API
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Nov 5, 2024
1 parent a385cc1 commit 63c45d1
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 8 deletions.
119 changes: 119 additions & 0 deletions go/operational_webhook_endpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package svix

import (
"context"

"github.com/svix/svix-webhooks/go/internal/openapi"
)

type (
ListResponseOperationalWebhookEndpointOut = openapi.ListResponseOperationalWebhookEndpointOut
OperationalWebhookEndpointIn = openapi.OperationalWebhookEndpointIn
OperationalWebhookEndpointUpdate = openapi.OperationalWebhookEndpointUpdate
OperationalWebhookEndpointOut = openapi.OperationalWebhookEndpointOut
OperationalWebhookEndpointSecretOut = openapi.OperationalWebhookEndpointSecretOut
OperationalWebhookEndpointSecretIn = openapi.OperationalWebhookEndpointSecretIn
Ordering = openapi.Ordering

Check failure on line 16 in go/operational_webhook_endpoint.go

View workflow job for this annotation

GitHub Actions / build

Ordering redeclared in this block
)

type OperationalWebhookEndpoint struct {
api *openapi.APIClient
}

type OperationalWebhookEndpointListOptions struct {
Iterator *string
Limit *int32
Order *Ordering
}

func (e *OperationalWebhookEndpoint) List(ctx context.Context, options *OperationalWebhookEndpointListOptions) (*ListResponseOperationalWebhookEndpointOut, error) {
req := e.api.WebhookEndpointAPI.ListOperationalWebhookEndpoint(ctx)

Check failure on line 30 in go/operational_webhook_endpoint.go

View workflow job for this annotation

GitHub Actions / build

e.api.WebhookEndpointAPI.ListOperationalWebhookEndpoint undefined (type *openapi.WebhookEndpointAPIService has no field or method ListOperationalWebhookEndpoint)
if options != nil {
if options.Iterator != nil {
req = req.Iterator(*options.Iterator)
}
if options.Limit != nil {
req = req.Limit(*options.Limit)
}
if options.Order != nil {
req = req.Order(*options.Order)
}
}
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (e *OperationalWebhookEndpoint) Create(ctx context.Context, endpointIn *OperationalWebhookEndpointIn) (*OperationalWebhookEndpointOut, error) {
return e.CreateWithOptions(ctx, endpointIn, nil)
}

func (e *OperationalWebhookEndpoint) CreateWithOptions(ctx context.Context, endpointIn *OperationalWebhookEndpointIn, options *PostOptions) (*OperationalWebhookEndpointOut, error) {
req := e.api.WebhookEndpointAPI.CreateOperationalWebhookEndpoint(ctx)
req = req.OperationalWebhookEndpointIn(*endpointIn)
if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
}
}
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (e *OperationalWebhookEndpoint) Get(ctx context.Context, endpointId string) (*OperationalWebhookEndpointOut, error) {
req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpoint(ctx, endpointId)
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (e *OperationalWebhookEndpoint) Update(ctx context.Context, endpointId string, endpointUpdate *OperationalWebhookEndpointUpdate) (*OperationalWebhookEndpointOut, error) {
req := e.api.WebhookEndpointAPI.UpdateOperationalWebhookEndpoint(ctx, endpointId)
req = req.OperationalWebhookEndpointUpdate(*endpointUpdate)
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (e *OperationalWebhookEndpoint) Delete(ctx context.Context, endpointId string) error {
req := e.api.WebhookEndpointAPI.DeleteOperationalWebhookEndpoint(ctx, endpointId)
res, err := req.Execute()
return wrapError(err, res)
}

func (e *OperationalWebhookEndpoint) GetSecret(ctx context.Context, endpointId string) (*OperationalWebhookEndpointSecretOut, error) {
req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpointSecret(ctx, endpointId)
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (e *OperationalWebhookEndpoint) RotateSecret(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn) error {
return e.RotateSecretWithOptions(ctx, endpointId, endpointSecretRotateIn, nil)
}

func (e *OperationalWebhookEndpoint) RotateSecretWithOptions(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn, options *PostOptions) error {
req := e.api.WebhookEndpointAPI.RotateOperationalWebhookEndpointSecret(ctx, endpointId)
req = req.OperationalWebhookEndpointSecretIn(*endpointSecretRotateIn)
if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
}
}
res, err := req.Execute()
if err != nil {
return wrapError(err, res)
}
return nil
}
20 changes: 12 additions & 8 deletions go/svix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ type (
HTTPClient *http.Client
}
Svix struct {
Authentication *Authentication
Application *Application
Endpoint *Endpoint
EventType *EventType
Integration *Integration
Message *Message
MessageAttempt *MessageAttempt
Statistics *Statistics
Authentication *Authentication
Application *Application
Endpoint *Endpoint
EventType *EventType
Integration *Integration
Message *Message
MessageAttempt *MessageAttempt
Statistics *Statistics
OperationalWebhookEndpoint *OperationalWebhookEndpoint
}
)

Expand Down Expand Up @@ -108,5 +109,8 @@ func New(token string, options *SvixOptions) *Svix {
Statistics: &Statistics{
api: apiClient,
},
OperationalWebhookEndpoint: &OperationalWebhookEndpoint{
api: apiClient,
},
}
}

0 comments on commit 63c45d1

Please sign in to comment.