From 483e76fc75f1b21149ef8b3fc63c99ece38c630c Mon Sep 17 00:00:00 2001 From: Yoann Chevalier Date: Tue, 31 Oct 2023 17:52:51 +0100 Subject: [PATCH 1/2] Add list API Required pluging: https://github.com/chervaliery/yourls-api-action-list --- yourls/core.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/yourls/core.py b/yourls/core.py index 3996707..1de2326 100644 --- a/yourls/core.py +++ b/yourls/core.py @@ -80,6 +80,23 @@ def shorten(self, url, keyword=None, title=None): return url + def list(self): + """List all URL + + Returns: + ShortenedURL[]: List of Shortened URL and associated data. + + Raises: + requests.exceptions.HTTPError: Generic HTTP Error + """ + data = dict(action='list') + jsondata = self._api_request(params=data) + urls = [] + for url in jsondata['result']: + urls.append(_json_to_shortened_url(url, url['shorturl'])) + + return urls + def expand(self, short): """Expand short URL or keyword to long URL. From 0f498e0d73ad7dd9197560373ab452a8dc20ce35 Mon Sep 17 00:00:00 2001 From: Yoann Chevalier Date: Fri, 9 Feb 2024 11:58:09 +0100 Subject: [PATCH 2/2] Add delete action Required pluging: https://github.com/chervaliery/yourls-api-action-delete --- yourls/core.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/yourls/core.py b/yourls/core.py index 1de2326..cee4a32 100644 --- a/yourls/core.py +++ b/yourls/core.py @@ -97,6 +97,19 @@ def list(self): return urls + def delete(self, keyword): + """Delete URL by keyword + + Returns: + Int: Number of deleted URL + + Raises: + requests.exceptions.HTTPError: Generic HTTP Error + """ + data = dict(action='delete', keyword=keyword) + jsondata = self._api_request(params=data) + return jsondata['result'] + def expand(self, short): """Expand short URL or keyword to long URL.