simplify GotifyClient.listen
This commit is contained in:
@@ -19,9 +19,14 @@ logger = logging.getLogger("gotify-tray")
|
||||
|
||||
class GotifySession(object):
|
||||
def __init__(self, url: str, token: str):
|
||||
self.url = url.rstrip("/")
|
||||
|
||||
self.session = requests.Session()
|
||||
self.update_auth(url.rstrip("/"), token)
|
||||
|
||||
def update_auth(self, url: str = None, token: str = None):
|
||||
if url:
|
||||
self.url = url
|
||||
if token:
|
||||
self.token = token
|
||||
self.session.headers.update({"X-Gotify-Key": token})
|
||||
|
||||
def _get(self, endpoint: str = "/", **kwargs) -> requests.Response:
|
||||
@@ -67,10 +72,6 @@ class GotifyApplication(GotifySession):
|
||||
|
||||
|
||||
class GotifyClient(GotifySession):
|
||||
def __init__(self, url: str, client_token: str):
|
||||
super(GotifyClient, self).__init__(url, client_token)
|
||||
self.url = url
|
||||
self.client_token = client_token
|
||||
|
||||
"""
|
||||
Application
|
||||
@@ -173,8 +174,6 @@ class GotifyClient(GotifySession):
|
||||
|
||||
def listen(
|
||||
self,
|
||||
url: str,
|
||||
client_token: str,
|
||||
opened_callback: Callable[[], None] = None,
|
||||
closed_callback: Callable[[int, str], None] = None,
|
||||
new_message_callback: Callable[[GotifyMessageModel], None] = None,
|
||||
@@ -183,7 +182,7 @@ class GotifyClient(GotifySession):
|
||||
def dummy(*args):
|
||||
...
|
||||
|
||||
self.listener = Listener(url, client_token)
|
||||
self.listener = Listener(self.url, self.token)
|
||||
self.listener.opened.connect(lambda: self.opened_callback(opened_callback))
|
||||
self.listener.closed.connect(closed_callback or dummy)
|
||||
self.listener.new_message.connect(new_message_callback or dummy)
|
||||
@@ -198,7 +197,7 @@ class GotifyClient(GotifySession):
|
||||
def reconnect(self):
|
||||
if not self.is_listening():
|
||||
self.listener.start()
|
||||
|
||||
|
||||
def stop_final(self):
|
||||
self.listener.stop_final()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user