forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_team_members.go
93 lines (77 loc) · 2.66 KB
/
account_team_members.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
// Copyright (c) 2020 Aiven, Helsinki, Finland. https://aiven.io/
package aiven
import (
"errors"
"time"
)
type (
// AccountTeamMembersHandler Aiven go-client handler for Account Team Members
AccountTeamMembersHandler struct {
client *Client
}
// AccountTeamMember represents an account team member
AccountTeamMember struct {
UserId string `json:"user_id,omitempty"`
RealName string `json:"real_name,omitempty"`
TeamId string `json:"team_id,omitempty"`
TeamName string `json:"team_name,omitempty"`
UserEmail string `json:"user_email,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
}
// AccountTeamMembersResponse represents account team members API response
AccountTeamMembersResponse struct {
APIResponse
Members []AccountTeamMember `json:"members"`
}
// AccountTeamMemberResponse represents a account team member API response
AccountTeamMemberResponse struct {
APIResponse
Member AccountTeamMember `json:"member"`
}
)
// List returns a list of all existing account team members
func (h AccountTeamMembersHandler) List(accountId, teamId string) (*AccountTeamMembersResponse, error) {
if accountId == "" || teamId == "" {
return nil, errors.New("cannot get a list of team members when account id or team id is empty")
}
path := buildPath("account", accountId, "team", teamId, "members")
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var rsp AccountTeamMembersResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}
// Invite invites a team member
func (h AccountTeamMembersHandler) Invite(accountId, teamId, email string) error {
if accountId == "" || teamId == "" {
return errors.New("cannot invite a team members when account id or team id is empty")
}
if email == "" {
return errors.New("cannot invite a team members when email is empty")
}
path := buildPath("account", accountId, "team", teamId, "members")
bts, err := h.client.doPostRequest(path, struct {
Email string `json:"email"`
}{Email: email})
if err != nil {
return err
}
return checkAPIResponse(bts, nil)
}
// Delete deletes an existing account team member
func (h AccountTeamMembersHandler) Delete(accountId, teamId, userId string) error {
if accountId == "" || teamId == "" || userId == "" {
return errors.New("cannot delete a team member when account id or team id or user id is empty")
}
path := buildPath("account", accountId, "team", teamId, "member", userId)
bts, err := h.client.doDeleteRequest(path, nil)
if err != nil {
return err
}
return checkAPIResponse(bts, nil)
}