"""Interface to the ows-product microservice.""" from typing import List import backoff from cachetools.func import ttl_cache from owsrequest import request from collaborator import config from collaborator.constants import error, service_name from collaborator.utils import owsrequest from collaborator.utils.error import OwsError from collaborator.utils.ttl_cache_list import ttl_cache_list @ttl_cache() @backoff.on_exception( wait_gen=backoff.expo, exception=OwsError, max_tries=config.MAX_NETWORK_REQUEST_RETRIES, logger=config.LOGGER_NAME, ) def get_product(product_id: str) -> dict: """Get information about a product. product_id (str): The product id. Returns: oto.response.Response """ product_url = f"/product/{product_id}" res = request.get(service_name.OWS_PRODUCT, product_url) return owsrequest.unwrap_data_or_error(res, error.ERROR_CODE_OWS_PRODUCT) @ttl_cache_list @backoff.on_exception( wait_gen=backoff.expo, exception=OwsError, max_tries=config.MAX_NETWORK_REQUEST_RETRIES, logger=config.LOGGER_NAME, ) def get_products_by_upc(upcs: List[str]) -> dict: """Get information about products by UPCs. upcs (List[str]): The UPCs. Returns: oto.response.Response """ product_url = "/bulk-upc" res = request.post(service_name.OWS_PRODUCT, product_url, json={"upcs": upcs}) return owsrequest.unwrap_data_or_error(res, error.ERROR_CODE_OWS_PRODUCT)