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)
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): channels = [channels] if isinstance(channels, dict) or not isinstance( channels, (collections.Sized, collections.Iterable)): raise TypeError("Expected a single or a list of channels") if len(channels) > 10: raise ValueError("Too many channels") channels = list(map(validate_channel, channels)) event_name = ensure_text(event_name, "event_name") if len(event_name) > 200: raise ValueError("event_name too long") data = data_to_string(data, self._json_encoder) if len(data) > 10240: raise ValueError("Too much data") params = {'name': event_name, 'channels': channels, 'data': data} if socket_id: params['socket_id'] = validate_socket_id(socket_id) return Request(self, POST, "/apps/%s/events" % self.app_id, params)
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)
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: event['data'] = data_to_string(event['data'], self._json_encoder) params = {'batch': batch} return Request(self, POST, "/apps/%s/batch_events" % self.app_id, params)
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): channels = [channels] if isinstance(channels, dict) or not isinstance( channels, (collections.Sized, collections.Iterable)): raise TypeError("Expected a single or a list of channels") if len(channels) > self.max_num_channels: raise ValueError("Too many channels") event_name = ensure_text(event_name, "event_name") if len(event_name) > self.max_len_event_name: raise ValueError("event_name too long") data = data_to_string(data, self._json_encoder) if len(data) > self.max_len_data: raise ValueError("Too much data") channels = list(map(validate_channel, channels)) if len(channels) > 1: for chan in channels: if is_encrypted_channel(chan): raise ValueError( "You cannot trigger to multiple channels when using encrypted channels" ) if is_encrypted_channel(channels[0]): data = json.dumps(encrypt(channels[0], data, self._encryption_master_key), ensure_ascii=False) params = {'name': event_name, 'channels': channels, 'data': data} if socket_id: params['socket_id'] = validate_socket_id(socket_id) return Request(self, POST, "/apps/%s/events" % self.app_id, params)
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): channels = [channels] if isinstance(channels, dict) or not isinstance( channels, (collections.Sized, collections.Iterable)): raise TypeError("Expected a single or a list of channels") if len(channels) > 100: raise ValueError("Too many channels") event_name = ensure_text(event_name, "event_name") if len(event_name) > 200: raise ValueError("event_name too long") data = data_to_string(data, self._json_encoder) if len(data) > 10240: raise ValueError("Too much data") channels = list(map(validate_channel, channels)) if len(channels) > 1: for chan in channels: if is_encrypted_channel(chan): raise ValueError("You cannot trigger to multiple channels when using encrypted channels") if is_encrypted_channel(channels[0]): data = json.dumps(encrypt(channels[0], data, self._encryption_master_key), ensure_ascii=False) params = { 'name': event_name, 'channels': channels, 'data': data} if socket_id: params['socket_id'] = validate_socket_id(socket_id) return Request(self, POST, "/apps/%s/events" % self.app_id, params)