Ejemplo n.º 1
0
    def __init__(self, platform_type=None, priority=None, collapse_key=None):
        """
        Args:
            platform_type (int): Type for the platform payload - can be None when using for default payload.
            priority (int): Priority for push notification - may be None.
            collapse_key (string): Collapse key for push notification - may be None.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that our platform_type looks right
        if platform_type:
            validate_is_type(int, not_empty=False, platform_type=platform_type)
            PlatformPayload._validate_platform_type(platform_type)
        self.platform_type = platform_type

        # Check that our priority looks right
        if priority:
            validate_is_type(int, not_empty=False, priority=priority)
            if priority not in PlatformPayloadPriority.types:
                raise TypeError(
                    "Unsupported PlatformPayload priority: {}".format(
                        priority))
        self.priority = priority

        # Check that our collapse key looks right
        if collapse_key:
            validate_is_string(collapse_key=collapse_key)
        self.collapse_key = collapse_key
Ejemplo n.º 2
0
    def __init__(self, response=None, error=None):
        """
        Success JSON will look like...

        {
            "applicationVersion": "1.0.2",
            "application": "com.the-blue-alliance.zach-dev",
            "scope": "*",
            "authorizedEntity": "244307294958",
            "rel": {
                "topics": {
                    "broadcasts": {"addDate":"2019-02-15"}
                }
            },
            "platform":"IOS"
        }

        Error JSON will look like...
        {
            "error": "InvalidToken"
        }
        """
        super(SubscriptionStatusResponse, self).__init__(response=response,
                                                         error=error)

        from tbans.utils.validation_utils import validate_is_type

        relations = self.data.get('rel', {})
        validate_is_type(dict, not_empty=False, relations=relations)

        topics = relations.get('topics', {})
        validate_is_type(dict, not_empty=False, topics=topics)

        self.subscriptions = [str(topic) for topic in topics]
    def __init__(self, response=None, error=None):
        """
        Args:
            response (object, content/status_code/headers): response from urlfetch Instance ID API call (https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.urlfetch)
            error (string): Directly pass an error instead of trying to parse the error from the JSON response.
        """
        if not response and not error:
            raise ValueError(
                'SubscriptionResponse must be initilized with either a response or an error'
            )

        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that response looks right
        if response:
            if response.content:
                validate_is_string(content=response.content)
            # Check that we have a status_code
            validate_is_type(int,
                             not_empty=False,
                             status_code=response.status_code)
        self._response = response

        # Check that error looks right
        if error:
            validate_is_string(error=error)
        self._error = error
    def __init__(self, tokens, topic, action_type):
        """
        Args:
            tokens (list, string): A non-empty list of device registration tokens. Also accepts a single device token as a string.
                List may not have more than 1000 elements.
            topic (string): Name of the topic for the request. May contain the ``/topics/`` prefix.
            action (SubscriptionActionType, int): Action to execute via the request - should be a SubscriptionActionType const
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Ensure our tokens are right - non-empty strings, in a list
        if isinstance(tokens, basestring):
            tokens = [tokens]
        validate_is_type(list, tokens=tokens)
        invalid_str = [t for t in tokens if not isinstance(t, basestring) or not t]
        if invalid_str:
            raise ValueError('SubscriptionBatchRequest tokens must be non-empty strings.')
        if len(tokens) > 1000:
            raise ValueError('SubscriptionBatchRequest tokens must have no more than 1000 tokens.')

        # Ensure our topic is right - format like `/topics/something`
        validate_is_string(topic=topic)
        if not topic.startswith('/topics/'):
            topic = '/topics/{0}'.format(topic)

        if action_type not in SubscriptionActionType.batch_actions:
            raise ValueError('SubscriptionBatchRequest unsupported action {}.'.format(action_type))

        self.tokens = tokens
        self.topic = topic
        self._action_type = action_type
    def __init__(self, platform_type=None, priority=None, collapse_key=None):
        """
        Args:
            platform_type (int): Type for the platform payload - can be None when using for default payload.
            priority (int): Priority for push notification - may be None.
            collapse_key (string): Collapse key for push notification - may be None.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that our platform_type looks right
        if platform_type:
            validate_is_type(int, not_empty=False, platform_type=platform_type)
            PlatformPayload._validate_platform_type(platform_type)
        self.platform_type = platform_type

        # Check that our priority looks right
        if priority:
            validate_is_type(int, not_empty=False, priority=priority)
            if priority not in PlatformPayloadPriority.types:
                raise TypeError("Unsupported PlatformPayload priority: {}".format(priority))
        self.priority = priority

        # Check that our collapse key looks right
        if collapse_key:
            validate_is_string(collapse_key=collapse_key)
        self.collapse_key = collapse_key
    def __init__(self, response=None, error=None):
        """
        Success JSON will look like...

        {
            "applicationVersion": "1.0.2",
            "application": "com.the-blue-alliance.zach-dev",
            "scope": "*",
            "authorizedEntity": "244307294958",
            "rel": {
                "topics": {
                    "broadcasts": {"addDate":"2019-02-15"}
                }
            },
            "platform":"IOS"
        }

        Error JSON will look like...
        {
            "error": "InvalidToken"
        }
        """
        super(SubscriptionStatusResponse, self).__init__(response=response, error=error)

        from tbans.utils.validation_utils import validate_is_type

        relations = self.data.get('rel', {})
        validate_is_type(dict, not_empty=False, relations=relations)

        topics = relations.get('topics', {})
        validate_is_type(dict, not_empty=False, topics=topics)

        self.subscriptions = [str(topic) for topic in topics]
    def __init__(self, notification):
        """
        Args:
            notification (Notification): The Notification to send.
        """
        from tbans.models.notifications.notification import Notification
        from tbans.utils.validation_utils import validate_is_type

        validate_is_type(Notification, notification=notification)
        self.notification = notification
Ejemplo n.º 8
0
    def __init__(self, notification):
        """
        Args:
            notification (Notification): The Notification to send.
        """
        from tbans.models.notifications.notification import Notification
        from tbans.utils.validation_utils import validate_is_type

        validate_is_type(Notification, notification=notification)
        self.notification = notification
Ejemplo n.º 9
0
    def __init__(self, token, result):
        """
        Args:
            token (string): Instance ID for the subscriber.
            result (dict): Dictionary result for the subscriber.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that token looks right.
        validate_is_string(token=token)
        self.token = token

        # Check that result looks right.
        validate_is_type(dict, not_empty=False, result=result)
        self.error = result.get('error', None)
    def __init__(self, url, secret):
        """
        Args:
            url (string): The URL to send the notification payload to.
            secret (string): The secret to calculate the payload checksum with.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type
        # Check url
        validate_is_string(url=url)

        # Check secret
        validate_is_type(basestring, not_empty=False, secret=secret)

        self.url = url
        self.secret = secret
        self._generate_key()
Ejemplo n.º 11
0
    def __init__(self, url, secret):
        """
        Args:
            url (string): The URL to send the notification payload to.
            secret (string): The secret to calculate the payload checksum with.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type
        # Check url
        validate_is_string(url=url)

        # Check secret
        validate_is_type(basestring, not_empty=False, secret=secret)

        self.url = url
        self.secret = secret
        self._generate_key()
    def __init__(self, status_code, content=None):
        """
        Args:
            status_code (int): The stauts code from the HTTP response
            content (string): The content from the HTTP response - may be None
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that we have a status_code
        validate_is_type(int, not_empty=False, status_code=status_code)
        self.status_code = status_code

        # Check that content looks right
        if content:
            validate_is_string(content=content)
        self.content = content
    def __init__(self, notification, url, secret):
        """
        Args:
            notification (Notification): The Notification to send.
            url (string): The URL to send the notification payload to.
            secret (string): The secret to calculate the payload checksum with.
        """
        super(WebhookRequest, self).__init__(notification)

        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that we have a url
        validate_is_string(url=url)
        self.url = url

        # Check that we have a secret
        validate_is_type(basestring, not_empty=False, secret=secret)
        self.secret = secret
Ejemplo n.º 14
0
    def __init__(self, notification, url, secret):
        """
        Args:
            notification (Notification): The Notification to send.
            url (string): The URL to send the notification payload to.
            secret (string): The secret to calculate the payload checksum with.
        """
        super(WebhookRequest, self).__init__(notification)

        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that we have a url
        validate_is_string(url=url)
        self.url = url

        # Check that we have a secret
        validate_is_type(basestring, not_empty=False, secret=secret)
        self.secret = secret
Ejemplo n.º 15
0
    def __init__(self, collapse_key=None, priority=None):
        """
        Args:
            collapse_key (string): Collapse key for push notification - may be None.
            priority (int): Priority for push notification - may be None.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that our collapse key looks right
        if collapse_key:
            validate_is_string(collapse_key=collapse_key)
        self.collapse_key = collapse_key

        # Check that our priority looks right
        if priority:
            validate_is_type(int, not_empty=False, priority=priority)
            PlatformPriority.validate(priority)
        self.priority = priority
