"""API Client for ows-moneyhub.""" import os import requests from tests.integration.utils.generate_auth0_token import generate_auth_token class MoneyhubAPIClient: """API Client for ows-moneyhub.""" token = generate_auth_token() HOST = os.getenv('MONEYHUB_HOST', 'localhost') PORT = os.getenv('MONEYHUB_PORT', 6501) BASE_URL = os.getenv('MONEYHUB_API_BASE_URL', f'http://{HOST}:{PORT}') HEADERS = { 'Content-Type': 'application/json', 'orchard-profile-id': '0', 'orchard-profile-type': 'MoneyhubProfile', 'orchard-profile-uuid': 'abcd', 'orchard-roles': 'administrator', 'authorization': f'Bearer {token}' } @classmethod def get_hello(cls): """Execute a GET against /hello endpoint.""" endpoint = f'{cls.BASE_URL}/hello' return requests.get(endpoint, headers=cls.HEADERS) @classmethod def get_statement_attachments(cls, account_id, statement_period_id): """Execute a GET against /statement-attachments endpoint.""" endpoint = '{}/statement-attachment/account/{}/statement-period/{}' \ .format(cls.BASE_URL, account_id, statement_period_id) return requests.get(endpoint, headers=cls.HEADERS) @classmethod def post_statement_attachment(cls, statement_period_id): """Execute a POST against /statement-attachments endpoint.""" endpoint = f'{cls.BASE_URL}/statement-attachment/statement-period/{statement_period_id}' return requests.post(endpoint, headers=cls.HEADERS) @classmethod def put_statement_attachment(cls, statement_attachment_id, body): """Execute a PUT against /statement-attachments endpoint.""" endpoint = f'{cls.BASE_URL}/statement-attachment/{statement_attachment_id}' return requests.put(endpoint, headers=cls.HEADERS, json=body) @classmethod def get_account_payments_for_statement_period( cls, account_id, statement_period_id, contract_id): """GET /account/{account_id}/statement-period/{period_id}/payments.""" endpoint = '{}/account/{}/statement-period/{}/payments?contract_id={}' \ .format(cls.BASE_URL, account_id, statement_period_id, contract_id) return requests.get(endpoint, headers=cls.HEADERS)