-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploygate_organization_member.go
87 lines (68 loc) · 2.09 KB
/
deploygate_organization_member.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
package deploygate
import "fmt"
type GetOrganizationMemberInput struct {
OrganizationName string
}
type GetOrganizationMemberResponse struct {
Error bool `mapstructure:"error"`
Members []*Member `mapstructure:"members"`
}
type Member struct {
UserName string `mapstructure:"username"`
Email string `mapstructure:"email"`
IconURL string `mapstructure:"icon_url"`
Inviting bool `mapstructure:"inviting"`
}
func (c *Client) GetOrganizationMember(i *GetOrganizationMemberInput) (*GetOrganizationMemberResponse, error) {
path := fmt.Sprintf("/organizations/%s/members", i.OrganizationName)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var g *GetOrganizationMemberResponse
if err := decodeJSON(&g, resp.Body); err != nil {
return nil, err
}
return g, nil
}
type AddOrganizationMemberInput struct {
OrganizationName string `form:"-"`
UserName string `form:"username,omitempty"`
Email string `form:"email,omitempty"`
}
type AddOrganizationMemberResponse struct {
Error bool `mapstructure:"error"`
Message string `mapstructure:"message"`
}
func (c *Client) AddOrganizationMember(i *AddOrganizationMemberInput) (*AddOrganizationMemberResponse, error) {
path := fmt.Sprintf("/organizations/%s/members", i.OrganizationName)
resp, err := c.PostForm(path, i, nil)
if err != nil {
return nil, err
}
var a *AddOrganizationMemberResponse
if err := decodeJSON(&a, resp.Body); err != nil {
return nil, err
}
return a, nil
}
type DeleteOrganizationMemberInput AddOrganizationMemberInput
type DeleteOrganizationMemberResponse AddOrganizationMemberResponse
func (c *Client) DeleteOrganizationMember(i *DeleteOrganizationMemberInput) (*DeleteOrganizationMemberResponse, error) {
var id string
if i.UserName != "" {
id = i.UserName
} else {
id = i.Email
}
path := fmt.Sprintf("/organizations/%s/members/%s", i.OrganizationName, id)
resp, err := c.DeleteForm(path, i, nil)
if err != nil {
return nil, err
}
var d *DeleteOrganizationMemberResponse
if err := decodeJSON(&d, resp.Body); err != nil {
return nil, err
}
return d, nil
}