Skip to content

Commit

Permalink
adding count of API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Sep 25, 2023
1 parent 673553d commit 0122a08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mistapi/__api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/mistapi/__api_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0122a08

Please sign in to comment.