Skip to content

Commit

Permalink
Address the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
caroline-ttd committed Jul 2, 2024
1 parent 4ab20bb commit 890557a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
5 changes: 1 addition & 4 deletions examples/sample_get_identity_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def _usage():

identity_buckets_response = client.get_identity_buckets(datetime.datetime(year, month, day, hour, minute, second))

if identity_buckets_response.buckets:
bucket = identity_buckets_response.buckets[0]
for bucket in identity_buckets_response.buckets:
print("The bucket id of the first bucket: ", bucket.get_bucket_id())
print("The last updated timestamp of the first bucket: ", bucket.get_last_updated())
else:
print("No buckets were returned for this datetime")
20 changes: 15 additions & 5 deletions tests/test_identity_map_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,23 @@ def test_identity_map_hashed_phones(self):
def test_identity_map_client_bad_url(self):
identity_map_input = IdentityMapInput.from_emails(
["[email protected]", "[email protected]", "[email protected]"])
client = IdentityMapClient("https://operator-bad-url.uidapi.com", os.getenv("UID2_API_KEY"), os.getenv("UID2_SECRET_KEY"))
client = IdentityMapClient("https://operator-bad-url.uidapi.com", os.getenv("UID2_API_KEY"),
os.getenv("UID2_SECRET_KEY"))
self.assertRaises(requests.exceptions.ConnectionError, client.generate_identity_map, identity_map_input)
self.assertRaises(requests.exceptions.ConnectionError, client.get_identity_buckets, datetime.datetime.now())

def test_identity_map_client_bad_api_key(self):
identity_map_input = IdentityMapInput.from_emails(
["[email protected]", "[email protected]", "[email protected]"])
client = IdentityMapClient(os.getenv("UID2_BASE_URL"), "bad-api-key", os.getenv("UID2_SECRET_KEY"))
self.assertRaises(requests.exceptions.HTTPError, client.generate_identity_map,identity_map_input)
self.assertRaises(requests.exceptions.HTTPError, client.generate_identity_map, identity_map_input)
self.assertRaises(requests.exceptions.HTTPError, client.get_identity_buckets, datetime.datetime.now())

def test_identity_map_client_bad_secret(self):
identity_map_input = IdentityMapInput.from_emails(
["[email protected]", "[email protected]", "[email protected]"])
client = IdentityMapClient(os.getenv("UID2_BASE_URL"), os.getenv("UID2_API_KEY"), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=")
client = IdentityMapClient(os.getenv("UID2_BASE_URL"), os.getenv("UID2_API_KEY"),
"wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=")
self.assertRaises(requests.exceptions.HTTPError, client.generate_identity_map,
identity_map_input)
self.assertRaises(requests.exceptions.HTTPError, client.get_identity_buckets,
Expand Down Expand Up @@ -182,8 +184,16 @@ def test_identity_buckets_empty_response(self):
self.assertTrue(response.is_success)

def test_identity_buckets_invalid_timestamp(self):
self.assertRaises(TypeError, self.identity_map_client.get_identity_buckets,
"1234567890")
test_cases = ["1234567890",
1234567890,
2024.7,
"2024-7-1",
"2024-07-01T12:00:00",
[2024, 7, 1, 12, 0, 0],
None]
for timestamp in test_cases:
self.assertRaises(AttributeError, self.identity_map_client.get_identity_buckets,
timestamp)


if __name__ == '__main__':
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions uid2_client/identity_map_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from datetime import timezone

from .Identity_buckets_response import IdentityBucketsResponse
from .identity_buckets_response import IdentityBucketsResponse
from .identity_map_response import IdentityMapResponse

from uid2_client import auth_headers, make_v2_request, post, parse_v2_response, get_datetime_iso_format
Expand Down Expand Up @@ -44,7 +44,7 @@ def generate_identity_map(self, identity_map_input):

def get_identity_buckets(self, since_timestamp):
req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc),
json.dumps({"since_timestamp": get_datetime_iso_format(since_timestamp)}).encode())
json.dumps({"since_timestamp": since_timestamp.isoformat()}).encode())
resp = post(self._base_url, '/v2/identity/buckets', headers=auth_headers(self._api_key), data=req)
resp.raise_for_status()
resp_body = parse_v2_response(self._client_secret, resp.text, nonce)
Expand Down
10 changes: 1 addition & 9 deletions uid2_client/input_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,4 @@ def normalize_and_hash_email(email):
def normalize_and_hash_phone(phone):
if not is_phone_number_normalized(phone):
raise ValueError("phone number is not normalized: " + phone)
return get_base64_encoded_hash(phone)


def get_datetime_iso_format(timestamp):
if isinstance(timestamp, datetime.datetime):
return timestamp.isoformat()
else:
raise TypeError("timestamp is not in datetime format")

return get_base64_encoded_hash(phone)

0 comments on commit 890557a

Please sign in to comment.