"""Interface for the ows-marketing microservice.""" from oto import response from owsrequest import request from project_manager.constant import error_const from project_manager.constant.services import OWS_ARTIST from project_manager.util.response_handler_util import safe_decode_json def get_artist_info(artist_id): """Request artist information for ows-artist microservice. Args: artist_id (int): id of artist to retrieve Returns: response.Response: result of requesting an artist's information """ artist_response = request.get(OWS_ARTIST, '/artist/{artist_id}'.format( artist_id=artist_id)) response_json = safe_decode_json(artist_response, OWS_ARTIST) if artist_response.status_code != 200: return response.create_error_response( message=response_json.get('message'), status=artist_response.status_code, code=response_json.get('code')) return response.Response(status=200, message=response_json) def create_artist_info(artist): """Create artist with ows-artist microservice. Args: artist (dict): artist object Returns: response.Response: result of created artist """ artist_name = artist.get('name') vendor_id = artist.get('vendor_id') subaccount_id = artist.get('subaccount_id') if not artist_name or not vendor_id: return response.create_error_response( message='Missing artist params', status=400, code=error_const.ERROR_CODE_BAD_REQUEST) params = { 'name': artist_name, 'vendor_id': vendor_id, 'subaccount_id': subaccount_id } artist_response = request.post( OWS_ARTIST, '/artist', json=params ) response_json = safe_decode_json(artist_response, OWS_ARTIST) if artist_response.status_code not in (200, 201): return response.create_error_response( message=response_json.get('message'), status=artist_response.status_code, code=response_json.get('code')) return response.Response(status=200, message=response_json)