"""An interface to ows-territories microservice.""" from oto import response from owsrequest import request from yt_conflict_elasticsearch.flows.elasticsearch_export import config ISO_3166_1_2016 = 'ISO_3166_1_2016' OWS_TERRITORIES_ERROR = 'OWS_TERRITORIES_ERROR' def get_territories(standard=ISO_3166_1_2016): """Get a list of territories for the provided standard. Args: standard (str): territory standard - ISO_3166_1_2016 or Orch_1_2016. Returns: oto.Response: a response containing a list of territories or an error """ territories_response = request.process( application=config.SWF_FLOW_NAME, environment=config.ENVIRONMENT, method='GET', service_name='ows-territories', path='/territory/{}'.format(standard)) if territories_response.status_code == 200: return response.Response(territories_response.json()) try: response_errors = territories_response.json() except (TypeError, ValueError): response_errors = territories_response.content.decode('utf-8') return response.create_error_response( code=OWS_TERRITORIES_ERROR, message=response_errors, status=territories_response.status_code)