-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsample_generate_identity_map_v3.py
More file actions
42 lines (32 loc) · 1.47 KB
/
sample_generate_identity_map_v3.py
File metadata and controls
42 lines (32 loc) · 1.47 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
import sys
from uid2_client import IdentityMapV3Client, IdentityMapV3Input
# !! Note: This is for the newest version of identity map. For the previous version, see sample_generate_identity_map.py
# this sample client takes email addresses as input and generates an IdentityMapV3Response object which contains raw uid
# or the reason why it is unmapped
def _usage():
print('Usage: python3 sample_generate_identity_map_v3.py <base_url> <api_key> <client_secret> <email_1> <email_2> ... <email_n>'
, file=sys.stderr)
sys.exit(1)
if len(sys.argv) <= 4:
_usage()
base_url = sys.argv[1]
api_key = sys.argv[2]
client_secret = sys.argv[3]
email_list = sys.argv[4:]
first_email = sys.argv[4]
client = IdentityMapV3Client(base_url, api_key, client_secret)
identity_map_response = client.generate_identity_map(IdentityMapV3Input.from_emails(email_list))
mapped_identities = identity_map_response.mapped_identities
unmapped_identities = identity_map_response.unmapped_identities
mapped_identity = mapped_identities.get(first_email)
if mapped_identity is not None:
current_uid = mapped_identity.current_raw_uid
previous_uid = mapped_identity.previous_raw_uid
refresh_from = mapped_identity.refresh_from
print('current_uid =', current_uid)
print('previous_uid =', str(previous_uid))
print('refresh_from =', str(refresh_from))
else:
unmapped_identity = unmapped_identities.get(first_email)
reason = unmapped_identity.reason
print('reason =', reason)