Skip to content

Commit

Permalink
url_identifier() function added to all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Jul 2, 2024
1 parent 2e6e3f6 commit ee2aea1
Show file tree
Hide file tree
Showing 109 changed files with 1,381 additions and 174 deletions.
2 changes: 1 addition & 1 deletion apprise/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
# Global Support
#

# C:\ProgramData\Apprise\
# C:\ProgramData\Apprise
'%ALLUSERSPROFILE%\\Apprise\\apprise',
'%ALLUSERSPROFILE%\\Apprise\\apprise.conf',
'%ALLUSERSPROFILE%\\Apprise\\apprise.yml',
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,15 @@ def url(self, privacy=False, *args, **kwargs):
params=NotifyAprs.urlencode(params),
)

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.user, self.password, self.locale)

def __len__(self):
"""
Returns the number of targets associated with this notification
Expand Down
12 changes: 12 additions & 0 deletions apprise/plugins/bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):

return not has_error

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (
self.secure_protocol if self.secure else self.protocol,
self.user, self.password, self.host, self.port,
)

def url(self, privacy=False, *args, **kwargs):
"""
Returns the URL built dynamically based on specified arguments.
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/boxcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ def url(self, privacy=False, *args, **kwargs):
params=NotifyBoxcar.urlencode(params),
)

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.access, self.secret)

def __len__(self):
"""
Returns the number of targets associated with this notification
Expand Down
13 changes: 13 additions & 0 deletions apprise/plugins/bulksms.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ def url(self, privacy=False, *args, **kwargs):
for x in self.groups])),
params=NotifyBulkSMS.urlencode(params))

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (
self.secure_protocol,
self.user if self.user else None,
self.password if self.password else None,
)

def __len__(self):
"""
Returns the number of targets associated with this notification
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/bulkvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):

return not has_error

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.source, self.user, self.password)

def url(self, privacy=False, *args, **kwargs):
"""
Returns the URL built dynamically based on specified arguments.
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/burstsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ def url(self, privacy=False, *args, **kwargs):
[NotifyBurstSMS.quote(x, safe='') for x in self.targets]),
params=NotifyBurstSMS.urlencode(params))

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.apikey, self.secret, self.source)

def __len__(self):
"""
Returns the number of targets associated with this notification
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/chantify.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ def url(self, privacy=False, *args, **kwargs):
params=NotifyChantify.urlencode(params),
)

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.token)

@staticmethod
def parse_url(url):
"""
Expand Down
9 changes: 9 additions & 0 deletions apprise/plugins/clicksend.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ def url(self, privacy=False, *args, **kwargs):
params=NotifyClickSend.urlencode(params),
)

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.user, self.password)

def __len__(self):
"""
Returns the number of targets associated with this notification
Expand Down
126 changes: 70 additions & 56 deletions apprise/plugins/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,62 +272,6 @@ def __init__(self, headers=None, method=None, payload=None, params=None,

return

def url(self, privacy=False, *args, **kwargs):
"""
Returns the URL built dynamically based on specified arguments.
"""

# Define any URL parameters
params = {
'method': self.method,
}

# Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))

# Append our headers into our parameters
params.update({'+{}'.format(k): v for k, v in self.headers.items()})

# Append our GET params into our parameters
params.update({'-{}'.format(k): v for k, v in self.params.items()})

# Append our payload extra's into our parameters
params.update(
{':{}'.format(k): v for k, v in self.payload_extras.items()})
params.update(
{':{}'.format(k): v for k, v in self.payload_overrides.items()})

if self.attach_as != self.attach_as_default:
# Provide Attach-As extension details
params['attach-as'] = self.attach_as

# Determine Authentication
auth = ''
if self.user and self.password:
auth = '{user}:{password}@'.format(
user=NotifyForm.quote(self.user, safe=''),
password=self.pprint(
self.password, privacy, mode=PrivacyMode.Secret, safe=''),
)
elif self.user:
auth = '{user}@'.format(
user=NotifyForm.quote(self.user, safe=''),
)

default_port = 443 if self.secure else 80

return '{schema}://{auth}{hostname}{port}{fullpath}?{params}'.format(
schema=self.secure_protocol if self.secure else self.protocol,
auth=auth,
# never encode hostname since we're expecting it to be a valid one
hostname=self.host,
port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port),
fullpath=NotifyForm.quote(self.fullpath, safe='/')
if self.fullpath else '/',
params=NotifyForm.urlencode(params),
)

def send(self, body, title='', notify_type=NotifyType.INFO, attach=None,
**kwargs):
"""
Expand Down Expand Up @@ -486,6 +430,76 @@ def send(self, body, title='', notify_type=NotifyType.INFO, attach=None,

return True

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (
self.secure_protocol if self.secure else self.protocol,
self.user, self.password, self.host,
self.port if self.port else (443 if self.secure else 80),
self.fullpath.rstrip('/'),
)

def url(self, privacy=False, *args, **kwargs):
"""
Returns the URL built dynamically based on specified arguments.
"""

# Define any URL parameters
params = {
'method': self.method,
}

# Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))

# Append our headers into our parameters
params.update({'+{}'.format(k): v for k, v in self.headers.items()})

# Append our GET params into our parameters
params.update({'-{}'.format(k): v for k, v in self.params.items()})

# Append our payload extra's into our parameters
params.update(
{':{}'.format(k): v for k, v in self.payload_extras.items()})
params.update(
{':{}'.format(k): v for k, v in self.payload_overrides.items()})

if self.attach_as != self.attach_as_default:
# Provide Attach-As extension details
params['attach-as'] = self.attach_as

# Determine Authentication
auth = ''
if self.user and self.password:
auth = '{user}:{password}@'.format(
user=NotifyForm.quote(self.user, safe=''),
password=self.pprint(
self.password, privacy, mode=PrivacyMode.Secret, safe=''),
)
elif self.user:
auth = '{user}@'.format(
user=NotifyForm.quote(self.user, safe=''),
)

default_port = 443 if self.secure else 80

return '{schema}://{auth}{hostname}{port}{fullpath}?{params}'.format(
schema=self.secure_protocol if self.secure else self.protocol,
auth=auth,
# never encode hostname since we're expecting it to be a valid one
hostname=self.host,
port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port),
fullpath=NotifyForm.quote(self.fullpath, safe='/')
if self.fullpath else '/',
params=NotifyForm.urlencode(params),
)

@staticmethod
def parse_url(url):
"""
Expand Down
Loading

0 comments on commit ee2aea1

Please sign in to comment.