Exemplo n.º 1
0
    def setup(self, ctx):
        self.db = ctx.database

        api_key = self.getConfig('apiKey')
        if not api_key:
            raise PushkinSetupException("No API key set in config")
        self.gcm = gcmclient.GCM(api_key)
        self.canonical_reg_id_store = CanonicalRegIdStore(self.db)
Exemplo n.º 2
0
 def __init__(self, ap_settings, router_conf):
     """Create a new GCM router and connect to GCM"""
     self.config = router_conf
     self.ttl = router_conf.get("ttl", 60)
     self.dryRun = router_conf.get("dryrun", False)
     self.collapseKey = router_conf.get("collapseKey", "simplepush")
     self.senderIDs = router_conf.get("senderIDs")
     if not self.senderIDs:
         self.senderIDs = SenderIDs(router_conf)
     try:
         senderID = self.senderIDs.choose_ID()
         self.gcm = gcmclient.GCM(senderID.get("auth"))
     except:
         raise IOError("GCM Bridge not initiated in main")
     log.msg("Starting GCM router...")
Exemplo n.º 3
0
 def __init__(self, ap_settings, router_conf, metrics):
     """Create a new GCM router and connect to GCM"""
     self.ap_settings = ap_settings
     self.config = router_conf
     self.metrics = metrics
     self.min_ttl = router_conf.get("ttl", 60)
     self.dryRun = router_conf.get("dryrun", False)
     self.collapseKey = router_conf.get("collapseKey", "simplepush")
     self.gcm = {}
     self.senderIDs = {}
     # Flatten the SenderID list from human readable and init gcmclient
     if not router_conf.get("senderIDs"):
         raise IOError("SenderIDs not configured.")
     for sid in router_conf.get("senderIDs"):
         auth = router_conf.get("senderIDs").get(sid).get("auth")
         self.senderIDs[sid] = auth
         try:
             self.gcm[sid] = gcmclient.GCM(auth)
         except:
             raise IOError("GCM Bridge not initiated in main")
     self._base_tags = ["platform:gcm"]
     self.log.debug("Starting GCM router...")
Exemplo n.º 4
0
        settings.APNS_FEEDBACK, cert_file=settings.APNS_CERT_FILE)
    apns_client = APNs(feedback_connection, tail_timeout=20)

    for token, since in apns_client.feedback():
        since_date = timestamp_to_datetime(since)
        logging.info("Found unavailable token %s, unavailable since %s" %
                     (token, since_date))

        PushDeviceToken.objects.filter(token=hex_to_b64(token),
                                       last_updates__lt=since_date,
                                       type=PushDeviceToken.APNS).delete()
    logging.info("Finished checking feedback for stale tokens")


if settings.ANDROID_GCM_API_KEY:
    gcm = gcmclient.GCM(settings.ANDROID_GCM_API_KEY)
else:
    gcm = None


@statsd_increment("android_push_notification")
def send_android_push_notification(user, data):
    if not gcm:
        logging.error(
            "Attempting to send a GCM push notification, but no API key was configured"
        )
        return

    reg_ids = [
        device.token
        for device in PushDeviceToken.objects.filter(user=user,