|
| 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.V1OperationalWebhookEndpointDelete(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 | +} |
0 commit comments