forked from desertbit/wego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_integrations.go
167 lines (134 loc) · 4.7 KB
/
client_integrations.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import (
"context"
"errors"
"io"
)
// GetAllIntegrations performs a get_all_integrations request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_integrations
func (c *Client) GetAllIntegrations(ctx context.Context, boardID string) (integrations []Integration, err error) {
endpoint := c.endpoint("boards", boardID, "integrations")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &integrations)
if err != nil {
return
}
return
}
// NewIntegration performs a new_integration request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_integration
func (c *Client) NewIntegration(ctx context.Context, boardID, url string) (r NewIntegrationResponse, err error) {
endpoint := c.endpoint("boards", boardID, "integrations")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, newIntegrationRequest{Url: url})
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetIntegration performs a get_integration request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_integration
//
// Returns ErrNotFound, if the integration could not be found.
func (c *Client) GetIntegration(ctx context.Context, boardID, integrationID string) (integration Integration, err error) {
endpoint := c.endpoint("boards", boardID, "integrations", integrationID)
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &integration)
if err != nil {
if errors.Is(err, io.EOF) {
err = ErrNotFound
}
return
}
return
}
// EditIntegration performs a edit_integration request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#edit_integration
func (c *Client) EditIntegration(ctx context.Context, boardID, integrationID string, data EditIntegrationOptions) (err error) {
endpoint := c.endpoint("boards", boardID, "integrations", integrationID)
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, data)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// DeleteIntegration performs a delete_integration request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_integration
func (c *Client) DeleteIntegration(ctx context.Context, boardID, integrationID string) (err error) {
endpoint := c.endpoint("boards", boardID, "integrations", integrationID)
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// DeleteIntegrationActivities performs a delete_integration_activities request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_integration_activities
func (c *Client) DeleteIntegrationActivities(ctx context.Context, boardID, integrationID string) (err error) {
endpoint := c.endpoint("boards", boardID, "integrations", integrationID, "activities")
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// NewIntegrationActivities performs a new_integration_activities request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_integration_activities
func (c *Client) NewIntegrationActivities(ctx context.Context, boardID, integrationID string, activities []string) (integration Integration, err error) {
endpoint := c.endpoint("boards", boardID, "integrations", integrationID, "activities")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, newIntegrationActivitiesRequest{Activities: activities})
if err != nil {
return
}
err = c.doSimpleRequest(req, &integration)
if err != nil {
return
}
return
}
//#############//
//### Types ###//
//#############//
type Integration struct {
Enabled bool `json:"enabled"`
Title string `json:"title"`
Type string `json:"type"`
Activities []string `json:"activities"`
Url string `json:"url"`
Token string `json:"token"`
BoardID string `json:"boardId"`
CreatedAt string `json:"createdAt"`
ModifiedAt string `json:"modifiedAt"`
UserID string `json:"userId"`
}
type newIntegrationRequest struct {
Url string `json:"url"`
}
type NewIntegrationResponse struct {
ID string `json:"_id"`
}
type EditIntegrationOptions struct {
Enabled bool `json:"enabled"`
Title string `json:"title"`
Url string `json:"url"`
Token string `json:"token"`
Activities []string `json:"activities"`
}
type newIntegrationActivitiesRequest struct {
Activities []string `json:"activities"`
}