def _apns_send( registration_id, alert, batch=False, application_id=None, certfile=None, **kwargs ): client = _apns_create_socket(certfile=certfile, application_id=application_id) notification_kwargs = {} # if expiration isn"t specified use 1 month from now notification_kwargs["expiration"] = kwargs.pop("expiration", None) if not notification_kwargs["expiration"]: notification_kwargs["expiration"] = int(time.time()) + 2592000 priority = kwargs.pop("priority", None) if priority: try: notification_kwargs["priority"] = apns2_client.NotificationPriority(str(priority)) except ValueError: raise APNSUnsupportedPriority("Unsupported priority %d" % (priority)) if batch: data = [apns2_client.Notification( token=rid, payload=_apns_prepare(rid, alert, **kwargs)) for rid in registration_id] return client.send_notification_batch( data, get_manager().get_apns_topic(application_id=application_id), **notification_kwargs ) data = _apns_prepare(registration_id, alert, **kwargs) client.send_notification( registration_id, data, "com.vitaminsoftware.Cami", **notification_kwargs )
def _apns_send(registration_id, alert, batch=False, **kwargs): client = _apns_create_socket(kwargs.pop("certfile", None)) notification_kwargs = {} # if expiration isn"t specified use 1 month from now notification_kwargs["expiration"] = kwargs.pop("expiration", None) if not notification_kwargs["expiration"]: notification_kwargs["expiration"] = int(time.time()) + 2592000 priority = kwargs.pop("priority", None) if priority: try: notification_kwargs[ "priority"] = apns2_client.NotificationPriority(str(priority)) except ValueError: raise APNSUnsupportedPriority("Unsupported priority %d" % (priority)) if batch: data = [ apns2_client.Notification(token=rid, payload=_apns_prepare( rid, alert, **kwargs)) for rid in registration_id ] return client.send_notification_batch(data, SETTINGS.get("APNS_TOPIC"), **notification_kwargs) data = _apns_prepare(registration_id, alert, **kwargs) client.send_notification(registration_id, data, SETTINGS.get("APNS_TOPIC"), **notification_kwargs)
def _apns_send(registration_id, alert, batch=False, application_id=None, creds=None, **kwargs): client = _apns_create_socket(creds=creds, application_id=application_id) notification_kwargs = {} # if expiration isn"t specified use 1 month from now notification_kwargs["expiration"] = kwargs.pop("expiration", None) if not notification_kwargs["expiration"]: notification_kwargs["expiration"] = int(time.time()) + 2592000 priority = kwargs.pop("priority", None) if priority: try: notification_kwargs[ "priority"] = apns2_client.NotificationPriority(str(priority)) except ValueError: raise APNSUnsupportedPriority("Unsupported priority %d" % (priority)) notification_kwargs["collapse_id"] = kwargs.pop("collapse_id", None) if batch: data = [ apns2_client.Notification(token=rid, payload=_apns_prepare( rid, alert, **kwargs)) for rid in registration_id ] # returns a dictionary mapping each token to its result. That # result is either "Success" or the reason for the failure. return client.send_notification_batch( data, get_manager().get_apns_topic(application_id=application_id), **notification_kwargs) data = _apns_prepare(registration_id, alert, **kwargs) client.send_notification( registration_id, data, get_manager().get_apns_topic(application_id=application_id), **notification_kwargs)