This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
members.go
66 lines (53 loc) · 1.91 KB
/
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
package packngo
import "path"
// API documentation https://metal.equinix.com/developers/api#tag/Memberships
const membersBasePath = "/members"
// OrganizationService interface defines available organization methods
type MemberService interface {
List(string, *ListOptions) ([]Member, *Response, error)
Delete(string, string) (*Response, error)
}
type membersRoot struct {
Members []Member `json:"members"`
Meta meta `json:"meta"`
}
// Member is the returned from organization/id/members
type Member struct {
*Href `json:",inline"`
ID string `json:"id"`
Roles []string `json:"roles"`
ProjectsCount int `json:"projects_count"`
User User `json:"user"`
Organization Organization `json:"organization"`
Projects []Project `json:"projects"`
}
// MemberServiceOp implements MemberService
type MemberServiceOp struct {
client *Client
}
var _ MemberService = (*MemberServiceOp)(nil)
// List returns the members in an organization
func (s *MemberServiceOp) List(organizationID string, opts *ListOptions) (orgs []Member, resp *Response, err error) {
subset := new(membersRoot)
endpointPath := path.Join(organizationBasePath, organizationID, membersBasePath)
apiPathQuery := opts.WithQuery(endpointPath)
for {
resp, err = s.client.DoRequest("GET", apiPathQuery, nil, subset)
if err != nil {
return nil, resp, err
}
orgs = append(orgs, subset.Members...)
if apiPathQuery = nextPage(subset.Meta, opts); apiPathQuery != "" {
continue
}
return
}
}
// Delete removes the given member from the given organization
func (s *MemberServiceOp) Delete(organizationID, memberID string) (*Response, error) {
if validateErr := ValidateUUID(organizationID); validateErr != nil {
return nil, validateErr
}
apiPath := path.Join(organizationBasePath, organizationID, membersBasePath, memberID)
return s.client.DoRequest("DELETE", apiPath, nil, nil)
}