Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable with syntax and use dedicated httpx.Client instance #205

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/sumo/wrapper/sumo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
raise ValueError(f"Invalid environment: {env}")

self._retry_strategy = retry_strategy
self._client = httpx
self._blob_client = BlobClient(retry_strategy)

access_token = None
Expand Down Expand Up @@ -92,6 +93,14 @@ def __init__(
pass
return

def __enter__(self):
self._client = httpx.Client()
return self

def __exit__(self, exc_type, exc_value, traceback):
self._client.close()
return

def authenticate(self):
if self.auth is None:
return None
Expand Down Expand Up @@ -155,7 +164,7 @@ def get(self, path: str, params: dict = None) -> dict:
headers.update(self.auth.get_authorization())

def _get():
return httpx.get(
return self._client.get(
f"{self.base_url}{path}",
params=params,
headers=headers,
Expand Down Expand Up @@ -229,7 +238,7 @@ def post(
headers.update(self.auth.get_authorization())

def _post():
return httpx.post(
return self._client.post(
f"{self.base_url}{path}",
content=blob,
json=json,
Expand Down Expand Up @@ -276,7 +285,7 @@ def put(
headers.update(self.auth.get_authorization())

def _put():
return httpx.put(
return self._client.put(
f"{self.base_url}{path}",
content=blob,
json=json,
Expand Down Expand Up @@ -315,7 +324,7 @@ def delete(self, path: str, params: dict = None) -> dict:
headers.update(self.auth.get_authorization())

def _delete():
return httpx.delete(
return self._client.delete(
f"{self.base_url}{path}",
headers=headers,
params=params,
Expand Down