-
Notifications
You must be signed in to change notification settings - Fork 23
/
channel.go
75 lines (60 loc) · 2.04 KB
/
channel.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
package enterpriseclient
import (
"fmt"
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/enterprisetypes"
)
func (c HTTPClient) ListChannels() ([]*enterprisetypes.Channel, error) {
enterpriseChannels := []*enterprisetypes.Channel{}
err := c.doJSON("GET", "/v1/channels", 200, nil, &enterpriseChannels)
if err != nil {
return nil, errors.Wrap(err, "failed to get channels")
}
return enterpriseChannels, nil
}
func (c HTTPClient) CreateChannel(name string, description string) (*enterprisetypes.Channel, error) {
type CreateChannelRequest struct {
Name string `json:"name"`
Description string `json:"description"`
}
createChannelRequest := CreateChannelRequest{
Name: name,
Description: description,
}
enterpriseChannel := enterprisetypes.Channel{}
err := c.doJSON("POST", "/v1/channel", 201, createChannelRequest, &enterpriseChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to create channel")
}
return &enterpriseChannel, nil
}
func (c HTTPClient) UpdateChannel(id string, name string, description string) (*enterprisetypes.Channel, error) {
type UpdateChannelRequest struct {
Name string `json:"name"`
Description string `json:"description"`
}
updateChannelRequest := UpdateChannelRequest{
Name: name,
Description: description,
}
enterpriseChannel := enterprisetypes.Channel{}
err := c.doJSON("PUT", fmt.Sprintf("/v1/channel/%s", id), 200, updateChannelRequest, &enterpriseChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to update channel")
}
return &enterpriseChannel, nil
}
func (c HTTPClient) RemoveChannel(id string) error {
err := c.doJSON("DELETE", fmt.Sprintf("/v1/channel/%s", id), 204, nil, nil)
if err != nil {
return errors.Wrap(err, "failed to delete channel")
}
return nil
}
func (c HTTPClient) AssignChannel(channelID string, teamID string) error {
err := c.doJSON("POST", fmt.Sprintf("/v1/teamchannel/%s/%s", channelID, teamID), 204, nil, nil)
if err != nil {
return errors.Wrap(err, "failed to assign channel")
}
return nil
}