Ejemplo n.º 16
0
    def __init__(self, collapse_key=None, priority=None):
        """
        Args:
            collapse_key (string): Collapse key for push notification - may be None.
            priority (int): Priority for push notification - may be None.
        """
        from tbans.utils.validation_utils import validate_is_string, validate_is_type

        # Check that our collapse key looks right
        if collapse_key:
            validate_is_string(collapse_key=collapse_key)
        self.collapse_key = collapse_key

        # Check that our priority looks right
        if priority:
            validate_is_type(int, not_empty=False, priority=priority)
            PlatformPriority.validate(priority)
        self.priority = priority
Ejemplo n.º 17
0
    def __init__(self, tokens, response=None, error=None):
        """
        Error JSON from FCM will look like...
        {"error":"MissingAuthorization"}

        Success JSON from FCM will look like...
        {
          "results":[...]
        }

        We can mix/match error and success, such as...
        {
          "results":[
            {},
            {"error":"NOT_FOUND"},
            {},
          ]
        }

        Note: These come back in a particular order, so we'll need to match up the results with the sent tokens + errors

        https://github.com/firebase/firebase-admin-python/blob/47345a1ecaf51611c07a7414d7e8afe50ea9decc/firebase_admin/messaging.py#L323

        Args:
            tokens (list, string): A non-empty list of device registration tokens.
        """
        super(SubscriptionBatchResponse, self).__init__(response=response, error=error)

        from tbans.utils.validation_utils import validate_is_type

        # Ensure our tokens are right - non-empty strings, in a list
        validate_is_type(list, tokens=tokens)
        invalid_str = [t for t in tokens if not isinstance(t, basestring) or not t]
        if invalid_str:
            raise ValueError('SubscriptionBatchResponse tokens must be non-empty strings.')

        results = self.data.get('results', [])
        if not isinstance(results, list) or (not results and not self.error):
            raise ValueError('SubscriptionBatchResponse results must be a non-empty list.')

        from tbans.models.subscriptions.subscriber import Subscriber
        self.subscribers = [Subscriber(token, result) for token, result in zip(tokens, results)]