-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdestinations.go
123 lines (93 loc) · 3.03 KB
/
destinations.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//go:generate go run tools/withoutctx.go
package redash
import (
"context"
"fmt"
"github.com/winebarrel/redash-go/v2/internal/util"
)
type Destination struct {
Icon string `json:"icon"`
ID int `json:"id"`
Name string `json:"name"`
Options map[string]any `json:"options"`
Type string `json:"type"`
}
func (client *Client) ListDestinations(ctx context.Context) ([]Destination, error) {
res, close, err := client.Get(ctx, "api/destinations", nil)
defer close()
if err != nil {
return nil, err
}
destinations := []Destination{}
if err := util.UnmarshalBody(res, &destinations); err != nil {
return nil, err
}
return destinations, nil
}
func (client *Client) GetDestination(ctx context.Context, id int) (*Destination, error) {
res, close, err := client.Get(ctx, fmt.Sprintf("api/destinations/%d", id), nil)
defer close()
if err != nil {
return nil, err
}
dest := &Destination{}
if err := util.UnmarshalBody(res, &dest); err != nil {
return nil, err
}
return dest, nil
}
type CreateDestinationInput struct {
Name string `json:"name"`
Options map[string]any `json:"options"`
Type string `json:"type"`
}
func (client *Client) CreateDestination(ctx context.Context, input *CreateDestinationInput) (*Destination, error) {
res, close, err := client.Post(ctx, "api/destinations", input)
defer close()
if err != nil {
return nil, err
}
dest := &Destination{}
if err := util.UnmarshalBody(res, &dest); err != nil {
return nil, err
}
return dest, nil
}
func (client *Client) DeleteDestination(ctx context.Context, id int) error {
_, close, err := client.Delete(ctx, fmt.Sprintf("api/destinations/%d", id))
defer close()
if err != nil {
return err
}
return nil
}
type DestinationType struct {
ConfigurationSchema DestinationTypeConfigurationSchema `json:"configuration_schema"`
Icon string `json:"icon"`
Name string `json:"name"`
Type string `json:"type"`
}
type DestinationTypeConfigurationSchema struct {
ExtraOptions []string `json:"extra_options"`
Properties map[string]DestinationTypeConfigurationSchemaProperty `json:"properties"`
Required []string `json:"required"`
Secret any `json:"secret"`
Type string `json:"type"`
}
type DestinationTypeConfigurationSchemaProperty struct {
Default any `json:"default"`
Title string `json:"title"`
Type string `json:"type"`
}
func (client *Client) GetDestinationTypes(ctx context.Context) ([]DestinationType, error) {
res, close, err := client.Get(ctx, "api/destinations/types", nil)
defer close()
if err != nil {
return nil, err
}
types := []DestinationType{}
if err := util.UnmarshalBody(res, &types); err != nil {
return nil, err
}
return types, nil
}