add additional event patch and update libs
This commit is contained in:
parent
6ed0b9c290
commit
7dcce53b2f
|
|
@ -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
|
||||
|
|
|
|||
6
setup.py
6
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'
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue