forked from svix/svix-webhooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.go
73 lines (64 loc) · 1.92 KB
/
application.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package svix
import (
"context"
"github.com/svixhq/svix-libs/go/internal/openapi"
)
type (
ListResponseApplicationOut openapi.ListResponseApplicationOut
ApplicationIn openapi.ApplicationIn
ApplicationOut openapi.ApplicationOut
)
type Application struct {
api *openapi.APIClient
}
func (a *Application) List(options *FetchOptions) (*ListResponseApplicationOut, error) {
req := a.api.ApplicationApi.ListApplicationsApiV1AppGet(context.Background())
if options != nil {
if options.Iterator != nil {
req = req.Iterator(*options.Iterator)
}
if options.Limit != nil {
req = req.Limit(*options.Limit)
}
}
resp, _, err := req.Execute()
if err != nil {
return nil, err
}
ret := ListResponseApplicationOut(resp)
return &ret, nil
}
func (a *Application) Create(applicationIn *ApplicationIn) (*ApplicationOut, error) {
req := a.api.ApplicationApi.CreateApplicationApiV1AppPost(context.Background())
req = req.ApplicationIn(openapi.ApplicationIn(*applicationIn))
resp, _, err := req.Execute()
if err != nil {
return nil, err
}
ret := ApplicationOut(resp)
return &ret, nil
}
func (a *Application) Get(appId string) (*ApplicationOut, error) {
req := a.api.ApplicationApi.GetApplicationApiV1AppAppIdGet(context.Background(), appId)
resp, _, err := req.Execute()
if err != nil {
return nil, err
}
ret := ApplicationOut(resp)
return &ret, nil
}
func (a *Application) Update(appId string, applicationIn *ApplicationIn) (*ApplicationOut, error) {
req := a.api.ApplicationApi.UpdateApplicationApiV1AppAppIdPut(context.Background(), appId)
req = req.ApplicationIn(openapi.ApplicationIn(*applicationIn))
resp, _, err := req.Execute()
if err != nil {
return nil, err
}
ret := ApplicationOut(resp)
return &ret, nil
}
func (a *Application) Delete(appId string) error {
req := a.api.ApplicationApi.DeleteApplicationApiV1AppAppIdDelete(context.Background(), appId)
_, err := req.Execute()
return err
}