Skip to content

Commit 0d2e396

Browse files
committed
Address the comments
1 parent 75d759e commit 0d2e396

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

examples/sample_identity_map_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from uid2_client import IdentityMapClient, IdentityMapInput
44

55

6-
# this sample client takes email addresses or phone numbers as input and generates an IdentityMapResponse object
7-
# which contains raw uid or the reason why it is unmapped
6+
# this sample client takes email addresses or phone numbers or hashed versions of either as input and generates
7+
# an IdentityMapResponse object which contains raw uid or the reason why it is unmapped
88

99
def _usage():
10-
print('Usage: python3 sample_sharing_client.py <base_url> <api_key> <client_secret> <email_1> <email_2> ... <email_n>'
10+
print('Usage: python3 sample_identity_map_client.py <base_url> <api_key> <client_secret> <email_1> <email_2> ... <email_n>'
1111
, file=sys.stderr)
1212
sys.exit(1)
1313

tests/test_identity_map_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def setUpClass(cls):
1818
cls.UID2_API_KEY = os.getenv("UID2_API_KEY")
1919
cls.UID2_SECRET_KEY = os.getenv("UID2_SECRET_KEY")
2020

21-
print(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY)
22-
2321
if cls.UID2_BASE_URL and cls.UID2_API_KEY and cls.UID2_SECRET_KEY:
2422
cls.identity_map_client = IdentityMapClient(cls.UID2_BASE_URL, cls.UID2_API_KEY, cls.UID2_SECRET_KEY)
2523
else:

uid2_client/identity_map_input.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22

3-
from uid2_client import IdentityType, normalize_email_string, get_base64_encoded_hash, is_phone_number_normalized, \
4-
normalize_and_hash_email, normalize_and_hash_phone
3+
from uid2_client import IdentityType, normalize_and_hash_email, normalize_and_hash_phone
54

65

76
class IdentityMapInput:
@@ -13,19 +12,19 @@ def __init__(self, identity_type, emails_or_phones, already_hashed):
1312
self.hashed_normalized_phones = None
1413
if identity_type == IdentityType.Email:
1514
self.hashed_normalized_emails = []
16-
for email in emails_or_phones:
17-
if already_hashed:
18-
self.hashed_normalized_emails.append(email)
19-
else:
15+
if already_hashed:
16+
self.hashed_normalized_emails = emails_or_phones
17+
else:
18+
for email in emails_or_phones:
2019
hashed_normalized_email = normalize_and_hash_email(email)
2120
self._add_hashed_to_raw_dii_mapping(hashed_normalized_email, email)
2221
self.hashed_normalized_emails.append(hashed_normalized_email)
2322
else: # phone
2423
self.hashed_normalized_phones = []
25-
for phone in emails_or_phones:
26-
if already_hashed:
27-
self.hashed_normalized_phones.append(phone)
28-
else:
24+
if already_hashed:
25+
self.hashed_normalized_phones = emails_or_phones
26+
else:
27+
for phone in emails_or_phones:
2928
hashed_normalized_phone = normalize_and_hash_phone(phone)
3029
self._add_hashed_to_raw_dii_mapping(hashed_normalized_phone, phone)
3130
self.hashed_normalized_phones.append(hashed_normalized_phone)

uid2_client/identity_map_response.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,47 @@
33

44
class IdentityMapResponse:
55
def __init__(self, response, identity_map_input):
6-
self.mapped_identities = {}
7-
self.unmapped_identities = {}
6+
self._mapped_identities = {}
7+
self._unmapped_identities = {}
88
response_json = json.loads(response)
9-
self.status = response_json["status"]
9+
self._status = response_json["status"]
1010

1111
if not self.is_success():
12-
raise ValueError("Got unexpected identity map status: " + self.status)
12+
raise ValueError("Got unexpected identity map status: " + self._status)
1313

14-
body = self._get_body_as_json(response_json)
14+
body = response_json["body"]
1515

1616
for identity in body.get("mapped", []):
1717
raw_diis = self._get_raw_diis(identity, identity_map_input)
1818
mapped_identity = MappedIdentity.from_json(identity)
1919
for raw_dii in raw_diis:
20-
self.mapped_identities[raw_dii] = mapped_identity
20+
self._mapped_identities[raw_dii] = mapped_identity
2121

2222
for identity in body.get("unmapped", []):
2323
raw_diis = self._get_raw_diis(identity, identity_map_input)
2424
unmapped_identity = UnmappedIdentity.from_json(identity)
2525
for raw_dii in raw_diis:
26-
self.unmapped_identities[raw_dii] = unmapped_identity
27-
28-
@staticmethod
29-
def _get_body_as_json(json_response):
30-
return json_response["body"]
26+
self._unmapped_identities[raw_dii] = unmapped_identity
3127

3228
@staticmethod
3329
def _get_raw_diis(identity, identity_map_input):
3430
identifier = identity["identifier"]
3531
return identity_map_input.get_raw_diis(identifier)
3632

3733
def is_success(self):
38-
return self.status == "success"
34+
return self._status == "success"
35+
36+
@property
37+
def mapped_identities(self):
38+
return self._mapped_identities
39+
40+
@property
41+
def unmapped_identities(self):
42+
return self._unmapped_identities
43+
44+
@property
45+
def status(self):
46+
return self._status
3947

4048

4149
class MappedIdentity:

0 commit comments

Comments
 (0)