"""API Client for ows-royalties.""" from time import sleep import requests class RoyaltiesAPIClient: """API Client for ows-royalties.""" def __init__(self, base_url, headers): """Initialize ows_royalties_APIClient class.""" self.base_url = base_url self.headers = headers def post_runcontroller_contract(self, body): """Execute a POST against /run-controller/contract endpoint.""" endpoint = '{}/run-controller/contract'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def post_runcontrollers_contracts_dataloader(self, body): """Execute a POST against /run-controllers/contracts/dataloader endpoint.""" endpoint = '{}/run-controllers/contracts/dataloader'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def post_runcontroller(self, body): """Execute a POST against /run-controller endpoint.""" endpoint = '{}/run-controller'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def get_runcontrollers(self, params=None): """Execute a GET against /run-controllers endpoint.""" if params is None: params = {'limit': '10000'} endpoint = '{}/run-controllers'.format(self.base_url) return requests.get(endpoint, headers=self.headers, params=params) def get_runcontroller(self, runcontroller_id): """Execute a GET against /run-controller endpoint.""" endpoint = '{}/run-controller/{}'.format(self.base_url, runcontroller_id) return requests.get(endpoint, headers=self.headers) def get_runcontroller_by_contract(self, contract_id): """Execute a GET against /run-controller-by-contract/ endpoint.""" endpoint = '{}/run-controller-by-contract/{}'.format(self.base_url, contract_id) return requests.get(endpoint, headers=self.headers) def delete_runcontroller(self, runcontroller_id): """Execute a DELETE against /run-controller endpoint.""" endpoint = '{}/run-controller/{}'.format(self.base_url, runcontroller_id) return requests.delete(endpoint, headers=self.headers) def post_sales_file(self, body): """Execute a POST against /sales-file endpoint.""" sleep(1) # to prevent multiple preprocess executions in the same second endpoint = '{}/sales-file'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def put_sales_file(self, file_id, body): """Execute a PUT against /sales-file endpoint.""" endpoint = '{}/sales-file/{}'.format(self.base_url, file_id) return requests.put(endpoint, headers=self.headers, json=body) def get_accounting_period(self, period_id): """Execute a GET against /accounting-period endpoint.""" endpoint = '{}/accounting-period/{}'.format(self.base_url, period_id) return requests.get(endpoint, headers=self.headers) def get_accounting_periods(self): """Execute a GET against /accounting-periods endpoint.""" endpoint = '{}/accounting-periods'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def get_contracts_by_payee_id(self, payee_id): """Execute a GET against /contracts/ endpoint.""" endpoint = '{}/contracts/{}'.format(self.base_url, payee_id) return requests.get(endpoint, headers=self.headers) def post_accounting_period(self, body): """Execute a POST against /accounting-period endpoint.""" endpoint = '{}/accounting-period'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def post_exchange_rate_upload(self, body): """Execute a POST against /exchange-rate/bulk-exchange-rates.""" endpoint = '{}/exchange-rate/bulk-exchange-rates'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def get_exchange_rates(self, period_id, params=None): """Execute a GET against /accounting-period//bulk-exchange-rates.""" endpoint = '{}/statement-period/{}/bulk-exchange-rates'.format( self.base_url, period_id ) return requests.get(endpoint, headers=self.headers, params=params) def get_accounting_runs(self, period_id): """Execute a GET against /accounting-period/{}/accounting-runs endpoint.""" endpoint = '{}/accounting-period/{}/accounting-runs'.format( self.base_url, period_id ) return requests.get(endpoint, headers=self.headers) def get_accounting_period_sales_files(self, accounting_period_id): """Execute a GET against /accounting-period/{}/sales-files endpoint.""" endpoint = '{}/accounting-period/{}/sales-files'.format( self.base_url, accounting_period_id ) return requests.get(endpoint, headers=self.headers) def get_contract_ids_by_acc_run_id(self, acc_run_id): """GET against /accounting_run_id/run-controller/contracts endpoint.""" endpoint = '{}/accounting-run/{}/run-controller/contracts'.format( self.base_url, acc_run_id ) return requests.get(endpoint, headers=self.headers) def get_run_controller_contracts_by_account_id(self, account_id): """GET against /run-controllers/contracts/account/ endpoint.""" endpoint = '{}/run-controllers/contracts/account/{}'.format( self.base_url, account_id ) return requests.get(endpoint, headers=self.headers) def get_period_reports_by_period_id(self, period_id): """GET /accounting-period//accounting-period-reports endpoint.""" endpoint = '{}/accounting-period/{}/accounting-period-reports'.format( self.base_url, period_id ) return requests.get(endpoint, headers=self.headers) def get_period_reports_by_period_id_and_report_type(self, period_id, report_type): """GET /accounting-period/<>/report-type/{}/accounting-period-report.""" endpoint = ( '{}/accounting-period/{}/report-type/{}/accounting-period-report'.format( self.base_url, period_id, report_type ) ) return requests.get(endpoint, headers=self.headers) def get_recent_statement_periods(self): """GET /statement-periods/recent/ .""" endpoint = '{}/statement-periods/recent'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def get_upcoming_statement_periods(self): """GET /statement-periods/upcoming/ .""" endpoint = '{}/statement-periods/upcoming/'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def close_statement_period(self, period_id): """PUT /statement-period/{statement_period_id}/close .""" endpoint = '{}/statement-period/{}/close'.format(self.base_url, period_id) return requests.put(endpoint, headers=self.headers) def get_statement_period(self, period_id): """GET /statement-period/{statement_period_id}/ .""" endpoint = '{}/statement-period/{}'.format(self.base_url, period_id) return requests.get(endpoint, headers=self.headers) def post_accounting_period_report(self, period_id, body): """POST /accounting-period//accounting-period-report endpoint.""" endpoint = '{}/accounting-period/{}/accounting-period-report/'.format( self.base_url, period_id ) return requests.post(endpoint, headers=self.headers, json=body) def get_statement_periods(self, params=None): """GET /statement-periods .""" endpoint = '{}/statement-periods'.format(self.base_url) return requests.get(endpoint, headers=self.headers, params=params) def post_statement_periods(self, body): """POST /statement-periods .""" endpoint = '{}/statement-periods'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def post_statement_periods_dataloader(self, body): """POST /dataloader/statement-periods/.""" endpoint = '{}/dataloader/statement-periods/'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def get_accounting_period_by_accounting_run_id(self, accounting_run_id): """GET /statement-periods .""" endpoint = '{}/accounting-run/{}/accounting-period'.format( self.base_url, accounting_run_id ) return requests.get(endpoint, headers=self.headers) def put_payment_entity_visible(self, statement_period_id, entity_id, body): """PUT /statement-period/{period_id}/payment-entity/{entity_id}/visible/ .""" endpoint = '{}/statement-period/{}/payment-entity/{}/visible/'.format( self.base_url, statement_period_id, entity_id ) return requests.put(endpoint, headers=self.headers, json=body) def get_payment_entities_for_statement_period(self, statement_period_id): """GET /statement-period/{}/payment-entities/ .""" endpoint = '{}/statement-period/{}/payment-entities/'.format( self.base_url, statement_period_id ) return requests.get(endpoint, headers=self.headers) def get_accounting_run(self, accoutnign_run_id): """GET /accounting-run/{accounting_run_id} .""" endpoint = '{}/accounting-run/{}'.format(self.base_url, accoutnign_run_id) return requests.get(endpoint, headers=self.headers) def put_accounting_run(self, accoutnign_run_id, body): """PUT /accounting-run/{accounting_run_id} .""" endpoint = '{}/accounting-run/{}'.format(self.base_url, accoutnign_run_id) return requests.put(endpoint, headers=self.headers, json=body) def post_statement_period_adjustment_file(self, period_id, body): """POST /statement-period//adjustment-file endpoint.""" endpoint = '{}/statement-period/{}/adjustment-file'.format( self.base_url, period_id ) return requests.post(endpoint, headers=self.headers, json=body) def put_statement_period_adjustment_file(self, period_id, file_id, body): """PUT /statement-period//adjustment-file/ endpoint.""" endpoint = '{}/statement-period/{}/adjustment-file/{}'.format( self.base_url, period_id, file_id ) return requests.put(endpoint, headers=self.headers, json=body) def get_statement_period_adjustment_file(self, period_id, file_id): """GET /statement-period//adjustment-file/ endpoint.""" endpoint = '{}/statement-period/{}/adjustment-file/{}'.format( self.base_url, period_id, file_id ) return requests.get(endpoint, headers=self.headers) def get_adjustment_files_by_statement_period_id(self, period_id): """GET /statement-period//adjustment-files endpoint.""" endpoint = '{}/statement-period/{}/adjustment-files'.format( self.base_url, period_id ) return requests.get(endpoint, headers=self.headers) def get_adjustment_file_by_file_id(self, file_id): """GET /statement-period-adjustment-file/ .""" endpoint = '{}/statement-period-adjustment-file/{}'.format( self.base_url, file_id ) return requests.get(endpoint, headers=self.headers) def get_adjustment_file_template(self): """GET /statement-period-adjustment-file/ .""" endpoint = '{}/abacus-adjustments/download/template'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def delete_adjustment_file(self, period_id, file_id): """DELETE /statement-period//adjustment-file/ .""" endpoint = '{}/statement-period/{}/adjustment-file/{}'.format( self.base_url, period_id, file_id ) return requests.delete(endpoint, headers=self.headers) def get_invalid_adjustment_file_download(self, file_id): """GET /statement-period-adjustment-file//download/error .""" endpoint = '{}/statement-period-adjustment-file/{}/download/error'.format( self.base_url, file_id ) return requests.get(endpoint, headers=self.headers) def get_valid_adjustment_file_download(self, file_id): """GET /statement-period-adjustment-file//download/report .""" endpoint = '{}/statement-period-adjustment-file/{}/download/report'.format( self.base_url, file_id ) return requests.get(endpoint, headers=self.headers) def get_statement_periods_adjustment_files(self, params=None): """GET /statement-period-adjustment-files .""" endpoint = '{}/statement-period-adjustment-files'.format(self.base_url) return requests.get(endpoint, headers=self.headers, params=params) def get_current_statement_period(self): """GET /statement-period/current .""" endpoint = '{}/statement-period/current'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def get_statement_period_payment_entities_states(self, statement_period_id): """GET /statement-period//payment-entities/states/ .""" endpoint = '{}/statement-period/{}/payment-entities/states/'.format( self.base_url, statement_period_id ) return requests.get(endpoint, headers=self.headers) def get_adjustment_files_with_params(self, params=None): """GET /statement-period-adjustment-files/? .""" endpoint = '{}/statement-period-adjustment-files/'.format(self.base_url) return requests.get(endpoint, headers=self.headers, params=params) def get_file_upload_configs(self): """GET /file-upload-configs .""" endpoint = '{}/file-upload-configs'.format(self.base_url) return requests.get(endpoint, headers=self.headers) def get_file_upload_config_by_id(self, config_id): """GET /file-upload-config/ .""" endpoint = '{}/file-upload-config/{}'.format(self.base_url, config_id) return requests.get(endpoint, headers=self.headers) def post_file_upload_config(self, body): """POST /file-upload-config .""" endpoint = '{}/file-upload-config'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def put_file_upload_config_by_id(self, config_id, body): """PUT /file-upload-config/ .""" endpoint = '{}/file-upload-config/{}'.format(self.base_url, config_id) return requests.put(endpoint, headers=self.headers, json=body) def delete_file_upload_config_by_id(self, config_id): """DELETE /file-upload-config/ .""" endpoint = '{}/file-upload-config/{}'.format(self.base_url, config_id) return requests.delete(endpoint, headers=self.headers) def post_file_upload_cancel(self, file_key): """POST /file-upload/{file_key}/cancel .""" endpoint = '{}/file-upload/{}/cancel'.format(self.base_url, file_key) return requests.post(endpoint, headers=self.headers) def post_file_upload_complete(self, file_key): """POST /file-upload/{file_key}/complete .""" endpoint = '{}/file-upload/{}/complete'.format(self.base_url, file_key) return requests.post(endpoint, headers=self.headers) def get_file_upload_download(self, file_key): """GET /file-upload/{file_key}/download .""" endpoint = '{}/file-upload/{}/download'.format(self.base_url, file_key) return requests.get(endpoint, headers=self.headers) def post_file_upload_quarantine(self, file_key): """POST /file-upload/{file_key}/quarantine .""" endpoint = '{}/file-upload/{}/quarantine'.format(self.base_url, file_key) return requests.post(endpoint, headers=self.headers) def get_statement_period_adjustment_file_batch_criteria_by_file_id(self, file_id): """GET /statement-period-adjustment-file//batch-criteria .""" endpoint = '{}/statement-period-adjustment-file/{}/batch-criteria'.format( self.base_url, file_id ) return requests.get(endpoint, headers=self.headers) def post_statement_period_adjustment_file_batch_criteria_by_file_id( self, file_id, body ): """POST /statement-period-adjustment-file//batch-criteria .""" endpoint = '{}/statement-period-adjustment-batch-criteria'.format( self.base_url, file_id ) return requests.post(endpoint, headers=self.headers, json=body) def post_adjustment_file_batch_criteria_for_statement_period(self, period_id, body): """POST /statement-period//adjustment-file/batch-criteria .""" endpoint = '{}/statement-period/{}/adjustment-file/batch-criteria'.format( self.base_url, period_id ) return requests.post(endpoint, headers=self.headers, json=body) def get_earnings_transfers(self, params=None): """GET /earnings-transfers .""" endpoint = '{}/earnings-transfers'.format(self.base_url) return requests.get(endpoint, headers=self.headers, params=params) def get_earnings_transfer_by_contract_id(self, contract_id, params=None): """GET /contract//earnings-transfers/transfer .""" endpoint = '{}/contract/{}/earnings-transfers/transfer'.format( self.base_url, contract_id ) return requests.get(endpoint, headers=self.headers, params=params) def get_earnings_transfer_by_id(self, earnings_transfer_id): """GET /earnings-transfer/ .""" endpoint = '{}/earnings-transfer/{}'.format(self.base_url, earnings_transfer_id) return requests.get(endpoint, headers=self.headers) def post_earnings_transfer(self, body): """POST /earnings-transfer/bulk .""" endpoint = '{}/earnings-transfer/bulk'.format(self.base_url) return requests.post(endpoint, headers=self.headers, json=body) def put_earnings_transfer(self, body): """PUT /earnings-transfer/bulk .""" endpoint = '{}/earnings-transfer/bulk'.format(self.base_url) return requests.put(endpoint, headers=self.headers, json=body) def post_transfer_job_terms(self, job_id, body): """POST /transfer-job/{job_id}/terms .""" endpoint = '{}/transfer-job/{}/terms'.format(self.base_url, job_id) return requests.post(endpoint, headers=self.headers, json=body) def get_transfer_job_terms(self, job_id): """GET /transfer-job/{job_id}/terms .""" endpoint = '{}/transfer-job/{}/terms'.format(self.base_url, job_id) return requests.get(endpoint, headers=self.headers)