Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
    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)
Пример #4
0
 def build_data(self):
     payload = {
         "name": self._name,
         "description": self._description,
         "custom": self._custom
     }
     return utils.write_value_as_string(payload)
Пример #5
0
    def build_data(self):
        params = {
            'type': self._message_action.type,
            'value': self._message_action.value
        }

        return utils.write_value_as_string(params)
Пример #6
0
 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)
Пример #8
0
    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)
Пример #9
0
 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
Пример #10
0
 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)
Пример #11
0
    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
Пример #12
0
    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
Пример #13
0
    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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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
Пример #18
0
    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
Пример #19
0
 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)
Пример #22
0
 def test_list(self):
     assert utils.write_value_as_string(["ch1",
                                         "ch2"]) == "[\"ch1\", \"ch2\"]"
Пример #23
0
 def test_tuple(self):
     assert utils.write_value_as_string(
         ("ch1", "ch2")) == "[\"ch1\", \"ch2\"]"
Пример #24
0
 def test_string(self):
     assert utils.write_value_as_string("blah") == "\"blah\""
     assert utils.write_value_as_string(u"blah") == "\"blah\""
Пример #25
0
 def test_bool(self):
     assert utils.write_value_as_string(False) == "false"
     assert utils.write_value_as_string(True) == "true"
Пример #26
0
def url_encode(data):
    return utils.url_encode(utils.write_value_as_string(data))
Пример #27
0
 def test_string(self):
     assert utils.write_value_as_string("blah") == "\"blah\""
     assert utils.write_value_as_string(u"blah") == "\"blah\""
 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)
Пример #29
0
 def test_tuple(self):
     assert utils.write_value_as_string(("ch1", "ch2")) == "[\"ch1\", \"ch2\"]"
Пример #30
0
def url_encode(data):
    return utils.url_encode(utils.write_value_as_string(data))
 def build_data(self):
     return utils.write_value_as_string(self._data)
Пример #32
0
 def test_list(self):
     assert utils.write_value_as_string(["ch1", "ch2"]) == "[\"ch1\", \"ch2\"]"