initial commit
This commit is contained in:
commit
4acb30b95b
|
|
@ -0,0 +1,23 @@
|
||||||
|
venv/
|
||||||
|
test-venv/
|
||||||
|
|
||||||
|
*.pyc
|
||||||
|
__pycache__/
|
||||||
|
|
||||||
|
instance/
|
||||||
|
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
.envs
|
||||||
|
session_files/
|
||||||
|
mongo_data/
|
||||||
|
test_data/
|
||||||
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
"""
|
||||||
|
lib_af_api
|
||||||
|
---------------------------------------------
|
||||||
|
A Python library for managing AF API objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
from lib_af_api.campaign import Campaign
|
||||||
|
from lib_af_api.event import Event
|
||||||
|
from lib_af_api.voterset import VoterSet
|
||||||
|
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
"""
|
||||||
|
Campaign Class object
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Campaign():
|
||||||
|
"""Campaign class"""
|
||||||
|
|
||||||
|
def __init__(self, base_url, jwt):
|
||||||
|
"""
|
||||||
|
__init__ Init Campaign
|
||||||
|
|
||||||
|
:param base_url: Base URL for Campaign API
|
||||||
|
:param jwt: JWT Authentication for Campaign API
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.base_url = base_url
|
||||||
|
self.jwt = jwt
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, campaign_key):
|
||||||
|
"""
|
||||||
|
get Get the campaign
|
||||||
|
|
||||||
|
:param campaign_key: The Campaign key to get with API
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Set the headers for the request
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': f'Bearer {self.jwt}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the GET
|
||||||
|
response = requests.get(
|
||||||
|
f'{self.base_url}/api/v1/campaigns/{campaign_key}',
|
||||||
|
headers=headers,
|
||||||
|
timeout=300
|
||||||
|
)
|
||||||
|
|
||||||
|
# Good response. Return Campaign
|
||||||
|
if response.ok:
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFCAMPAIGN GET] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def patch(self, campaign_key, patch_data):
|
||||||
|
"""
|
||||||
|
patch Path the Campaign
|
||||||
|
|
||||||
|
:param campaign_key: The Campaign key to update with API
|
||||||
|
:param patch_data: The data to update the Campaign
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 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'] = campaign_key
|
||||||
|
|
||||||
|
# Run the GET
|
||||||
|
response = requests.patch(
|
||||||
|
f'{self.base_url}/api/v1/campaigns/{campaign_key}',
|
||||||
|
headers=headers,
|
||||||
|
timeout=300,
|
||||||
|
json=patch_data
|
||||||
|
)
|
||||||
|
|
||||||
|
# Good response. Return Campaign
|
||||||
|
if response.ok:
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFCAMPAIGN UPDATE] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
"""
|
||||||
|
Event Class object
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Event():
|
||||||
|
"""Event class"""
|
||||||
|
|
||||||
|
def __init__(self, base_url, jwt):
|
||||||
|
"""
|
||||||
|
__init__ Init Event
|
||||||
|
|
||||||
|
:param base_url: Base URL for Event API
|
||||||
|
:param jwt: JWT Authentication for Event API
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.base_url = base_url
|
||||||
|
self.jwt = jwt
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, event_key):
|
||||||
|
"""
|
||||||
|
get Get the event
|
||||||
|
|
||||||
|
:param event_key: The Event key to get with API
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Set the headers for the request
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': f'Bearer {self.jwt}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the GET
|
||||||
|
response = requests.get(
|
||||||
|
f'{self.base_url}/api/v1/events/{event_key}',
|
||||||
|
headers=headers,
|
||||||
|
timeout=300
|
||||||
|
)
|
||||||
|
|
||||||
|
# Good response. Return Event
|
||||||
|
if response.ok:
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFEVENT GET] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def patch(self, event_key, patch_data):
|
||||||
|
"""
|
||||||
|
patch Path the Event
|
||||||
|
|
||||||
|
:param event_key: The Event key to update with API
|
||||||
|
:param patch_data: The data to update the Event
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFEVENT UPDATE] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
"""
|
||||||
|
VoterSet Class object
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class VoterSet():
|
||||||
|
"""VoterSet class"""
|
||||||
|
|
||||||
|
def __init__(self, base_url, jwt):
|
||||||
|
"""
|
||||||
|
__init__ Init VoterSet
|
||||||
|
|
||||||
|
:param base_url: Base URL for Voter API
|
||||||
|
:param jwt: JWT Authentication for Voter API
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.base_url = base_url
|
||||||
|
self.jwt = jwt
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, voterset_key):
|
||||||
|
"""
|
||||||
|
get Get the voterset
|
||||||
|
|
||||||
|
:param voterset_key: The Voterset key to get with API
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Set the headers for the request
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': f'Bearer {self.jwt}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the GET
|
||||||
|
response = requests.get(
|
||||||
|
f'{self.base_url}/api/v1/votersets/{voterset_key}',
|
||||||
|
headers=headers,
|
||||||
|
timeout=300
|
||||||
|
)
|
||||||
|
|
||||||
|
# Good response. Return VoterSet
|
||||||
|
if response.ok:
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFVOTER GET] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def patch(self, voterset_key, patch_data):
|
||||||
|
"""
|
||||||
|
patch Path the Voterset
|
||||||
|
|
||||||
|
:param voterset_key: The Voterset key to update with API
|
||||||
|
:param patch_data: The data to update the Voterset
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 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'] = voterset_key
|
||||||
|
|
||||||
|
# Run the GET
|
||||||
|
response = requests.patch(
|
||||||
|
f'{self.base_url}/api/v1/votersets/{voterset_key}',
|
||||||
|
headers=headers,
|
||||||
|
timeout=300,
|
||||||
|
json=patch_data
|
||||||
|
)
|
||||||
|
|
||||||
|
# Good response. Return VoterSet
|
||||||
|
if response.ok:
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
# Log error and retunr null
|
||||||
|
logging.error("[AFVOTER UPDATE] [%s]", response.text)
|
||||||
|
return None
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
"""
|
||||||
|
Project build definition file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
with open('README.md', 'r') as f:
|
||||||
|
long_description = f.read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='lib_af_api',
|
||||||
|
version='0.1.0',
|
||||||
|
author='',
|
||||||
|
author_email='',
|
||||||
|
description='',
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
|
zip_safe=False,
|
||||||
|
include_package_data=False,
|
||||||
|
packages=find_packages(),
|
||||||
|
python_requires='>=3.7',
|
||||||
|
install_requires=[
|
||||||
|
'requests==2.29.0',
|
||||||
|
],
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue