-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_groups.py
More file actions
36 lines (26 loc) · 937 Bytes
/
get_groups.py
File metadata and controls
36 lines (26 loc) · 937 Bytes
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
import requests
from pywell.entry_points import run_from_cli
from get_token import get_token
DESCRIPTION = 'Get user groups.'
ARG_DEFINITIONS = {
'REACH_API_USER': 'Reach.vote API username.',
'REACH_API_PASS': 'Reach.vote API password.',
'REACH_API_TOKEN': 'Reach.vote API token.'
}
REQUIRED_ARGS = []
def get_groups(args):
if not args.REACH_API_TOKEN:
args.REACH_API_TOKEN = get_token(args)
result = requests.get(
'https://api.reach.vote/api/v1/user_groups',
headers={
'Authorization': 'Bearer %s' % args.REACH_API_TOKEN,
}
)
if result.status_code == 404:
return {'user_groups': []}
if result.status_code != 200:
return 'Error: %s %s' % (result.status_code, result.json().get('detail', '(no error detail)'))
return result.json()
if __name__ == '__main__':
run_from_cli(get_groups, DESCRIPTION, ARG_DEFINITIONS, REQUIRED_ARGS)