Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PushMe Support Added #928

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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