コード例 #1
0
    def trigger_batch(self, batch=[], already_encoded=False):
        """Trigger multiple events with a single HTTP call.

        http://pusher.com/docs/rest_api#method-post-batch-events
        """
        if not already_encoded:
            for event in batch:

                validate_channel(event['channel'])

                event_name = ensure_text(event['name'], "event_name")
                if len(event['name']) > 200:
                    raise ValueError("event_name too long")

                event['data'] = data_to_string(event['data'], self._json_encoder)

                if len(event['data']) > 10240:
                    raise ValueError("Too much data")

                if is_encrypted_channel(event['channel']):
                    event['data'] = json.dumps(encrypt(event['channel'], event['data'], self._encryption_master_key), ensure_ascii=False)

        params = {
            'batch': batch}

        return Request(
            self, POST, "/apps/%s/batch_events" % self.app_id, params)
コード例 #2
0
ファイル: pusher.py プロジェクト: rcrdclub/pusher-http-python
    def users_info(self, channel):
        '''
        Fetch user ids currently subscribed to a presence channel

        http://pusher.com/docs/rest_api#method-get-users
        '''
        validate_channel(channel)

        return Request(self, GET, "/apps/%s/channels/%s/users" % (self.app_id, channel))
コード例 #3
0
    def users_info(self, channel):
        '''
        Fetch user ids currently subscribed to a presence channel

        http://pusher.com/docs/rest_api#method-get-users
        '''
        validate_channel(channel)

        return Request(self, GET,
                       "/apps/%s/channels/%s/users" % (self.app_id, channel))
コード例 #4
0
ファイル: pusher.py プロジェクト: rcrdclub/pusher-http-python
    def channel_info(self, channel, attributes=[]):
        '''
        Get information on a specific channel, see:

        http://pusher.com/docs/rest_api#method-get-channel
        '''
        validate_channel(channel)

        params = {}
        if attributes:
            params['info'] = join_attributes(attributes)
        return Request(self, GET, "/apps/%s/channels/%s" % (self.app_id, channel), params)
コード例 #5
0
    def channel_info(self, channel, attributes=[]):
        """Get information on a specific channel, see:

        http://pusher.com/docs/rest_api#method-get-channel
        """
        validate_channel(channel)

        params = {}
        if attributes:
            params['info'] = join_attributes(attributes)

        return Request(self, GET,
                       "/apps/%s/channels/%s" % (self.app_id, channel), params)
コード例 #6
0
ファイル: pusher.py プロジェクト: rcrdclub/pusher-http-python
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' % channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        result = {'auth': auth}

        if custom_data:
            result['channel_data'] = custom_data

        return result
コード例 #7
0
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' %
                             channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        result = {'auth': auth}

        if custom_data:
            result['channel_data'] = custom_data

        return result
コード例 #8
0
    def trigger(self, channels, event_name, data, socket_id=None):
        '''
        Trigger an event on one or more channels, see:

        http://pusher.com/docs/rest_api#method-post-event
        '''
        if isinstance(channels, six.string_types) or not isinstance(
                channels, (collections.Sized, collections.Iterable)):
            raise TypeError(
                "Expected a collection of channels (each channel should be %s)"
                % text)

        if len(channels) > 10:
            raise ValueError("Too many channels")

        for channel in channels:
            validate_channel(channel)

        if not isinstance(event_name, six.text_type):
            raise TypeError("event_name should be %s" % text)

        if len(event_name) > 200:
            raise ValueError("event_name too long")

        if not isinstance(data, six.text_type):
            data = json.dumps(data)

        if len(data) > 10240:
            raise ValueError("Too much data")

        params = {'name': event_name, 'channels': channels, 'data': data}
        if socket_id:
            if not isinstance(socket_id, six.text_type):
                raise TypeError("Socket ID should be %s" % text)
            params['socket_id'] = socket_id
        return Request(self.config, POST,
                       "/apps/%s/events" % self.config.app_id, params)
コード例 #9
0
ファイル: pusher.py プロジェクト: knowsis/pusher-rest-python
    def trigger(self, channels, event_name, data, socket_id=None):
        '''
        Trigger an event on one or more channels, see:

        http://pusher.com/docs/rest_api#method-post-event
        '''
        if isinstance(channels, six.string_types) or not isinstance(channels, (collections.Sized, collections.Iterable)):
            raise TypeError("Expected a collection of channels (each channel should be %s)" % text)

        if len(channels) > 10:
            raise ValueError("Too many channels")

        for channel in channels:
            validate_channel(channel)

        if not isinstance(event_name, six.text_type):
            raise TypeError("event_name should be %s" % text)

        if len(event_name) > 200:
            raise ValueError("event_name too long")

        if not isinstance(data, six.text_type):
            data = json.dumps(data)

        if len(data) > 10240:
            raise ValueError("Too much data")

        params = {
            'name': event_name,
            'channels': channels,
            'data': data
        }
        if socket_id:
            if not isinstance(socket_id, six.text_type):
                raise TypeError("Socket ID should be %s" % text)
            params['socket_id'] = socket_id
        return Request(self.config, POST, "/apps/%s/events" % self.config.app_id, params)
コード例 #10
0
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' %
                             channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        response_payload = {"auth": auth}

        if is_encrypted_channel(channel):
            shared_secret = generate_shared_secret(
                ensure_binary(channel, "channel"), self._encryption_master_key)
            shared_secret_b64 = base64.b64encode(shared_secret)
            response_payload["shared_secret"] = shared_secret_b64

        if custom_data:
            response_payload['channel_data'] = custom_data

        return response_payload