""" Deezer store connector. Provides query_store() function that performs the actual I/O. """ import json import sys import requests from availability import exceptions def query_store(upc): """Query Deezer HTTP API for release status. Args: upc (str): The Universal Product Code. Returns: dict: Deezer search API response JSON decoded as dict. Raises: StoreRequestError: Error sending request to remote store. """ product_url = 'https://api.deezer.com/album/upc:{0}'.format(upc) try: response = requests.get(product_url) content = json.loads(response.content.decode()) except (TypeError, ValueError): raise exceptions.StoreResponseParseError( 'Failed to load {}'.format(response.content.decode())) except Exception: exc_info = sys.exc_info() raise exceptions.StoreRequestError( exc_info[1]).with_traceback(exc_info[2]) else: return content