"""Interface for the ows-track microservice.""" from oto import response from owsrequest import request as requests from pricing.constants import service_name def get_tracks_by_product_id(product_id): """Get all tracks for a product ID. Returns: Response: all the tracks for the product ID """ path = '/product/{product_id}/tracks'.format(product_id=product_id) return make_track_request(path) def get_track_by_track_id(track_id): """Get track for a track ID. Returns: Response: the track object """ path = '/track/{track_id}'.format(track_id=track_id) return make_track_request(path) def get_ig_tracks_by_product_id(product_id): """Get all instant grats for a product ID. Returns: Response: all the instant grat tracks for the product ID """ path = '/product/{product_id}/tracks/grats'.format(product_id=product_id) return make_track_request(path) def make_track_request(path): """Make an actual request to ows-track. Args: path ([string]): the path to request. Returns: Response: the result of the request """ track_response = requests.get(service_name.OWS_TRACK, path) if track_response.status_code == 200: return response.Response(message=(track_response.json())) else: return response.Response(status=404)