-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
80 lines (58 loc) · 2.52 KB
/
examples.py
File metadata and controls
80 lines (58 loc) · 2.52 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from src.karatclient import KaratClient
from pprint import pprint
import os
if 'TOKEN' not in os.environ or 'SUBDOMAIN' not in os.environ:
print('No token found. Please run this script as `TOKEN=your-token-here ENVIRONMENT=[production/test/development] SUBDOMAIN=your-subdomain-here python examples.py`')
exit()
print('\n------ Instantiating a client\n')
kc = KaratClient(
token=os.environ['TOKEN'],
environment=os.environ.get('ENVIRONMENT'),
subdomain=os.environ.get('SUBDOMAIN')
)
print('\n------ Listing available operations\n')
print('Available mutations:', kc.mutations())
print('Available queries:', kc.queries())
print('\n------ Getting an operation and reporting what it expects\n')
print('Args for \'users\' query:')
user_query = kc.query('users')
print('All:', user_query.possible_args())
print('Mandatory:', user_query.mandatory_args())
print()
print('Args for \'invite\' mutation:')
invite_mutation = kc.mutation('invite')
print('All:', invite_mutation.possible_args())
print('Mandatory:', invite_mutation.mandatory_args())
print('\n------ Fluent querying\n')
print('Getting users:')
result = kc.query('users').set_param('clientUserType', 'ADMIN').set_params({'disabled': False, 'first': 1}).execute()
pprint(result)
print()
print('\n------ non-fluent querying\n')
print('Getting groups:')
group_query = kc.query('groups')
group_query.set_param('first', 1)
result2 = group_query.execute()
pprint(result2)
print('\n------ fluent mutations\n')
print('Sending an invite (This will fail due to missing arguments!):')
try:
result2 = kc.mutation('invite').set_param('email', 'user@example.com').execute()
except Exception as ex:
print(f'Exception received! {ex}')
print('\n------ non-fluent mutations\n')
print('Sending disposition (This will fail for a variety of reasons!):')
disposition_mutation = kc.mutation('disposition')
try:
# This method isn't available for disposition mutations, and is reported via exception:
disposition_mutation.set_param('email', 'user@example.com')
except Exception as ex:
print(f'Exception received! {ex}')
# Now we know which method to use instead!
disposition_mutation.add_outcome('DECLINED_AT_ONSITE_INTERVIEW', ['1', '24'])
disposition_mutation.add_outcome('OFFER_ACCEPTED', ['153', '123'])
disposition_mutation.add_outcome('OFFER_ACCEPTED', '17') # can accept either lists or individual IDs
try:
disposition_mutation.execute()
except Exception as ex:
print(f'Exception received (likely invalid permissions against the provided candidacy IDs - you can replace these with your own): {ex}')