From 7345481a4e038017a840bba116ca03a4281b04e4 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Wed, 6 Feb 2019 21:07:22 -0500 Subject: [PATCH] Updated of pjet:// docs+url as online service is no longer available; refs #46 --- README.md | 2 +- .../plugins/NotifyPushjet/NotifyPushjet.py | 49 +++++++++++++------ test/test_pushjet_plugin.py | 4 +- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5ba74e69..c055d671 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The table below identifies the services this tool supports and some example serv | [Prowl](https://github.com/caronc/apprise/wiki/Notify_prowl) | prowl:// | (TCP) 443 | prowl://apikey
prowl://apikey/providerkey | [Pushalot](https://github.com/caronc/apprise/wiki/Notify_pushalot) | palot:// | (TCP) 443 | palot://authorizationtoken | [PushBullet](https://github.com/caronc/apprise/wiki/Notify_pushbullet) | pbul:// | (TCP) 443 | pbul://accesstoken
pbul://accesstoken/#channel
pbul://accesstoken/A_DEVICE_ID
pbul://accesstoken/email@address.com
pbul://accesstoken/#channel/#channel2/email@address.net/DEVICE -| [Pushjet](https://github.com/caronc/apprise/wiki/Notify_pushjet) | pjet:// | (TCP) 80 | pjet://secret
pjet://secret@hostname
pjet://secret@hostname:port
pjets://secret@hostname
pjets://secret@hostname:port
Note: if no hostname defined https://api.pushjet.io will be used +| [Pushjet](https://github.com/caronc/apprise/wiki/Notify_pushjet) | pjet:// | (TCP) 80 | pjet://secret@hostname
pjet://secret@hostname:port
pjets://secret@hostname
pjets://secret@hostname:port | [Pushover](https://github.com/caronc/apprise/wiki/Notify_pushover) | pover:// | (TCP) 443 | pover://user@token
pover://user@token/DEVICE
pover://user@token/DEVICE1/DEVICE2/DEVICEN
_Note: you must specify both your user_id and token_ | [Rocket.Chat](https://github.com/caronc/apprise/wiki/Notify_rocketchat) | rocket:// or rockets:// | (TCP) 80 or 443 | rocket://user:password@hostname/RoomID/Channel
rockets://user:password@hostname:443/Channel1/Channel1/RoomID
rocket://user:password@hostname/Channel | [Slack](https://github.com/caronc/apprise/wiki/Notify_slack) | slack:// | (TCP) 443 | slack://TokenA/TokenB/TokenC/Channel
slack://botname@TokenA/TokenB/TokenC/Channel
slack://user@TokenA/TokenB/TokenC/Channel1/Channel2/ChannelN diff --git a/apprise/plugins/NotifyPushjet/NotifyPushjet.py b/apprise/plugins/NotifyPushjet/NotifyPushjet.py index 7258b477..cb9ddc94 100644 --- a/apprise/plugins/NotifyPushjet/NotifyPushjet.py +++ b/apprise/plugins/NotifyPushjet/NotifyPushjet.py @@ -43,9 +43,6 @@ class NotifyPushjet(NotifyBase): # The default descriptive name associated with the Notification service_name = 'Pushjet' - # The services URL - service_url = 'https://pushjet.io/' - # The default protocol protocol = 'pjet' @@ -66,21 +63,16 @@ class NotifyPushjet(NotifyBase): Perform Pushjet Notification """ try: - if self.user and self.host: - server = "http://" - if self.secure: - server = "https://" - - server += self.host - if self.port: - server += ":" + str(self.port) + server = "http://" + if self.secure: + server = "https://" - api = pushjet.Api(server) - service = api.Service(secret_key=self.user) + server += self.host + if self.port: + server += ":" + str(self.port) - else: - api = pushjet.Api(pushjet.DEFAULT_API_URL) - service = api.Service(secret_key=self.host) + api = pushjet.Api(server) + service = api.Service(secret_key=self.user) service.send(body, title) self.logger.info('Sent Pushjet notification.') @@ -91,3 +83,28 @@ class NotifyPushjet(NotifyBase): return False return True + + @staticmethod + def parse_url(url): + """ + Parses the URL and returns enough arguments that can allow + us to substantiate this object. + + Syntax: + pjet://secret@hostname + pjet://secret@hostname:port + pjets://secret@hostname + pjets://secret@hostname:port + + """ + results = NotifyBase.parse_url(url) + + if not results: + # We're done early as we couldn't load the results + return results + + if not results.get('user'): + # a username is required + return None + + return results diff --git a/test/test_pushjet_plugin.py b/test/test_pushjet_plugin.py index 1ab0f00b..789d4844 100644 --- a/test/test_pushjet_plugin.py +++ b/test/test_pushjet_plugin.py @@ -38,9 +38,9 @@ TEST_URLS = ( ('pjets://', { 'instance': None, }), - # Default query (uses pushjet server) + # You must specify a username ('pjet://%s' % ('a' * 32), { - 'instance': plugins.NotifyPushjet, + 'instance': None, }), # Specify your own server ('pjet://%s@localhost' % ('a' * 32), {