def render(self, client_types):
        if not isinstance(client_types, list):
            # Listify client types, if needed
            client_types = [client_types]

        if not self.check_enabled():
            # Don't send for NotificationTypes that aren't enabled
            return

        for client_type in client_types:
            if client_type is ClientType.OS_ANDROID and client_type in self.keys:
                client_render_method = self.render_method(client_type)
                notification = client_render_method()
                if len(
                        self.keys[client_type]
                ) > 0:  # this is after _render because if it's an update fav/subscription notification, then
                    NotificationSender.send_gcm(
                        notification
                    )  # we remove the client id that sent the update so it doesn't get notified redundantly

            elif client_type == ClientType.WEBHOOK and ClientType.WEBHOOK in self.keys and len(
                    self.keys[ClientType.WEBHOOK]) > 0:
                notification = self._render_webhook()
                NotificationSender.send_webhook(notification,
                                                self.keys[ClientType.WEBHOOK])
    def render(self, client_types):
        if not isinstance(client_types, list):
            # Listify client types, if needed
            client_types = [client_types]

        if not self.check_enabled():
            # Don't send for NotificationTypes that aren't enabled
            return

        for client_type in client_types:
            if client_type == ClientType.OS_ANDROID and ClientType.OS_ANDROID in self.keys:
                notification = self._render_android()
                if len(self.keys[ClientType.OS_ANDROID]) > 0:  # this is after _render because if it's an update fav/subscription notification, then
                    NotificationSender.send_gcm(notification)  # we remove the client id that sent the update so it doesn't get notified redundantly

            elif client_type == ClientType.OS_IOS and ClientType.OS_IOS in self.keys:
                notification = self._render_ios()
                NotificationSender.send_ios(notification)

            if client_type == ClientType.WEB and ClientType.WEB in self.keys:
                notification = self._render_web()
                if len(self.keys[ClientType.WEB]) > 0:  # this is after _render because if it's an update fav/subscription notification, then
                    NotificationSender.send_gcm(notification)  # we remove the client id that sent the update so it doesn't get notified redundantly

            elif client_type == ClientType.WEBHOOK and ClientType.WEBHOOK in self.keys and len(self.keys[ClientType.WEBHOOK]) > 0:
                notification = self._render_webhook()
                NotificationSender.send_webhook(notification, self.keys[ClientType.WEBHOOK])
Example #3
0
    def get(self):
        webhooks = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
        failures = []

        notification = PingNotification()._render_webhook()

        for key in webhooks:
            if not NotificationSender.send_webhook(notification, [(key.messaging_id, key.secret)]):
                failures.append(key.key)

        count = len(failures)
        if failures:
            ndb.delete_multi(failures)
        logging.info("Deleted {} broken webhooks".format(count))

        template_values = {'count': count}
        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/webhooks_clear_do.html')
        self.response.out.write(template.render(path, template_values))
Example #4
0
    def render(self, client_types):
        for client_type in client_types:
            if client_type == ClientType.OS_ANDROID and ClientType.OS_ANDROID in self.keys:
                notification = self._render_android()
                if len(
                        self.keys[ClientType.OS_ANDROID]
                ) > 0:  # this is after _render because if it's an update fav/subscription notification, then
                    NotificationSender.send_gcm(
                        notification
                    )  # we remove the client id that sent the update so it doesn't get notified redundantly

            elif client_type == ClientType.OS_IOS and ClientType.OS_IOS in self.keys:
                notification = self._render_ios()
                NotificationSender.send_ios(notification)

            elif client_type == ClientType.WEBHOOK and ClientType.WEBHOOK in self.keys and len(
                    self.keys[ClientType.WEBHOOK]) > 0:
                notification = self._render_webhook()
                NotificationSender.send_webhook(notification,
                                                self.keys[ClientType.WEBHOOK])