forked from splitio-examples/splitcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers_api.py
More file actions
57 lines (49 loc) · 1.45 KB
/
Copy pathusers_api.py
File metadata and controls
57 lines (49 loc) · 1.45 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
53
54
55
56
57
from splitcli.split_apis import http_client
# URLs
def users_url():
return f"users"
def user_url(user_id):
base_url = users_url()
return f"{base_url}/{user_id}"
def invite_user(email, group_ids):
groups = list(map(lambda x: {"id":x, "type":"group"}, group_ids))
content = {
"email": email,
"groups":groups
}
http_client.post(users_url(), content)
def list_users(status=None,group_id=None):
all_users = []
next_marker = None
# Stop once a batch is smaller than the limit
while True:
result = list_users_batch(next_marker, status, group_id)
next_marker = result['nextMarker']
data = result['data']
if len(data) != 0:
all_users.extend(data)
if next_marker is None:
break
return all_users
def list_users_batch(next=None, status=None, group_id=None):
path = users_url()
query = ""
if next is not None:
query += f"after={next}"
if status is not None:
query += f"status={status}"
if group_id is not None:
query += f"group_id={group_id}"
if len(query) > 0:
path += f"?{query}"
return http_client.get(path)
def get_user_by_email(email):
users = list_users(status="ACTIVE")
match = list(filter(lambda x: x['email'] == email, users))
if len(match) == 1:
return match[0]
else:
return None
def get_user(user_id):
path = user_url(user_id)
return http_client.get(path)