/
organization_user.go
86 lines (69 loc) · 2.47 KB
/
organization_user.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
// Package aiven provides a client for using the Aiven API.
package aiven
type (
// OrganizationUserHandler is the client which interacts with the Organization Users API on Aiven.
OrganizationUserHandler struct {
// client is the API client to use.
client *Client
}
// OrganizationUserList is a response from Aiven for a list of organization users.
OrganizationUserList struct {
APIResponse
// Users is a list of organization users.
Users []OrganizationMemberInfo `json:"users"`
}
// OrganizationMemberInfo is a struct that represents a user's membership in an organization.
OrganizationMemberInfo struct {
APIResponse
// UserID is the unique identifier of the user.
UserID string `json:"user_id"`
// JoinTime is the time when the user joined the organization.
JoinTime string `json:"join_time"`
// UserInfo is the information of the user.
UserInfo OrganizationUserInfo `json:"user_info"`
}
// OrganizationUserInfo is a struct that represents a user in an organization.
OrganizationUserInfo struct {
// UserEmail is the email of the user.
UserEmail string `json:"user_email"`
// RealName is the real name of the user.
RealName string `json:"real_name"`
// State is the state of the user.
State string `json:"state"`
// JobTitle is the job title of the user.
JobTitle string `json:"job_title"`
// Country is the country of the user.
Country string `json:"country"`
// Department is the department of the user.
Department string `json:"department"`
}
)
// List returns a list of all organization user invitations.
func (h *OrganizationUserHandler) List(id string) (*OrganizationUserList, error) {
path := buildPath("organization", id, "user")
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var r OrganizationUserList
return &r, checkAPIResponse(bts, &r)
}
// Get returns a single organization user invitation.
func (h *OrganizationUserHandler) Get(id, userID string) (*OrganizationMemberInfo, error) {
path := buildPath("organization", id, "user", userID)
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var r OrganizationMemberInfo
return &r, checkAPIResponse(bts, &r)
}
// Delete deletes a single organization user invitation.
func (h *OrganizationUserHandler) Delete(id, userID string) error {
path := buildPath("organization", id, "user", userID)
bts, err := h.client.doDeleteRequest(path, nil)
if err != nil {
return err
}
return checkAPIResponse(bts, nil)
}