""" 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