growlee: more work on multiconnect
[enigma2-plugins.git] / growlee / src / Prowl.py
1 from twisted.web.client import getPage
2 from twisted.internet.defer import Deferred
3 from twisted.internet import reactor
4 from urllib import urlencode
5
6 from GrowleeConnection import emergencyDisable
7 from . import NOTIFICATIONID
8
9 class ProwlAPI:
10         def __init__(self, host):
11                 self.enable_outgoing = host.enable_outgoing.value
12                 self.api_key = host.password.value
13
14         def sendNotification(self, title='No title.', description='No message.', priority=0, timeout=-1):
15                 if not self.enable_outgoing:
16                         return
17
18                 headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
19                 data = {
20                         'apikey': self.api_key,
21                         'application': "growlee",
22                         'event': title,
23                         'description': description,
24                         'priority': priority,
25                 }
26
27                 getPage('https://prowl.weks.net/publicapi/add/', method = 'POST', headers = headers, postdata = urlencode(data)).addErrback(emergencyDisable)
28
29         def stop(self):
30                 defer = Deferred()
31                 reactor.callLater(1, defer.callback, True)
32                 return defer
33