From 31caff1ac9796dddbe9c00f9aee1b05a899d3265 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 20 Aug 2023 10:59:21 -0400 Subject: [PATCH] PushMe Support Added (#928) --- apprise/plugins/NotifyPushMe.py | 27 +++++++++++++++++++++++---- test/test_plugin_pushme.py | 18 ++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/apprise/plugins/NotifyPushMe.py b/apprise/plugins/NotifyPushMe.py index d5e5ed46f1..43eed1cc23 100644 --- a/apprise/plugins/NotifyPushMe.py +++ b/apprise/plugins/NotifyPushMe.py @@ -36,6 +36,7 @@ from ..common import NotifyType from ..common import NotifyFormat from ..utils import validate_regex +from ..utils import parse_bool from ..AppriseLocale import gettext_lazy as _ @@ -82,9 +83,14 @@ class NotifyPushMe(NotifyBase): 'push_key': { 'alias_of': 'token', }, + 'status': { + 'name': _('Show Status'), + 'type': 'bool', + 'default': True, + }, }) - def __init__(self, token, **kwargs): + def __init__(self, token, status=None, **kwargs): """ Initialize PushMe Object """ @@ -98,6 +104,9 @@ def __init__(self, token, **kwargs): self.logger.warning(msg) raise TypeError(msg) + # Set Status type + self.status = status + return def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs): @@ -112,7 +121,8 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs): # Prepare our payload params = { 'push_key': self.token, - 'title': title, + 'title': title if not self.status + else '{} {}'.format(self.asset.ascii(notify_type), title), 'content': body, 'type': 'markdown' if self.notify_format == NotifyFormat.MARKDOWN else 'text' @@ -170,8 +180,13 @@ def url(self, privacy=False, *args, **kwargs): Returns the URL built dynamically based on specified arguments. """ - # Our URL parameters - params = self.url_parameters(privacy=privacy, *args, **kwargs) + # Define any URL parameters + params = { + 'status': 'yes' if self.status else 'no', + } + + # Extend our parameters + params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) # Official URLs are easy to assemble return '{schema}://{token}/?{params}'.format( @@ -203,4 +218,8 @@ def parse_url(url): # Support 'push_key' if specified results['token'] = NotifyPushMe.unquote(results['qsd']['push_key']) + # Get status switch + results['status'] = \ + parse_bool(results['qsd'].get('status', True)) + return results diff --git a/test/test_plugin_pushme.py b/test/test_plugin_pushme.py index ab7117aff3..bf0a4e93a2 100644 --- a/test/test_plugin_pushme.py +++ b/test/test_plugin_pushme.py @@ -55,14 +55,28 @@ 'privacy_url': 'pushme://a...a/', }), # Token specified - ('pushme://?token=%s' % ('b' * 6), { + ('pushme://?token=%s&status=yes' % ('b' * 6), { + 'instance': NotifyPushMe, + + # Our expected url(privacy=True) startswith() response: + 'privacy_url': 'pushme://b...b/', + }), + # Status setting + ('pushme://?token=%s&status=no' % ('b' * 6), { + 'instance': NotifyPushMe, + + # Our expected url(privacy=True) startswith() response: + 'privacy_url': 'pushme://b...b/', + }), + # Status setting + ('pushme://?token=%s&status=True' % ('b' * 6), { 'instance': NotifyPushMe, # Our expected url(privacy=True) startswith() response: 'privacy_url': 'pushme://b...b/', }), # Token specified - ('pushme://?push_key=%s' % ('p' * 6), { + ('pushme://?push_key=%s&status=no' % ('p' * 6), { 'instance': NotifyPushMe, # Our expected url(privacy=True) startswith() response: