Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add initial version of URL callbacks

This is a simple URL callback to get people started. In the future, it
would be nice if callback can be either a string for URL callbacks or a
function.

Fixes #11
  • Loading branch information...
commit 32f41797706158de5b330df5380cd6b67e30f87b 1 parent f435588
@kfdm authored
Showing with 18 additions and 3 deletions.
  1. +3 −0  gntp/cli.py
  2. +3 −1 gntp/config.py
  3. +12 −2 gntp/notifier.py
View
3  gntp/cli.py
@@ -39,6 +39,7 @@ def __init__(self):
dest="priority", type="int", default=0)
self.add_option("--image", help="Icon for notification (Only supports URL currently)",
dest="icon", default='')
+ self.add_option("--callback", help="URL callback", dest="callback")
def parse_args(self, args=None, values=None):
values, args = OptionParser.parse_args(self, args, values)
@@ -62,6 +63,7 @@ def parse_args(self, args=None, values=None):
return values, message
+
def main():
(options, message) = ClientParser().parse_args()
if options.debug:
@@ -88,6 +90,7 @@ def main():
icon=options.icon,
sticky=options.sticky,
priority=options.priority,
+ callback=options.callback,
)
if result is not True:
exit(result)
View
4 gntp/config.py
@@ -23,7 +23,8 @@
def mini(description, applicationName='PythonMini', noteType="Message",
title="Mini Message", applicationIcon=None, hostname='localhost',
- password=None, port=23053, sticky=False, priority=None):
+ password=None, port=23053, sticky=False, priority=None,
+ callback=None):
"""Single notification function
Simple notification function in one line. Has only one required parameter
@@ -49,6 +50,7 @@ def mini(description, applicationName='PythonMini', noteType="Message",
icon=applicationIcon,
sticky=sticky,
priority=priority,
+ callback=callback,
)
View
14 gntp/notifier.py
@@ -24,7 +24,8 @@
def mini(description, applicationName='PythonMini', noteType="Message",
title="Mini Message", applicationIcon=None, hostname='localhost',
- password=None, port=23053, sticky=False, priority=None):
+ password=None, port=23053, sticky=False, priority=None,
+ callback=None):
"""Single notification function
Simple notification function in one line. Has only one required parameter
@@ -50,6 +51,7 @@ def mini(description, applicationName='PythonMini', noteType="Message",
icon=applicationIcon,
sticky=sticky,
priority=priority,
+ callback=callback,
)
@@ -113,7 +115,8 @@ def register(self):
self.register_hook(register)
return self._send('register', register)
- def notify(self, noteType, title, description, icon=None, sticky=False, priority=None):
+ def notify(self, noteType, title, description, icon=None, sticky=False,
+ priority=None, callback=None):
"""Send a GNTP notifications
.. warning::
@@ -125,6 +128,11 @@ def notify(self, noteType, title, description, icon=None, sticky=False, priority
:param string icon: Icon URL path
:param boolean sticky: Sticky notification
:param integer priority: Message priority level from -2 to 2
+ :param string callback: URL callback
+
+ .. warning::
+ For now, only URL callbacks are supported. In the future, the
+ callback argument will also support a function
"""
logger.info('Sending notification [%s] to %s:%s', noteType, self.hostname, self.port)
assert noteType in self.notifications
@@ -142,6 +150,8 @@ def notify(self, noteType, title, description, icon=None, sticky=False, priority
notice.add_header('Notification-Icon', self._checkIcon(icon))
if description:
notice.add_header('Notification-Text', description)
+ if callback:
+ notice.add_header('Notification-Callback-Target', callback)
self.add_origin_info(notice)
self.notify_hook(notice)
Please sign in to comment.
Something went wrong with that request. Please try again.