def build(self):
        """
        Build all notifications items to one string.
        """
        keys = []
        apsKeys = []
        if self.soundValue:
            apsKeys.append('"sound":"%s"' % _doublequote(self.soundValue))

        if self.badgeValue:
            apsKeys.append('"badge":%d' % int(self.badgeValue))

        if self.alertObject != None:
            alertArgument = ""
            if isinstance(self.alertObject, str):
                alertArgument = _doublequote(self.alertObject)
                apsKeys.append('"alert":"%s"' % alertArgument)
            elif isinstance(self.alertObject, APNSAlert):
                alertArgument = self.alertObject.build()
                apsKeys.append('"alert":{%s}' % alertArgument)

        keys.append('"aps":{%s}' % ",".join(apsKeys))

        # prepare properties
        for property in self.properties:
            keys.append(property.build())

        payload = "{%s}" % ",".join(keys)

        if len(payload) > self.maxPayloadLength:
            raise APNSPayloadLengthError("Length of Payload more "\
                                    "than %d bytes." % self.maxPayloadLength)

        return payload
Exemple #2
0
    def build(self):
        """
        Build all notifications items to one string.
        """
        keys = []
        apsKeys = []
        if self.soundValue:
            apsKeys.append('"sound":"%s"' % _doublequote(self.soundValue))

        if self.badgeValue:
            apsKeys.append('"badge":%d' % int(self.badgeValue))

        if self.alertObject != None:
            alertArgument = ""
            if isinstance(self.alertObject, str):
                alertArgument = _doublequote(self.alertObject)
                apsKeys.append('"alert":"%s"' % alertArgument)
            elif isinstance(self.alertObject, APNSAlert):
                alertArgument = self.alertObject.build()
                apsKeys.append('"alert":{%s}' % alertArgument)

        keys.append('"aps":{%s}' % ",".join(apsKeys))

        # prepare properties
        for property in self.properties:
            keys.append(property.build())

        payload = "{%s}" % ",".join(keys)

        if len(payload) > self.maxPayloadLength:
            raise APNSPayloadLengthError("Length of Payload more "\
                                    "than %d bytes." % self.maxPayloadLength)

        return payload
    def _build(self):
        arguments = []
        name = '"%s":' % self.name

        if isinstance(self.data, (int, float)):
            return "%s%s" % (name, str(self.data))

        if isinstance(self.data, str) or isinstance(self.data, unicode):
            return '%s"%s"' % (name, _doublequote(self.data))

        if isinstance(self.data, (tuple, list)):
            arguments = map(lambda x: if_else(isinstance(x, str), '"%s"' % _doublequote(str(x)), str(x)), self.data)
            return "%s[%s]" % (name, ",".join(arguments))

        return '%s%s' % (name, NULL)
Exemple #4
0
 def _build(self):        
     arguments = []
     name = '"%s":' % self.name
     
     if isinstance(self.data, (int, float)):
         return "%s%s" % (name, str(self.data))
         
     if isinstance(self.data, str):
         return '%s"%s"' % (name, _doublequote(self.data))
     
     if isinstance(self.data, (tuple, list)):
         arguments = map(lambda x: if_else(isinstance(x, str), '"%s"' % _doublequote(str(x)), str(x)), self.data)
         return "%s[%s]" % (name, ",".join(arguments))
         
     return '%s%s' % (name, NULL)
Exemple #5
0
    def build(self):
        """Build property for payload"""
        arguments = []
        name = '"%s":' % self.name

        if isinstance(self.data, (int, float)):
            return "%s%s" % (name, str(self.data))

        if isinstance(self.data, str) or isinstance(self.data, unicode):
            return '%s"%s"' % (name, _doublequote(self.data))

        if isinstance(self.data, (tuple, list)):
            arguments = map(lambda x: if_else(isinstance(x, str), \
                            '"%s"' % _doublequote(str(x)), str(x)), self.data)
            return "%s[%s]" % (name, ",".join(arguments))

        return '%s%s' % (name, NULL)
    def _build(self):
        """
        Build object to JSON Apple Push Notification Service string.
        """

        arguments = []
        if self.alertBody:
            arguments.append('"body":"%s"' % _doublequote(self.alertBody))

        if self.actionLocKey:
            arguments.append('"action-loc-key":"%s"' % _doublequote(self.actionLocKey))

        if self.locKey:
            arguments.append('"loc-key":"%s"' % _doublequote(self.locKey))

        if self.locArgs:
            arguments.append('"loc-args":[%s]' % ",".join(self.locArgs))

        return ",".join(arguments)
Exemple #7
0
    def _build(self):
        """
        Build object to JSON Apple Push Notification Service string.
        """
        
        arguments = []
        if self.alertBody:
            arguments.append('"body":"%s"' % _doublequote(self.alertBody))

        if self.actionLocKey:
            arguments.append('"action-loc-key":"%s"' % _doublequote(self.actionLocKey))

        if self.locKey:
            arguments.append('"loc-key":"%s"' % _doublequote(self.locKey))

        if self.locArgs:
            arguments.append('"loc-args":[%s]' % ",".join(self.locArgs))    
        
        return ",".join(arguments)
    def build(self):
        """Build property for payload"""
        arguments = []
        name = '"%s":' % self.name

        if isinstance(self.data, (int, float)):
            return "%s%s" % (name, str(self.data))

        if isinstance(self.data, str) or isinstance(self.data, unicode):
            return '%s"%s"' % (name, _doublequote(self.data))


        if isinstance(self.data, (tuple, list)):
            arguments = map(lambda x: if_else(isinstance(x, str), \
                            '"%s"'.encode('utf8') % _doublequote(unicode(x).encode('utf8')), unicode(x).encode('utf8')), self.data)
            return "%s[%s]" % (name, ",".join(arguments))
        # if isinstance(self.data, (tuple, list)):
        #     arguments = map(lambda x: if_else(isinstance(x, str), \
        #                     '"%s"' % _doublequote(str(x)), str(x)), self.data)
        #     return "%s[%s]" % (name, ",".join(arguments))

        return '%s%s' % (name, NULL)