Beispiel #1
0
    def push(self,
             token,
             alert=None,
             badge=None,
             sound=None,
             expiry=None,
             extra=None,
             timestamp=None):
        '''
        This is really the only api you want to use. Pushes a notification onto the queue
        for non-flagged users. The queue is processed in the tornado event loop.
        '''
        flagged = mc.get(token)
        if flagged:
            if not timestamp or timestamp > flagged:
                self.stats['invalid_tokens'] += 1
                return False

        self.generation.value += 1
        identifier = self.generation.value
        msg = create_message(token,
                             alert=alert,
                             badge=badge,
                             sound=sound,
                             identifier=identifier,
                             expiry=expiry,
                             extra=extra)
        if len(msg) > MAX_PAYLOAD_BYTES:
            raise ValueError, u"max payload(%d) exceeded: %d" % (
                MAX_PAYLOAD_BYTES, len(msg))

        self.write_queue.append(msg)
        self.recent.append(dict(identifier=identifier, token=token))
        self.ioloop.add_callback(self.push_one)
        return True
Beispiel #2
0
    def push(self, registration_id, collapse_key, delay_while_idle=None, extra={}):
        flagged = mc.get(registration_id)
        if flagged:
            self.stats['invalid_registration'] += 1
            return False

        data = {'registration_id': registration_id, 'collapse_key': collapse_key}
        for k, v in extra.items():
            data['data.'+k] = v
        if delay_while_idle:
            data['delay_while_idle'] = ""
        data = urllib.urlencode(data, doseq=1)
        if len(data) > MAX_PAYLOAD_BYTES:
            raise ValueError, u"max payload(%d) exceeded: %d" % (MAX_PAYLOAD_BYTES, len(data))
        self.send(dict(registration_id=registration_id, payload=data))
        return True
Beispiel #3
0
    def push(self, token, alert=None, badge=None, sound=None, expiry=None, extra=None, timestamp=None):
        '''
        This is really the only api you want to use. Pushes a notification onto the queue
        for non-flagged users. The queue is processed in the tornado event loop.
        '''
        flagged = mc.get(token)
        if flagged:
            if not timestamp or timestamp > flagged:
                self.stats['invalid_tokens'] += 1
                return False

        self.generation.value += 1
        identifier = self.generation.value
        msg = create_message(token, alert=alert, badge=badge, sound=sound,
            identifier=identifier, expiry=expiry, extra=extra)
        if len(msg) > MAX_PAYLOAD_BYTES:
            raise ValueError, u"max payload(%d) exceeded: %d" % (MAX_PAYLOAD_BYTES, len(msg))

        self.write_queue.append(msg)
        self.recent.append(dict(identifier=identifier, token=token))
        self.ioloop.add_callback(self.push_one)
        return True