diff --git a/src/blueink/client.py b/src/blueink/client.py index fea0dc8..6b85fb5 100644 --- a/src/blueink/client.py +++ b/src/blueink/client.py @@ -19,6 +19,7 @@ def __init__( private_api_key: str = None, base_url: str = None, raise_exceptions: bool = True, + security_headers: dict = None, ): """Initialize a Client instance to access the Blueink eSignature API @@ -29,6 +30,7 @@ def __init__( base_url: override the API base URL. If not supplied, we check the environment variable BLUEINK_API_URL. If that is empty, the default value of "https://api.blueink.com/api/v2" is used. + security_headers: Place for additional security headers, likely unnecessary raise_exceptions (Default True): raise HTTPError if code != 200. Otherwise return as NormalizedResponse objects. @@ -44,9 +46,9 @@ def __init__( if not private_api_key: raise ValueError( - "A Blueink Private API Key must be provided on Client initialization" - " or specified via the environment variable" - " {ENV_BLUEINK_PRIVATE_API_KEY}" + f"A Blueink Private API Key must be provided on Client initialization" + f" or specified via the environment variable" + f" {ENV_BLUEINK_PRIVATE_API_KEY}" ) if not base_url: @@ -57,7 +59,11 @@ def __init__( self._base_url = base_url - self._request_helper = RequestHelper(private_api_key, raise_exceptions) + self._request_helper = RequestHelper( + private_api_key, + raise_exceptions, + security_headers=security_headers, + ) self.bundles = BundleSubClient(self._base_url, self._request_helper) self.persons = PersonSubClient(self._base_url, self._request_helper) diff --git a/src/blueink/request_helper.py b/src/blueink/request_helper.py index f9843da..8dc7cf6 100644 --- a/src/blueink/request_helper.py +++ b/src/blueink/request_helper.py @@ -1,6 +1,5 @@ import requests from munch import munchify -from requests import Request, Session from blueink.constants import BLUEINK_PAGINATION_HEADER @@ -55,9 +54,13 @@ def __init__(self, response: requests.Response): class RequestHelper: - def __init__(self, private_api_key, raise_exceptions=False): + def __init__( + self, private_api_key, raise_exceptions=False, security_headers: dict = None + ): + self._private_api_key = private_api_key self._raise_exceptions = raise_exceptions + self._security_headers = security_headers def delete(self, url, **kwargs): return self._make_request("delete", url, **kwargs) @@ -88,6 +91,9 @@ def _build_headers(self, content_type=None, more_headers=None): if more_headers: hdrs.update(more_headers) + if self._security_headers: + hdrs.update(self._security_headers) + hdrs["Authorization"] = f"Token {self._private_api_key}" if content_type is not None: @@ -120,6 +126,6 @@ def _make_request( ) if self._raise_exceptions: - # print(response.content) response.raise_for_status() + return NormalizedResponse(response) diff --git a/src/blueink/subclients/template.py b/src/blueink/subclients/template.py index 0613b9a..7e4ce06 100644 --- a/src/blueink/subclients/template.py +++ b/src/blueink/subclients/template.py @@ -5,9 +5,6 @@ class TemplateSubClient(SubClient): - def __init__(self, base_url, private_api_key): - super().__init__(base_url, private_api_key) - def paged_list( self, page: int = 1, per_page: int = 50, **query_params ) -> PaginatedIterator: diff --git a/src/blueink/subclients/webhook.py b/src/blueink/subclients/webhook.py index 1adac16..ca0edc0 100644 --- a/src/blueink/subclients/webhook.py +++ b/src/blueink/subclients/webhook.py @@ -4,9 +4,6 @@ class WebhookSubClient(SubClient): - def __init__(self, base_url, private_api_key): - super().__init__(base_url, private_api_key) - # ---------- # Webhooks # ----------