Skip to content

Commit

Permalink
modificata identitazioni in sapzi
Browse files Browse the repository at this point in the history
  • Loading branch information
morlins committed Mar 15, 2017
1 parent bbcc869 commit 548fd6b
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions api/multipush.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_apns_conn(self):

def async_multipush(self, data):

data = self.validate_data(data)
data = self.validate_data(data)

# Hook
if 'extra' in data:
Expand Down Expand Up @@ -99,58 +99,58 @@ def async_multipush(self, data):
self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))

if device == DEVICE_TYPE_SMS:
data.setdefault('sms', {})
data['sms'].setdefault('to', data.get('token', ''))
data['sms'].setdefault('message', data.get('message', ''))
sms = self.smsconnections[self.app['shortname']][0]
sms.process(token=data['token'], alert=data['alert'], extra=extra, sms=data['sms'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_IOS:
data.setdefault('sms', {})
data['sms'].setdefault('to', data.get('token', ''))
data['sms'].setdefault('message', data.get('message', ''))
sms = self.smsconnections[self.app['shortname']][0]
sms.process(token=data['token'], alert=data['alert'], extra=extra, sms=data['sms'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_IOS:
_logger.info('push for alert: %s',data['alert'])
# Use sliptlines trick to remove line ending (only for iOs).
if type(data['alert']) is not dict:
alert = ''.join(data['alert'].splitlines())
else:
alert = data['alert']
data.setdefault('apns', {})
data['apns'].setdefault('badge', data.get('badge', None))
data['apns'].setdefault('sound', data.get('sound', None))
data['apns'].setdefault('custom', data.get('custom', None))
_logger.info('push for ios data: %s',data)
_logger.info('push for ios extra: %s',extra)
self.get_apns_conn().process(token=self.token, alert=alert, extra=extra, apns=data['apns'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_ANDROID:
data.setdefault('gcm', {})
try:
gcm = self.gcmconnections[self.app['shortname']][0]
_logger.info('push for android data: %s',data)
response = gcm.process(token=[self.token], alert=data['alert'], extra=data['extra'], gcm=data['gcm'])
responsedata = response.json()
if responsedata['failure'] == 0:
self.send_response(ACCEPTED)
except GCMUpdateRegIDsException as ex:
self.send_response(ACCEPTED)
except GCMInvalidRegistrationException as ex:
self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
except GCMNotRegisteredException as ex:
self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
except GCMException as ex:
self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))
elif device == DEVICE_TYPE_WNS:
data.setdefault('wns', {})
wns = self.wnsconnections[self.app['shortname']][0]
wns.process(token=data['token'], alert=data['alert'], extra=extra, wns=data['wns'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_MPNS:
data.setdefault('mpns', {})
mpns = self.mpnsconnections[self.app['shortname']][0]
mpns.process(token=data['token'], alert=data['alert'], extra=extra, mpns=data['mpns'])
self.send_response(ACCEPTED)
else:
self.send_response(BAD_REQUEST, dict(error='Invalid device type'))
logmessage = 'Message length: %s, Access key: %s' %(len(data['alert']), self.appkey)
self.add_to_log('%s notification' % self.appname, logmessage)
# Use sliptlines trick to remove line ending (only for iOs).
if type(data['alert']) is not dict:
alert = ''.join(data['alert'].splitlines())
else:
alert = data['alert']
data.setdefault('apns', {})
data['apns'].setdefault('badge', data.get('badge', None))
data['apns'].setdefault('sound', data.get('sound', None))
data['apns'].setdefault('custom', data.get('custom', None))
_logger.info('push for ios data: %s',data)
_logger.info('push for ios extra: %s',extra)
self.get_apns_conn().process(token=self.token, alert=alert, extra=extra, apns=data['apns'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_ANDROID:
data.setdefault('gcm', {})
try:
gcm = self.gcmconnections[self.app['shortname']][0]
_logger.info('push for android data: %s',data)
response = gcm.process(token=[self.token], alert=data['alert'], extra=data['extra'], gcm=data['gcm'])
responsedata = response.json()
if responsedata['failure'] == 0:
self.send_response(ACCEPTED)
except GCMUpdateRegIDsException as ex:
self.send_response(ACCEPTED)
except GCMInvalidRegistrationException as ex:
self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
except GCMNotRegisteredException as ex:
self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
except GCMException as ex:
self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))
elif device == DEVICE_TYPE_WNS:
data.setdefault('wns', {})
wns = self.wnsconnections[self.app['shortname']][0]
wns.process(token=data['token'], alert=data['alert'], extra=extra, wns=data['wns'])
self.send_response(ACCEPTED)
elif device == DEVICE_TYPE_MPNS:
data.setdefault('mpns', {})
mpns = self.mpnsconnections[self.app['shortname']][0]
mpns.process(token=data['token'], alert=data['alert'], extra=extra, mpns=data['mpns'])
self.send_response(ACCEPTED)
else:
self.send_response(BAD_REQUEST, dict(error='Invalid device type'))
logmessage = 'Message length: %s, Access key: %s' %(len(data['alert']), self.appkey)
self.add_to_log('%s notification' % self.appname, logmessage)

#def finish(self):
# return
Expand All @@ -171,9 +171,9 @@ def post(self):
try:
for self.notification in notifications:
self.token = self.notification['token']
# Method that send multiple push notifications asynchronously calling callback when finished.
#result = pool.apply_async(self.async_multipush, [self.notification], callback=self.finish)
self.async_multipush(self.notification)
# Method that send multiple push notifications asynchronously calling callback when finished.
#result = pool.apply_async(self.async_multipush, [self.notification], callback=self.finish)
self.async_multipush(self.notification)
except Exception as ex:
_logger.error(ex)
except Exception as ex:
Expand Down

0 comments on commit 548fd6b

Please sign in to comment.