diff --git a/lib_af_api/__init__.py b/lib_af_api/__init__.py index 6afa7b0..fbf2710 100644 --- a/lib_af_api/__init__.py +++ b/lib_af_api/__init__.py @@ -5,6 +5,7 @@ A Python library for managing AF API objects """ from lib_af_api.campaign import Campaign +from lib_af_api.business import Business from lib_af_api.event import Event from lib_af_api.voterset import VoterSet from lib_af_api.voter import Voter diff --git a/lib_af_api/business.py b/lib_af_api/business.py new file mode 100644 index 0000000..ce519c7 --- /dev/null +++ b/lib_af_api/business.py @@ -0,0 +1,86 @@ +""" +Business Class object +""" + +import logging +import requests + + +class Business(): + """Business class""" + + def __init__(self, base_url, jwt): + """ + __init__ Init Business + + :param base_url: Base URL for Business API + :param jwt: JWT Authentication for Business API + """ + + self.base_url = base_url + self.jwt = jwt + + + def get(self, business_key): + """ + get Get the business + + :param business_key: The Business 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/businesses/{business_key}', + headers=headers, + timeout=300 + ) + + # Good response. Return Business + if response.ok: + return response.json() + + # Log error and retunr null + logging.error("[AFBUSINESS GET] [%s]", response.text) + return None + + + def patch(self, business_key, patch_data): + """ + patch Path the Business + + :param business_key: The Business key to update with API + :param patch_data: The data to update the Business + """ + + # 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'] = business_key + + # Run the GET + response = requests.patch( + f'{self.base_url}/api/v1/businesses/{business_key}', + headers=headers, + timeout=300, + json=patch_data + ) + + # Good response. Return Business + if response.ok: + return response.json() + + # Log error and retunr null + logging.error("[AFBUSINESS UPDATE] [%s]", response.text) + return None diff --git a/setup.py b/setup.py index 5f8ae9b..1a846e8 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.7', + version='0.1.8', author='', author_email='', description='',