def vote(mbid, spotify_uri, user_id): """Submit report about incorrect Spotify mapping.""" if _base_url is None or _key is None: return # TODO(roman): Catch errors during voting. requests.post(_base_url + 'mapping/vote?key=' + _key, headers={'Content-Type': 'application/json'}, data=json.dumps({ 'mbid': str(mbid), 'user': str(user_id), 'spotify_uri': str(spotify_uri), })) cache.delete(mbid, _CACHE_NAMESPACE)
def add_mapping(mbid, spotify_uri, user_id): """Submit new Spotify mapping. Returns: Returns two values. First one is a boolean that indicates whether the submission has been successful. The second is an exception in case errors occur. If there are no errors, this value is None. """ if _base_url is None or _key is None: return False, None try: session = requests.Session() session.mount(_base_url, HTTPAdapter(max_retries=2)) resp = session.post(_base_url + 'mapping/add?key=' + _key, headers={'Content-Type': 'application/json'}, data=json.dumps({'mbid': str(mbid), 'spotify_uri': spotify_uri, 'user': str(user_id)})) cache.delete(mbid, _CACHE_NAMESPACE) return resp.status_code == 200, None except RequestException as e: return False, e
def add_mapping(mbid, spotify_uri, user_id): """Submit new Spotify mapping. Returns: Returns two values. First one is a boolean that indicates whether the submission has been successful. The second is an exception in case errors occur. If there are no errors, this value is None. """ if _base_url is None or _key is None: return False, None try: session = requests.Session() session.mount(_base_url, HTTPAdapter(max_retries=2)) resp = session.post(_base_url + 'mapping/add?key=' + _key, headers={'Content-Type': 'application/json'}, data=json.dumps({ 'mbid': str(mbid), 'spotify_uri': spotify_uri, 'user': str(user_id) })) cache.delete(mbid, _CACHE_NAMESPACE) return resp.status_code == 200, None except RequestException as e: return False, e