-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpn_manager.py
executable file
·39 lines (31 loc) · 1.03 KB
/
pn_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
#Push Notification Manager handles GCM interaction
#Author: Kevin Murphy
#Date : 4 - Jan - 15
import json
from configurable import Configurable
import constants as CONSTS
from gcm import GCM
from api_manager import APIManager
class PNManager(object):
DEBUG = True
LOGTAG = "PNManager"
def __init__(self):
self.__gcm = GCM(CONSTS.GCM_API_KEY)
if self.DEBUG:
print self.LOGTAG, " :: Created"
def sendJsonPush(self, data):
try:
apiManager = APIManager(sensorManager=None)
registration_ids = json.loads(apiManager.getPNRegIDs())
response = self.__gcm.json_request(registration_ids=registration_ids[CONSTS.JSON_KEY_PN_MANAGER_REG_IDS], data=data)
if self.DEBUG:
print response
except:
if self.DEBUG:
print self.LOGTAG, " :: Sending Push Notification Failed"
'''
pnManager = PNManager()
testData = {'sensor': 'temperature', 'value': 50}
pnManager.sendJsonPush(testData)
'''