"""Model for ows-pricing.""" 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_orchard_pricing_tiers(pricing_family_id): """Get the list of Orchard Pricing Tiers by family ID from ows-pricing. Args: pricing_family_id (int): id of pricing family for which we get the list of Orchard Pricing Tiers. Returns: Response: List of orchard pricing tiers. """ pricing_response = request.process( application=ows_services.APPLICATION_NAME, environment=config.ENVIRONMENT, method='get', service_name=ows_services.OWS_PRICING, path='/pricing-family/{pricing_family_id}/orchard-pricing-tier'.format( pricing_family_id=pricing_family_id)) if pricing_response.status_code != 200: logger.warning( 'Could not retrieve list of pricing tiers for pricing family {}' ' from ows-pricing.'.format(pricing_family_id)) return response.Response( errors=pricing_response.text, status=pricing_response.status_code) return response.Response( message=pricing_response.json().get('items')) def get_orchard_pricing_tier_for_product(product_id, pricing_family_id): """Get the id of Orchard Pricing Tier for product from ows-pricing. Args: product_id (int): id of the product. pricing_family_id (int): id of pricing family for which we get the list of Orchard Pricing Tiers. Returns: Response: product's orchard pricing tier data. """ pricing_response = request.process( application=ows_services.APPLICATION_NAME, environment=config.ENVIRONMENT, method='get', service_name=ows_services.OWS_PRICING, path='/product/{}/pricing-family/{}/orchard_pricing_tier'.format( product_id, pricing_family_id)) if pricing_response.status_code != 200: logger.warning( 'Could not retrieve pricing tier for a product {}' ' from ows-pricing.'.format(product_id)) return response.Response( errors=pricing_response.text, status=pricing_response.status_code) if not pricing_response.text: return response.Response( message=ows_services.DEFAULT_PHYSICAL_PRICING_TIER) return response.Response( message=pricing_response.json())