From 7dcce53b2f903b76fd76d73a55880e139c57ad05 Mon Sep 17 00:00:00 2001 From: Nolan Burfield Date: Sat, 6 Apr 2024 17:55:04 -0700 Subject: [PATCH] add additional event patch and update libs --- lib_af_api/event.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 6 +++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib_af_api/event.py b/lib_af_api/event.py index 75b5ced..47d3e40 100644 --- a/lib_af_api/event.py +++ b/lib_af_api/event.py @@ -121,3 +121,47 @@ class Event(): return response.json() except: # pylint: disable=bare-except return None + + + def patch_v2(self, event_key, patch_data, retry=-1): + """ + patch_v2 Path the Event V2. This will retry a 409 as many times as set by 'retry' parameter + + :param event_key: The Event key to update with API + :param patch_data: The data to update the Event + :param retry: If set to a positive number an attempt to replay the path will happen + """ + + # Set the headers for the request + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': f'Bearer {self.jwt}' + } + + # Set the key to the patch data + patch_data['key'] = event_key + + # Run the GET + response = requests.patch( + f'{self.base_url}/api/v1/events/{event_key}', + headers=headers, + timeout=300, + json=patch_data + ) + + # Good response. Return Event + if response.ok: + return response.json(), response.status_code + + # Log error and retunr null + logging.error("[AFEVENT UPDATE] [%s]", response.text) + + # Check if this call should be tried again + if str(response.status_code) == "409" and retry > 0: + return self.patch_v2(event_key, patch_data, retry=retry-1) + + try: + return response.json(), response.status_code + except: # pylint: disable=bare-except + return None, response.status_code diff --git a/setup.py b/setup.py index 77120e1..9de8903 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ with open('README.md', 'r') as f: setup( name='lib_af_api', - version='0.1.9', + version='1.0.0', author='', author_email='', description='', @@ -20,7 +20,7 @@ setup( packages=find_packages(), python_requires='>=3.7', install_requires=[ - 'requests==2.29.0', - 'pytz==2023.3.post1', + 'pytz==2024.1', + 'requests==2.31.0' ], )