Skip to content

Commit

Permalink
httptclient patch update to accept infinity float
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Papon authored and Julien Papon committed Jul 26, 2024
1 parent ebb85b3 commit ef1a656
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions geosyspy/utils/http_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
""" http client class"""

import json

from oauthlib.oauth2 import TokenExpiredError
from requests_oauthlib import OAuth2Session

from . import oauth2_client


def renew_access_token(func):
"""Decorator used to wrap the Geosys class's http methods.
Expand All @@ -22,6 +26,7 @@ def wrapper(self, *args, **kwargs):

return wrapper


class HttpClient:
"""A class for making HTTP requests with OAuth2 authentication.
Expand All @@ -32,15 +37,16 @@ class HttpClient:
get_access_token(): Returns the access token.
"""

def __init__(
self,
client_id: str,
client_secret: str,
username: str,
password: str,
enum_env: str,
enum_region: str,
bearer_token: str = None
self,
client_id: str,
client_secret: str,
username: str,
password: str,
enum_env: str,
enum_region: str,
bearer_token: str = None,
):
self.__client_oauth = oauth2_client.Oauth2Api(
client_id=client_id,
Expand All @@ -49,15 +55,16 @@ def __init__(
username=username,
enum_env=enum_env,
enum_region=enum_region,
bearer_token=bearer_token
bearer_token=bearer_token,
)
self.access_token = self.__client_oauth.token

self.__client = OAuth2Session(self.__client_oauth.client_id,
token=self.__client_oauth.token)

self.__client = OAuth2Session(
self.__client_oauth.client_id, token=self.__client_oauth.token
)

@renew_access_token
def get(self, url_endpoint: str, headers=None, verify_ssl = True):
def get(self, url_endpoint: str, headers=None, verify_ssl=True):
"""Gets the url_endpopint.
Args:
Expand All @@ -71,7 +78,7 @@ def get(self, url_endpoint: str, headers=None, verify_ssl = True):
return self.__client.get(url_endpoint, headers=headers, verify=verify_ssl)

@renew_access_token
def post(self, url_endpoint: str, payload: dict, headers=None, verify_ssl = True):
def post(self, url_endpoint: str, payload: dict, headers=None, verify_ssl=True):
"""Posts payload to the url_endpoint.
Args:
Expand All @@ -83,10 +90,12 @@ def post(self, url_endpoint: str, payload: dict, headers=None, verify_ssl = True
"""
if headers is None:
headers = {}
return self.__client.post(url_endpoint, json=payload, headers=headers, verify=verify_ssl)
return self.__client.post(
url_endpoint, json=payload, headers=headers, verify=verify_ssl
)

@renew_access_token
def patch(self, url_endpoint: str, payload: dict, verify_ssl = True):
def patch(self, url_endpoint: str, payload: dict, verify_ssl=True):
"""Patchs payload to the url_endpoint.
Args:
Expand All @@ -96,7 +105,11 @@ def patch(self, url_endpoint: str, payload: dict, verify_ssl = True):
Returns:
A response object.
"""
return self.__client.patch(url_endpoint, json=payload, verify=verify_ssl)
headers = {"Content-Type": "application/json"}
json_payload = json.dumps(payload, allow_nan=True)
return self.__client.patch(
url_endpoint, data=json_payload, verify=verify_ssl, headers=headers
)

def get_access_token(self):
"""Returns the access token.
Expand Down

0 comments on commit ef1a656

Please sign in to comment.