Skip to content

Commit

Permalink
PushMe Support Added (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Aug 20, 2023
1 parent 5fd568f commit 31caff1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
27 changes: 23 additions & 4 deletions apprise/plugins/NotifyPushMe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down Expand Up @@ -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
"""
Expand All @@ -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):
Expand All @@ -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'
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
18 changes: 16 additions & 2 deletions test/test_plugin_pushme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 31caff1

Please sign in to comment.