"""Data access layer for ows-product-physical. Data access layer for extracting product information from ows-product-physical. """ from oto import response from owsrequest import request from label_copy_export import config from label_copy_export.connectors import loggly from label_copy_export.constants import ows_services logger = loggly.get_current_logger() def get_product_physical_data(product_id, correlation_id=None): """Get physical product data from ows-product-physical microservice. Args: product_id (str): product id correlation_id (str): correlation id Returns: response.Response: containing dict message. """ endpoint = '/product/{}'.format(product_id) resp = request.process( application=config.APP_NAME, environment=config.ENVIRONMENT, method='GET', service_name=ows_services.OWS_PRODUCT_PHYSICAL, path=endpoint, correlation_id=correlation_id, ) if resp.status_code != 200: logger.warning( 'Product data for product_id: {} is not found in {}'.format( product_id, ows_services.OWS_PRODUCT_PHYSICAL)) return response.Response(errors=resp.text, status=resp.status_code) return response.Response(message=resp.json()) def get_product_physical_tracks(product_id, correlation_id=None): """Get physical product tracks from ows-product-physical microservice. Args: product_id (str): product id correlation_id (str): correlation id Returns: response.Response: containing dict message. """ endpoint = '/product/{}/tracks'.format(product_id) resp = request.process( application=config.APP_NAME, environment=config.ENVIRONMENT, method='GET', service_name=ows_services.OWS_PRODUCT_PHYSICAL, path=endpoint, correlation_id=correlation_id, ) if not resp: logger.warning( 'Tracks for product_id: {} are not found in {}'.format( product_id, ows_services.OWS_PRODUCT_PHYSICAL)) return response.Response(errors=resp.text, status=resp.status_code) return response.Response(message=resp.json()) def get_packaging_options(correlation_id=None): """Get a list of available physical packaging options. Args: correlation_id (str): correlation id Returns: response.Response: containing dict message. """ endpoint = '/packaging' resp = request.process( application=config.APP_NAME, environment=config.ENVIRONMENT, method='GET', service_name=ows_services.OWS_PRODUCT_PHYSICAL, path=endpoint, correlation_id=correlation_id, ) if resp.status_code != 200: logger.warning('Packaging options are not found') return response.Response(errors=resp.text, status=resp.status_code) return response.Response(message=resp.json())