From b3a2a1fb78278843ee50bdc8dde5f7fb218fbc64 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 4 Mar 2018 15:15:59 +0100 Subject: [PATCH] Add api.playlist_clear and api.playlist_remove --- grzegorz_clients/api.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/grzegorz_clients/api.py b/grzegorz_clients/api.py index 158fc46..8e5683c 100644 --- a/grzegorz_clients/api.py +++ b/grzegorz_clients/api.py @@ -13,6 +13,19 @@ def set_endpoint(base_url:str): class APIError(Exception): pass # decorator: +# (TODO): Add logging +def request_delete(func): + @wraps(func) + def new_func(*args, **kwargs): + url, data = func(*args, **kwargs) + if type(data) is dict: data = json.dumps(data) + response = requests.delete(f"{BASE_URL}/{url}", data=data) + data = json.loads(response.text) + if "error" not in data or data["error"] != False: + print(data) + raise APIError(data["error"]) + return data["success"] + return new_func def request_post(func): @wraps(func) def new_func(*args, **kwargs): @@ -73,6 +86,15 @@ def playlist_next(): def playlist_previous(): return f"playlist/previous", None +@request_delete +def playlist_clear(): + return f"playlist", None + +@request_delete +def playlist_remove(index:int): + args = urlencode(locals()) + return f"playlist?{args}", None + @request_get def get_playback_pos(): return f"time"