mirror of https://github.com/caronc/apprise
Gotify supports extended URL paths beyond just the hostname (#259)
parent
74759031fc
commit
84feb163aa
|
@ -89,6 +89,8 @@ class NotifyGotify(NotifyBase):
|
||||||
templates = (
|
templates = (
|
||||||
'{schema}://{host}/{token}',
|
'{schema}://{host}/{token}',
|
||||||
'{schema}://{host}:{port}/{token}',
|
'{schema}://{host}:{port}/{token}',
|
||||||
|
'{schema}://{host}{path}{token}',
|
||||||
|
'{schema}://{host}:{port}{path}{token}',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Define our template tokens
|
# Define our template tokens
|
||||||
|
@ -104,6 +106,13 @@ class NotifyGotify(NotifyBase):
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'required': True,
|
'required': True,
|
||||||
},
|
},
|
||||||
|
'path': {
|
||||||
|
'name': _('Path'),
|
||||||
|
'type': 'string',
|
||||||
|
'map_to': 'fullpath',
|
||||||
|
'default': '/',
|
||||||
|
'required': True,
|
||||||
|
},
|
||||||
'port': {
|
'port': {
|
||||||
'name': _('Port'),
|
'name': _('Port'),
|
||||||
'type': 'int',
|
'type': 'int',
|
||||||
|
@ -137,6 +146,9 @@ class NotifyGotify(NotifyBase):
|
||||||
self.logger.warning(msg)
|
self.logger.warning(msg)
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
|
# prepare our fullpath
|
||||||
|
self.fullpath = kwargs.get('fullpath', '/')
|
||||||
|
|
||||||
if priority not in GOTIFY_PRIORITIES:
|
if priority not in GOTIFY_PRIORITIES:
|
||||||
self.priority = GotifyPriority.NORMAL
|
self.priority = GotifyPriority.NORMAL
|
||||||
|
|
||||||
|
@ -161,7 +173,7 @@ class NotifyGotify(NotifyBase):
|
||||||
url += ':%d' % self.port
|
url += ':%d' % self.port
|
||||||
|
|
||||||
# Append our remaining path
|
# Append our remaining path
|
||||||
url += '/message'
|
url += '{fullpath}message'.format(fullpath=self.fullpath)
|
||||||
|
|
||||||
# Define our parameteers
|
# Define our parameteers
|
||||||
params = {
|
params = {
|
||||||
|
@ -245,11 +257,12 @@ class NotifyGotify(NotifyBase):
|
||||||
|
|
||||||
default_port = 443 if self.secure else 80
|
default_port = 443 if self.secure else 80
|
||||||
|
|
||||||
return '{schema}://{hostname}{port}/{token}/?{args}'.format(
|
return '{schema}://{hostname}{port}{fullpath}{token}/?{args}'.format(
|
||||||
schema=self.secure_protocol if self.secure else self.protocol,
|
schema=self.secure_protocol if self.secure else self.protocol,
|
||||||
hostname=NotifyGotify.quote(self.host, safe=''),
|
hostname=NotifyGotify.quote(self.host, safe=''),
|
||||||
port='' if self.port is None or self.port == default_port
|
port='' if self.port is None or self.port == default_port
|
||||||
else ':{}'.format(self.port),
|
else ':{}'.format(self.port),
|
||||||
|
fullpath=NotifyGotify.quote(self.fullpath, safe='/'),
|
||||||
token=self.pprint(self.token, privacy, safe=''),
|
token=self.pprint(self.token, privacy, safe=''),
|
||||||
args=NotifyGotify.urlencode(args),
|
args=NotifyGotify.urlencode(args),
|
||||||
)
|
)
|
||||||
|
@ -271,13 +284,17 @@ class NotifyGotify(NotifyBase):
|
||||||
|
|
||||||
# optionally find the provider key
|
# optionally find the provider key
|
||||||
try:
|
try:
|
||||||
# The first entry is our token
|
# The last entry is our token
|
||||||
results['token'] = entries.pop(0)
|
results['token'] = entries.pop()
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# No token was set
|
# No token was set
|
||||||
results['token'] = None
|
results['token'] = None
|
||||||
|
|
||||||
|
# Re-assemble our full path
|
||||||
|
results['fullpath'] = \
|
||||||
|
'/' if not entries else '/{}/'.format('/'.join(entries))
|
||||||
|
|
||||||
if 'priority' in results['qsd'] and len(results['qsd']['priority']):
|
if 'priority' in results['qsd'] and len(results['qsd']['priority']):
|
||||||
_map = {
|
_map = {
|
||||||
'l': GotifyPriority.LOW,
|
'l': GotifyPriority.LOW,
|
||||||
|
|
|
@ -103,6 +103,14 @@ class NotifyNotica(NotifyBase):
|
||||||
'{schema}://{user}@{host}:{port}/{token}',
|
'{schema}://{user}@{host}:{port}/{token}',
|
||||||
'{schema}://{user}:{password}@{host}/{token}',
|
'{schema}://{user}:{password}@{host}/{token}',
|
||||||
'{schema}://{user}:{password}@{host}:{port}/{token}',
|
'{schema}://{user}:{password}@{host}:{port}/{token}',
|
||||||
|
|
||||||
|
# Self-hosted notica servers (with custom path)
|
||||||
|
'{schema}://{host}{path}{token}',
|
||||||
|
'{schema}://{host}:{port}{path}{token}',
|
||||||
|
'{schema}://{user}@{host}{path}{token}',
|
||||||
|
'{schema}://{user}@{host}:{port}{path}{token}',
|
||||||
|
'{schema}://{user}:{password}@{host}{path}{token}',
|
||||||
|
'{schema}://{user}:{password}@{host}:{port}{path}{token}',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Define our template tokens
|
# Define our template tokens
|
||||||
|
@ -133,6 +141,12 @@ class NotifyNotica(NotifyBase):
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'private': True,
|
'private': True,
|
||||||
},
|
},
|
||||||
|
'path': {
|
||||||
|
'name': _('Path'),
|
||||||
|
'type': 'string',
|
||||||
|
'map_to': 'fullpath',
|
||||||
|
'default': '/',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
# Define any kwargs we're using
|
# Define any kwargs we're using
|
||||||
|
|
|
@ -803,6 +803,20 @@ TEST_URLS = (
|
||||||
# Our expected url(privacy=True) startswith() response:
|
# Our expected url(privacy=True) startswith() response:
|
||||||
'privacy_url': 'gotify://hostname/t...t',
|
'privacy_url': 'gotify://hostname/t...t',
|
||||||
}),
|
}),
|
||||||
|
# Provide a hostname, path, and token
|
||||||
|
('gotify://hostname/a/path/ending/in/a/slash/%s' % ('u' * 16), {
|
||||||
|
'instance': plugins.NotifyGotify,
|
||||||
|
|
||||||
|
# Our expected url(privacy=True) startswith() response:
|
||||||
|
'privacy_url': 'gotify://hostname/a/path/ending/in/a/slash/u...u/',
|
||||||
|
}),
|
||||||
|
# Provide a hostname, path, and token
|
||||||
|
('gotify://hostname/a/path/not/ending/in/a/slash/%s' % ('v' * 16), {
|
||||||
|
'instance': plugins.NotifyGotify,
|
||||||
|
|
||||||
|
# Our expected url(privacy=True) startswith() response:
|
||||||
|
'privacy_url': 'gotify://hostname/a/path/not/ending/in/a/slash/v...v/',
|
||||||
|
}),
|
||||||
# Provide a priority
|
# Provide a priority
|
||||||
('gotify://hostname/%s?priority=high' % ('i' * 16), {
|
('gotify://hostname/%s?priority=high' % ('i' * 16), {
|
||||||
'instance': plugins.NotifyGotify,
|
'instance': plugins.NotifyGotify,
|
||||||
|
|
Loading…
Reference in New Issue