def build_data(self): if self._use_post is True: cipher = self.pubnub.config.cipher_key if cipher is not None: return '"' + pn_crypto.encrypt(cipher, utils.write_value_as_string(self._message)) + '"' else: return utils.write_value_as_string(self._message) else: return None
def build_data(self): if self._use_post is True: cipher = self.pubnub.config.cipher_key if cipher is not None: return '"' + self.pubnub.config.crypto.encrypt(cipher, utils.write_value_as_string(self._message)) + '"' else: return utils.write_value_as_string(self._message) else: return None
def build_data(self): params = {'ttl': str(self._ttl)} permissions = {} resources = {} patterns = {} utils.parse_resources(self._channels, "channels", resources, patterns) utils.parse_resources(self._groups, "groups", resources, patterns) utils.parse_resources(self._users, "users", resources, patterns) utils.parse_resources(self._spaces, "spaces", resources, patterns) permissions['resources'] = resources permissions['patterns'] = patterns if self._meta is not None: if isinstance(self._meta, dict): permissions['meta'] = self._meta else: raise PubNubException(pn_error=PNERR_INVALID_META) else: permissions['meta'] = {} params['permissions'] = permissions return utils.write_value_as_string(params)
def build_data(self): payload = { "name": self._name, "description": self._description, "custom": self._custom } return utils.write_value_as_string(payload)
def build_data(self): params = { 'type': self._message_action.type, 'value': self._message_action.value } return utils.write_value_as_string(params)
def _encrypt_message(self, message): if self._cipher_key or self._pubnub.config.cipher_key: return self._pubnub.config.crypto.encrypt( self._cipher_key or self._pubnub.config.cipher_key, utils.write_value_as_string(message)) else: return message
def build_data(self): uuids_to_delete = [] for uuid in self._uuids: uuids_to_delete.append(uuid.to_payload_dict()) payload = {"set": [], "delete": uuids_to_delete} return utils.write_value_as_string(payload)
def build_data(self): channel_memberships_to_set = [] for channel_membership in self._channel_memberships: channel_memberships_to_set.append( channel_membership.to_payload_dict()) payload = {"set": channel_memberships_to_set, "delete": []} return utils.write_value_as_string(payload)
def custom_params(self): params = {} if self._meta is not None: params['meta'] = utils.write_value_as_string(self._meta) params["store"] = "0" params["norep"] = "1" if self.pubnub.config.auth_key is not None: params["auth"] = utils.url_encode(self.pubnub.config.auth_key) return params
def build_data(self): payload = { "name": self._name, "email": self._email, "externalId": self._external_id, "profileUrl": self._profile_url, "custom": self._custom } return utils.write_value_as_string(payload)
def custom_params(self): params = {'heartbeat': str(self.pubnub.config.presence_timeout)} if len(self._groups) > 0: params['channel-group'] = utils.join_items(self._groups) if self._state is not None and len(self._state) > 0: params['state'] = utils.write_value_as_string(self._state) return params
def custom_params(self): if self._subscription_manager is not None: self._subscription_manager.adapt_state_builder( StateOperation(channels=self._channels, channel_groups=self._groups, state=self._state)) params = {'state': utils.write_value_as_string(self._state)} if len(self._groups) > 0: params['channel-group'] = utils.join_items_and_encode(self._groups) return params
def custom_params(self): if self._subscription_manager is not None: self._subscription_manager.adapt_state_builder(StateOperation( channels=self._channels, channel_groups=self._groups, state=self._state )) params = {'state': utils.write_value_as_string(self._state)} if len(self._groups) > 0: params['channel-group'] = utils.join_items_and_encode(self._groups) return params
def build_data(self): uuids_to_set = [] uuids_to_remove = [] for uuid in self._uuids_to_set: uuids_to_set.append(uuid.to_payload_dict()) for uuid in self._uuids_to_remove: uuids_to_remove.append(uuid.to_payload_dict()) payload = { "set": uuids_to_set, "delete": uuids_to_remove } return utils.write_value_as_string(payload)
def build_path(self): if self._use_post: return Publish.PUBLISH_POST_PATH % (self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, utils.url_encode(self._channel), 0) else: cipher = self.pubnub.config.cipher_key stringified_message = utils.write_value_as_string(self._message) if cipher is not None: stringified_message = '"' + self.pubnub.config.crypto.encrypt(cipher, stringified_message) + '"' stringified_message = utils.url_encode(stringified_message) return Publish.PUBLISH_GET_PATH % (self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, utils.url_encode(self._channel), 0, stringified_message)
def build_path(self): if self._use_post: return Publish.PUBLISH_POST_PATH % (self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, self._channel, 0) else: cipher = self.pubnub.config.cipher_key stringified_message = utils.write_value_as_string(self._message) if cipher is not None: stringified_message = '"' + pn_crypto.encrypt(cipher, stringified_message) + '"' stringified_message = utils.url_encode(stringified_message) return Publish.PUBLISH_GET_PATH % (self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, self._channel, 0, stringified_message)
def custom_params(self): params = {} if self._meta is not None: params['meta'] = utils.write_value_as_string(self._meta) if self._should_store is not None: if self._should_store: params["store"] = "1" else: params["store"] = "0" # REVIEW: should auth key be assigned here? if self.pubnub.config.auth_key is not None: params["auth"] = utils.url_encode(self.pubnub.config.auth_key) return params
def custom_params(self): params = {} if self._meta is not None: params['meta'] = utils.write_value_as_string(self._meta) if self._should_store is not None: if self._should_store: params["store"] = "1" else: params["store"] = "0" if self._replicate is not None: if self._replicate: params["replicate"] = "1" else: params["replicate"] = "0" # REVIEW: should auth key be assigned here? if self.pubnub.config.auth_key is not None: params["auth"] = utils.url_encode(self.pubnub.config.auth_key) return params
def test_bool(self): assert utils.write_value_as_string(False) == "false" assert utils.write_value_as_string(True) == "true"
def build_data(self): params = {"name": self._file_name} return utils.write_value_as_string(params)
def build_data(self): if self._data is not None: return utils.write_value_as_string(self._data)
def test_list(self): assert utils.write_value_as_string(["ch1", "ch2"]) == "[\"ch1\", \"ch2\"]"
def test_tuple(self): assert utils.write_value_as_string( ("ch1", "ch2")) == "[\"ch1\", \"ch2\"]"
def test_string(self): assert utils.write_value_as_string("blah") == "\"blah\"" assert utils.write_value_as_string(u"blah") == "\"blah\""
def url_encode(data): return utils.url_encode(utils.write_value_as_string(data))
def build_path(self): stringified_message = utils.write_value_as_string(self._message) msg = utils.url_encode(stringified_message) return Signal.SIGNAL_PATH % (self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, utils.url_encode(self._channel), msg)
def test_tuple(self): assert utils.write_value_as_string(("ch1", "ch2")) == "[\"ch1\", \"ch2\"]"
def build_data(self): return utils.write_value_as_string(self._data)