-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorganisation.go
More file actions
52 lines (45 loc) · 1.15 KB
/
organisation.go
File metadata and controls
52 lines (45 loc) · 1.15 KB
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
package flagsmithapi
import (
"fmt"
)
func (c *Client) GetOrganisationByUUID(orgUUID string) (*Organisation, error) {
url := fmt.Sprintf("%s/organisations/get-by-uuid/%s/", c.baseURL, orgUUID)
organisation := Organisation{}
resp, err := c.client.R().
SetResult(&organisation).
Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting organisation: %s", resp)
}
return &organisation, nil
}
func (c *Client) GetOrganisationUsers(orgID int64) ([]User, error) {
url := fmt.Sprintf("%s/organisations/%d/users/", c.baseURL, orgID)
users := []User{}
resp, err := c.client.R().
SetResult(&users).
Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting organisation users: %s", resp)
}
return users, nil
}
func (c *Client) GetOrganisationUserByEmail(orgID int64, email string) (*User, error) {
users, err := c.GetOrganisationUsers(orgID)
if err != nil {
return nil, err
}
for i := range users {
if users[i].Email == email {
u := users[i]
return &u, nil
}
}
return nil, UserNotFoundError{email: email}
}