예제 #1
0
    def register(self, connection=None):

        response = connection.create_topic(self.full_name)
        if not response:
            raise SNSException(
                'Failed to register Topic. ({0})'.format(response))
        self.set_arn_from_response(response)
        self.save()
예제 #2
0
 def deregister(self, connection=None, save=True):
     if not self.is_registered:
         raise NotRegisteredException
     success = connection.unsubscribe(self.arn)
     if not success:
         raise SNSException(
             'Failed to unsubscribe Device from Topic.({0})'.format(
                 success))
     self.arn = None
     if save: self.save()
     return success
예제 #3
0
 def register(self, connection=None):
     self.device.is_registered_or_register()
     self.topic.is_registered_or_register()
     success = connection.subscribe(topic=self.topic.arn,
                                    endpoint=self.device.arn,
                                    protocol="application")
     if not success:
         raise SNSException(
             'Failed to subscribe device to topic.({0})'.format(success))
     self.set_arn_from_response(success)
     self.save()
예제 #4
0
    def deregister(self, connection=None, save=True):
        if not self.is_registered:
            raise NotRegisteredException
        success = connection.delete_topic(self.arn)
        if not success:
            raise SNSException(
                'Failed to deregister Topic. ({0})'.format(success))

        self.arn = None
        if save: self.save()

        return success
예제 #5
0
 def register(self, custom_user_data='', connection=None):
     '''
     :exception SNSException
     '''
     self.platform.is_registered_or_register()
     response = connection.create_platform_endpoint(
         self.platform.arn,
         self.push_token,
         custom_user_data=custom_user_data)
     success = self.set_arn_from_response(response)
     if not success:
         raise SNSException(
             'Failed to register Device.({0})'.format(success))
     self.save()
     return success
예제 #6
0
    def deregister(self, connection=None, save=True):
        """
        :type connection: SNSConnection
        :param connection: the connection which should be used.
        if the argument isn't set there will be created a default connection
        :return:
        """
        if not self.is_registered:
            raise NotRegisteredException

        success = connection.delete_platform_application(self.arn)
        if not success:
            SNSException(
                'Failded to deregister Platform.({0})'.format(success))
        self.arn = None
        if save: self.save()
        return success
예제 #7
0
    def register(self, connection=None):
        """
        Adds an app to SNS. Apps are per platform. The name of a
        sns application is app_platform.

        :type connection: SNSConnection
        :param connection: the connection which should be used.
        if the argument isn't set there will be created a default connection
        :rtype bool:
        :return:
        """

        response = connection.create_platform_application(
            self.name, self.platform, self.attributes)
        if not response:
            raise SNSException(
                'Failed to register Platform.{0}'.format(response))
        return self.set_arn_from_response(response)
예제 #8
0
 def deregister(self, connection=None, save=True):
     """
     Dergisters the device from SNS.
     :type connection: SNSConnection
     :param connection: the connection which should be used.
     if the argument isn't set there will be created a default connection
     :param save: weather the device should be saved, after the device has
     been deregsitered.
     :return:
     """
     if not self.is_registered:
         raise NotRegisteredException()
     success = connection.delete_endpoint(self.arn)
     if not success:
         SNSException('Failed to deregister device.({0})'.format(success))
     self.arn = None
     if save: self.save()
     return success