diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index d050456..d77ec9d 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -1,6 +1,7 @@ import base64 import datetime as dt import json +import time from datetime import timezone from .identity_buckets_response import IdentityBucketsResponse @@ -37,9 +38,12 @@ def __init__(self, base_url, api_key, client_secret): def generate_identity_map(self, identity_map_input): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), identity_map_input.get_identity_map_input_as_json_string().encode()) + start_time = time.time() resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) - return IdentityMapResponse(resp_body, identity_map_input) + end_time = time.time() + elapsed_time = end_time - start_time + return IdentityMapResponse(resp_body, identity_map_input, elapsed_time) def get_identity_buckets(self, since_timestamp): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), diff --git a/uid2_client/identity_map_response.py b/uid2_client/identity_map_response.py index 814cd74..5fe9487 100644 --- a/uid2_client/identity_map_response.py +++ b/uid2_client/identity_map_response.py @@ -2,12 +2,17 @@ class IdentityMapResponse: - def __init__(self, response, identity_map_input): + def __init__(self, response, identity_map_input, elapsed_time=None): self._mapped_identities = {} self._unmapped_identities = {} + self._response = response + self._elapsed_time = None response_json = json.loads(response) self._status = response_json["status"] + if elapsed_time is not None: + self._elapsed_time = elapsed_time + if not self.is_success(): raise ValueError("Got unexpected identity map status: " + self._status) @@ -44,6 +49,15 @@ def unmapped_identities(self): @property def status(self): return self._status + + @property + def elapsed_time(self): + return self._elapsed_time + + + @property + def response(self): + return self._response class MappedIdentity: