From de9bb1a6842e6797c88d810c20ff8d5b09e58a7c Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sat, 16 Oct 2010 21:05:11 -0400 Subject: [PATCH 1/2] Update client and library to just use a listen URL --- docs/libnotify-example.py | 6 +++--- tynio/__init__.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/libnotify-example.py b/docs/libnotify-example.py index 59e3714..19e5229 100755 --- a/docs/libnotify-example.py +++ b/docs/libnotify-example.py @@ -6,8 +6,8 @@ from twisted.python import log as twistedLog from twisted.internet import reactor -API_KEY = 'YOUR_API_KEY_GOES_HERE' -LISTEN_TO = 'EMAIL_ADDRESS_TO_LISTEN_TO' +# Replace with the contents of your .ListenURL file +LISTEN_URL = 'http://listen.notify.io/~1/listen/XXX' class Notifier(object): ''' A small wrapper around libnotify. Because it has a crappy API. ''' @@ -26,6 +26,6 @@ def notify(self, note): n = Notifier('NIO Linux Client') - nio = tynio.NotifyIO(API_KEY, LISTEN_TO, n.notify) + nio = tynio.NotifyIO(LISTEN_URL, n.notify) nio.listen() reactor.run() diff --git a/tynio/__init__.py b/tynio/__init__.py index e8462cb..a882d57 100755 --- a/tynio/__init__.py +++ b/tynio/__init__.py @@ -4,6 +4,7 @@ from twisted.internet.protocol import ReconnectingClientFactory from twisted.internet import reactor from twisted.python import log as twistedLog +from urlparse import urlparse try: import simplejson as json @@ -37,7 +38,7 @@ def lineReceived(self, line): def connectionMade(self): self.sendCommand('GET', self.factory.path) - self.sendHeader('Host', 'api.notify.io') + self.sendHeader('Host', self.factory.host) self.sendHeader('User-Agent', self.factory.agent) self.endHeaders() twistedLog.msg('Connected and receiving...') @@ -45,8 +46,9 @@ def connectionMade(self): class _CometFactory(ReconnectingClientFactory): protocol = _CometStream - def __init__(self, callback, path, agent=None): + def __init__(self, callback, host, path, agent=None): self.callback = callback + self.host = host self.path = path self.agent = agent @@ -61,14 +63,16 @@ def clientConnectionLost(self, connector, reason): ReconnectingClientFactory.clientConnectionLost(self, connector, reason) class NotifyIO(object): - def __init__(self, api_key, email, callback, api_version=1): + def __init__(self, listen_url, callback): self.callback = callback - path = '/v%(version)i/listen/%(email)s?api_key=%(api)s' % \ - dict(version = api_version, email = md5(email).hexdigest(), api = api_key) - self.factory = _CometFactory(callback, path) + url = urlparse(listen_url) + self.path = url.path + if url.query: self.path += '?' + url.query + self.host = url.hostname + self.factory = _CometFactory(callback, self.host, self.path) def listen(self): - reactor.connectTCP('api.notify.io', 80, self.factory) + reactor.connectTCP(self.host, 80, self.factory) def kill(self): self.factory.doStop() From c3ac5a7e78c2b1e63871ae484b0b4f2b65b92d98 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sat, 16 Oct 2010 21:05:39 -0400 Subject: [PATCH 2/2] Ignore files created by setup.py --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0d20b64..e1817bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.pyc +build +dist +tynio.egg-info