def send_message(self, msg, debug=False): devices = Device.objects.filter(cluster_id=self.cluster_id) get_regs = operator.attrgetter('reg_id') if not devices: if debug: print 'No devices with cluster ID =', cluster return if debug: print 'Devices found =', devices try: reply = send_gcm_message(settings.GCM_APIKEY, map(get_regs, devices), msg, 'C_Update') results = parse_gcm_result(reply) except Exception as e: results = [] reply = e if results: for i,result in enumerate(results): if result != 'OK': if result[0] == 'reg_id': reregister(devices[i], result[1]) else: #error received if result[1] == 'NotRegistered' or result[1] == 'InvalidRegistration': unregister(devices[i]) else: #Another error that we don't need to deal with yet pass if debug: print 'Reply from server =', reply print 'Results =', results
def send_message(self, msg): """ Send message to current device """ return send_gcm_message(api_key=settings.GCM_APIKEY, reg_id=[self.reg_id], data=msg, collapse_key="D_Update")