make gotify api return values uniform
This commit is contained in:
@@ -110,8 +110,9 @@ class GotifyClient(GotifySession):
|
|||||||
else GotifyErrorModel(response)
|
else GotifyErrorModel(response)
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_application(self, application_id: int) -> bool:
|
def delete_application(self, application_id: int) -> None | GotifyErrorModel:
|
||||||
return self._delete(f"/application/{application_id}").ok
|
response = self._delete(f"/application/{application_id}")
|
||||||
|
return None if response.ok else GotifyErrorModel(response)
|
||||||
|
|
||||||
def upload_application_image(
|
def upload_application_image(
|
||||||
self, application_id: int, img_path: str
|
self, application_id: int, img_path: str
|
||||||
@@ -132,6 +133,10 @@ class GotifyClient(GotifySession):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def delete_application_image(self, application_id: int) -> None | GotifyErrorModel:
|
||||||
|
response = self._delete(f"/application/{application_id}/image")
|
||||||
|
return None if response.ok else GotifyErrorModel(response)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Message
|
Message
|
||||||
"""
|
"""
|
||||||
@@ -151,8 +156,9 @@ class GotifyClient(GotifySession):
|
|||||||
paging=GotifyPagingModel(j["paging"]),
|
paging=GotifyPagingModel(j["paging"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_application_messages(self, application_id: int) -> bool:
|
def delete_application_messages(self, application_id: int) -> None | GotifyErrorModel:
|
||||||
return self._delete(f"/application/{application_id}/message").ok
|
response = self._delete(f"/application/{application_id}/message")
|
||||||
|
return None if response.ok else GotifyErrorModel(response)
|
||||||
|
|
||||||
def get_messages(
|
def get_messages(
|
||||||
self, limit: int = 100, since: int | None = None
|
self, limit: int = 100, since: int | None = None
|
||||||
@@ -166,11 +172,13 @@ class GotifyClient(GotifySession):
|
|||||||
paging=GotifyPagingModel(j["paging"]),
|
paging=GotifyPagingModel(j["paging"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_messages(self) -> bool:
|
def delete_messages(self) -> None | GotifyErrorModel:
|
||||||
return self._delete("/message").ok
|
response = self._delete("/message")
|
||||||
|
return None if response.ok else GotifyErrorModel(response)
|
||||||
|
|
||||||
def delete_message(self, message_id: int) -> bool:
|
def delete_message(self, message_id: int) -> None | GotifyErrorModel:
|
||||||
return self._delete(f"/message/{message_id}").ok
|
response = self._delete(f"/message/{message_id}")
|
||||||
|
return None if response.ok else GotifyErrorModel(response)
|
||||||
|
|
||||||
def listen(
|
def listen(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from PyQt6 import QtCore
|
|||||||
from PyQt6.QtCore import pyqtSignal
|
from PyQt6.QtCore import pyqtSignal
|
||||||
|
|
||||||
from gotify_tray.database import Cache, Settings
|
from gotify_tray.database import Cache, Settings
|
||||||
from gotify_tray.gotify.api import GotifyClient
|
|
||||||
from gotify_tray.gotify.models import GotifyVersionModel
|
from gotify_tray.gotify.models import GotifyVersionModel
|
||||||
from gotify_tray.utils import process_messages
|
from gotify_tray.utils import process_messages
|
||||||
|
|
||||||
@@ -50,7 +49,8 @@ class BaseTask(QtCore.QThread):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteMessageTask(BaseTask):
|
class DeleteMessageTask(BaseTask):
|
||||||
deleted = pyqtSignal(bool)
|
success = pyqtSignal()
|
||||||
|
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||||
|
|
||||||
def __init__(self, message_id: int, gotify_client: gotify.GotifyClient):
|
def __init__(self, message_id: int, gotify_client: gotify.GotifyClient):
|
||||||
super(DeleteMessageTask, self).__init__()
|
super(DeleteMessageTask, self).__init__()
|
||||||
@@ -58,12 +58,16 @@ class DeleteMessageTask(BaseTask):
|
|||||||
self.gotify_client = gotify_client
|
self.gotify_client = gotify_client
|
||||||
|
|
||||||
def task(self):
|
def task(self):
|
||||||
success = self.gotify_client.delete_message(self.message_id)
|
result = self.gotify_client.delete_message(self.message_id)
|
||||||
self.deleted.emit(success)
|
if isinstance(result, gotify.GotifyErrorModel):
|
||||||
|
self.error.emit(result)
|
||||||
|
else:
|
||||||
|
self.success.emit()
|
||||||
|
|
||||||
|
|
||||||
class DeleteApplicationMessagesTask(BaseTask):
|
class DeleteApplicationMessagesTask(BaseTask):
|
||||||
deleted = pyqtSignal(bool)
|
success = pyqtSignal()
|
||||||
|
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||||
|
|
||||||
def __init__(self, appid: int, gotify_client: gotify.GotifyClient):
|
def __init__(self, appid: int, gotify_client: gotify.GotifyClient):
|
||||||
super(DeleteApplicationMessagesTask, self).__init__()
|
super(DeleteApplicationMessagesTask, self).__init__()
|
||||||
@@ -71,20 +75,27 @@ class DeleteApplicationMessagesTask(BaseTask):
|
|||||||
self.gotify_client = gotify_client
|
self.gotify_client = gotify_client
|
||||||
|
|
||||||
def task(self):
|
def task(self):
|
||||||
success = self.gotify_client.delete_application_messages(self.appid)
|
result = self.gotify_client.delete_application_messages(self.appid)
|
||||||
self.deleted.emit(success)
|
if isinstance(result, gotify.GotifyErrorModel):
|
||||||
|
self.error.emit(result)
|
||||||
|
else:
|
||||||
|
self.success.emit()
|
||||||
|
|
||||||
|
|
||||||
class DeleteAllMessagesTask(BaseTask):
|
class DeleteAllMessagesTask(BaseTask):
|
||||||
deleted = pyqtSignal(bool)
|
success = pyqtSignal()
|
||||||
|
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||||
|
|
||||||
def __init__(self, gotify_client: gotify.GotifyClient):
|
def __init__(self, gotify_client: gotify.GotifyClient):
|
||||||
super(DeleteAllMessagesTask, self).__init__()
|
super(DeleteAllMessagesTask, self).__init__()
|
||||||
self.gotify_client = gotify_client
|
self.gotify_client = gotify_client
|
||||||
|
|
||||||
def task(self):
|
def task(self):
|
||||||
success = self.gotify_client.delete_messages()
|
result = self.gotify_client.delete_messages()
|
||||||
self.deleted.emit(success)
|
if isinstance(result, gotify.GotifyErrorModel):
|
||||||
|
self.error.emit(result)
|
||||||
|
else:
|
||||||
|
self.success.emit()
|
||||||
|
|
||||||
|
|
||||||
class GetApplicationsTask(BaseTask):
|
class GetApplicationsTask(BaseTask):
|
||||||
@@ -197,7 +208,7 @@ class VerifyServerInfoTask(BaseTask):
|
|||||||
class ServerConnectionWatchdogTask(BaseTask):
|
class ServerConnectionWatchdogTask(BaseTask):
|
||||||
closed = pyqtSignal()
|
closed = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, gotify_client: GotifyClient):
|
def __init__(self, gotify_client: gotify.GotifyClient):
|
||||||
super(ServerConnectionWatchdogTask, self).__init__()
|
super(ServerConnectionWatchdogTask, self).__init__()
|
||||||
self.gotify_client = gotify_client
|
self.gotify_client = gotify_client
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user