-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploygate_app.go
99 lines (79 loc) · 2.56 KB
/
deploygate_app.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
package deploygate
import "fmt"
type GetAppCollaboratorInput struct {
Owner string
Platform string
AppId string
}
type GetAppCollaboratorResponse struct {
Error bool `mapstructure:"error"`
Results *GetAppCollaboratorResponseResult `mapstructure:"results"`
}
type AccountsUsage struct {
Used uint `mapstructure:"used"`
Max uint `mapstructure:"max"`
}
type GetAppCollaboratorResponseResult struct {
Usage *AccountsUsage `mapstructure:"usage"`
Users []*Collaborator `mapstructure:"users"`
Teams []*Collaborator `mapstructure:"teams"`
}
func (c *Client) GetAppCollaborator(i *GetAppCollaboratorInput) (*GetAppCollaboratorResponse, error) {
path := fmt.Sprintf("/users/%s/platforms/%s/apps/%s/members", i.Owner, i.Platform, i.AppId)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var g *GetAppCollaboratorResponse
if err := decodeJSON(&g, resp.Body); err != nil {
return nil, err
}
return g, nil
}
type AddAppCollaboratorInput struct {
Owner string `form:"-"`
Platform string `form:"-"`
AppId string `form:"-"`
Users string `form:"users"`
Role int `form:"role"`
}
type AddAppCollaboratorResponse struct {
Error bool `mapstructure:"error"`
Results *AddAppCollaboratorResponseResult `mapstructure:"results"`
}
type Collaborator struct {
Name string `mapstructure:"name"`
Role uint `mapstructure:"role"`
}
type AddAppCollaboratorResponseResult struct {
Invite string `mapstructure:"invite"`
Added []*Collaborator `mapstructure:"added"`
Invited []*Collaborator `mapstructure:"invited"`
}
// https://docs.deploygate.com/reference#invite
func (c *Client) AddAppCollaborator(i *AddAppCollaboratorInput) (*AddAppCollaboratorResponse, error) {
path := fmt.Sprintf("/users/%s/platforms/%s/apps/%s/members", i.Owner, i.Platform, i.AppId)
resp, err := c.PostForm(path, i, nil)
if err != nil {
return nil, err
}
var a *AddAppCollaboratorResponse
if err := decodeJSON(&a, resp.Body); err != nil {
return nil, err
}
return a, nil
}
type DeleteAppCollaboratorInput AddAppCollaboratorInput
type DeleteAppCollaboratorResponse AddAppCollaboratorResponse
func (c *Client) DeleteAppCollaborator(i *DeleteAppCollaboratorInput) (*DeleteAppCollaboratorResponse, error) {
path := fmt.Sprintf("/users/%s/platforms/%s/apps/%s/members", i.Owner, i.Platform, i.AppId)
resp, err := c.DeleteForm(path, i, nil)
if err != nil {
return nil, err
}
var a *DeleteAppCollaboratorResponse
if err := decodeJSON(&a, resp.Body); err != nil {
return nil, err
}
return a, nil
}