From 0122a08b524ba5740200ddafa81252e268480a44 Mon Sep 17 00:00:00 2001 From: Thomas Munzer Date: Mon, 25 Sep 2023 09:18:02 +0200 Subject: [PATCH] adding count of API requests --- src/mistapi/__api_request.py | 8 ++++++++ src/mistapi/__api_session.py | 1 + 2 files changed, 9 insertions(+) diff --git a/src/mistapi/__api_request.py b/src/mistapi/__api_request.py index 389fda3..25de57d 100644 --- a/src/mistapi/__api_request.py +++ b/src/mistapi/__api_request.py @@ -28,7 +28,10 @@ def __init__(self): self._cloud_uri = "" self._session = requests.session() self.privileges = "" + self._count = 0 + def get_request_count(self): + return self._count def _url(self, uri) -> str: """ @@ -113,6 +116,7 @@ def mist_get(self, uri:str, query:dict=None) -> APIResponse: logger.error(f'apirequest:mist_get: Other error occurred: {err}') # Python 3.6 logger.error("apirequest:mist_get: Exception occurred", exc_info=True) finally: + self._count += 1 return APIResponse(url=url, response=resp) def mist_post(self, uri:str, body:dict=None) -> APIResponse: @@ -149,6 +153,7 @@ def mist_post(self, uri:str, body:dict=None) -> APIResponse: logger.error(f'apirequest:mist_post: Other error occurred: {err}') # Python 3.6 logger.error("apirequest:mist_post: Exception occurred", exc_info=True) finally: + self._count += 1 return APIResponse(url=url, response=resp) def mist_put(self, uri:str, body:dict=None) -> APIResponse: @@ -185,6 +190,7 @@ def mist_put(self, uri:str, body:dict=None) -> APIResponse: logger.error(f'apirequest:mist_put: Other error occurred: {err}') # Python 3.6 logger.error("apirequest:mist_put: Exception occurred", exc_info=True) finally: + self._count += 1 return APIResponse(url=url, response=resp) def mist_delete(self, uri:str, query:dict=None) -> APIResponse: @@ -213,6 +219,7 @@ def mist_delete(self, uri:str, query:dict=None) -> APIResponse: logger.error(f'apirequest:mist_delete: Other error occurred: {err}') # Python 3.6 logger.error("apirequest:mist_delete: Exception occurred", exc_info=True) else: + self._count += 1 return APIResponse(url=url, response=resp) @@ -263,4 +270,5 @@ def mist_post_file(self, uri:str, multipart_form_data:dict={}) -> APIResponse: logger.error(f'apirequest:mist_post_file: Other error occurred: {err}') # Python 3.6 logger.error("apirequest:mist_post_file: Exception occurred", exc_info=True) else: + self._count += 1 return APIResponse(url=url, response=resp) diff --git a/src/mistapi/__api_session.py b/src/mistapi/__api_session.py index 1d76c57..9881ddd 100644 --- a/src/mistapi/__api_session.py +++ b/src/mistapi/__api_session.py @@ -93,6 +93,7 @@ def __init__( self._apitoken = None self._csrftoken = None self._authenticated = False + self._count=0 self._session = requests.session() self._console_log_level = console_log_level self._logging_log_level = logging_log_level