예제 #1
0
 def apns_error_listener(error_response):
     elle.log.warn('APNS error: %s' % str(error_response))
     self.__apns.gateway_server.force_close()
     self.__apns = apns.APNs(use_sandbox=not self.__production,
                             cert_file=cert,
                             enhanced=True)
     self.__apns.gateway_server.register_response_listener(
         apns_error_listener)
예제 #2
0
 def __init__(self,
              cert,
              key,
              pushtoken=None,
              use_sandbox=True,
              *args,
              **kwargs):
     super(APNSWorker, self).__init__(*args, **kwargs)
     self._pushtoken = pushtoken
     self._apns = apns.APNs(use_sandbox=use_sandbox,
                            cert_file=cert,
                            key_file=key)
예제 #3
0
    def establish_connection(self):
        if self.cert_file is None:
            raise PushAPNsCertificateException

        connection = apns.APNs(use_sandbox=self.use_sandbox,
                               cert_file=self.cert_file,
                               key_file=self.key_file,
                               enhanced=True)

        connection.gateway_server.register_response_listener(
            self.on_error_response)

        self.connection = connection
예제 #4
0
    def push_notification(self, recipient_id, token, payload, os):
        if os == 'iOS':
            cert = conf.INFINIT_APS_CERT_PATH_PRODUCTION \
                   if self.__production else conf.INFINIT_APS_CERT_PATH
            if self.__apns is None:
                self.__apns = apns.APNs(use_sandbox=not self.__production,
                                        cert_file=cert,
                                        enhanced=True)

            def apns_error_listener(error_response):
                elle.log.warn('APNS error: %s' % str(error_response))
                self.__apns.gateway_server.force_close()
                self.__apns = apns.APNs(use_sandbox=not self.__production,
                                        cert_file=cert,
                                        enhanced=True)
                self.__apns.gateway_server.register_response_listener(
                    apns_error_listener)

            self.__apns.gateway_server.register_response_listener(
                apns_error_listener)
            identifier = random.getrandbits(32)
            self.__apns.gateway_server.send_notification(token,
                                                         payload,
                                                         identifier=identifier)
        elif os == 'Android':
            headers = {
                'Authorization': 'key=%s' % API_KEY,
                'Content-Type': 'application/json',
            }
            data = {
                'registration_ids': [token],
                'data': payload,
            }
            r = requests.post(GCM_URL,
                              headers=headers,
                              data=bson.json_util.dumps(data))
            elle.log.trace('Android notification: %s' % r.content)
예제 #5
0
파일: utils.py 프로젝트: tayduivn/eucaby
def create_apns_socket(app):
    """Creates APNs socket. App should be configured at the stage."""
    return apns.APNs(
        use_sandbox=app.config['APNS_USE_SANDBOX'],
        cert_file=app.config['APNS_CERT_FILE'],
        key_file=app.config['APNS_KEY_FILE'])#, enhanced=True)
예제 #6
0
 def __init__(self, sisyphus, certificate, production):
     super().__init__(sisyphus)
     self.__cert = certificate
     self.__apns = apns.APNs(use_sandbox=not production,
                             cert_file=self.__cert)
예제 #7
0
 def _connect(self):
     """Connect to APNS"""
     self.apns = apns.APNs(use_sandbox=self.config.get("sandbox", False),
                           cert_file=self.config.get("cert_file"),
                           key_file=self.config.get("key_file"),
                           enhanced=True)