From 0fc46975cf5ec8e7decc5b1887a0a17f392e95f0 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Thu, 7 Mar 2024 09:09:48 +0100 Subject: [PATCH] Add support for Status and Type fields in app context --- .../objects_v2/channel/get_all_channels.py | 5 +- .../objects_v2/channel/get_channel.py | 7 +-- .../objects_v2/channel/set_channel.py | 17 ++++++- .../endpoints/objects_v2/objects_endpoint.py | 46 +++++++++++++++++++ .../endpoints/objects_v2/uuid/get_all_uuid.py | 5 +- pubnub/endpoints/objects_v2/uuid/get_uuid.py | 5 +- pubnub/endpoints/objects_v2/uuid/set_uuid.py | 8 +++- 7 files changed, 80 insertions(+), 13 deletions(-) diff --git a/pubnub/endpoints/objects_v2/channel/get_all_channels.py b/pubnub/endpoints/objects_v2/channel/get_all_channels.py index 8e7e8815..6b6e732d 100644 --- a/pubnub/endpoints/objects_v2/channel/get_all_channels.py +++ b/pubnub/endpoints/objects_v2/channel/get_all_channels.py @@ -1,17 +1,18 @@ from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \ - IncludeCustomEndpoint + IncludeCustomEndpoint, IncludeStatusTypeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.channel import PNGetAllChannelMetadataResult -class GetAllChannels(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint): +class GetAllChannels(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeStatusTypeEndpoint): GET_ALL_CHANNELS_PATH = "/v2/objects/%s/channels" def __init__(self, pubnub): ObjectsEndpoint.__init__(self, pubnub) ListEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) def build_path(self): return GetAllChannels.GET_ALL_CHANNELS_PATH % self.pubnub.config.subscribe_key diff --git a/pubnub/endpoints/objects_v2/channel/get_channel.py b/pubnub/endpoints/objects_v2/channel/get_channel.py index b507be35..58cc7064 100644 --- a/pubnub/endpoints/objects_v2/channel/get_channel.py +++ b/pubnub/endpoints/objects_v2/channel/get_channel.py @@ -1,17 +1,18 @@ -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - ChannelEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, ChannelEndpoint, \ + IncludeStatusTypeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.channel import PNGetChannelMetadataResult -class GetChannel(ObjectsEndpoint, ChannelEndpoint, IncludeCustomEndpoint): +class GetChannel(ObjectsEndpoint, ChannelEndpoint, IncludeCustomEndpoint, IncludeStatusTypeEndpoint): GET_CHANNEL_PATH = "/v2/objects/%s/channels/%s" def __init__(self, pubnub): ObjectsEndpoint.__init__(self, pubnub) ChannelEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) def build_path(self): return GetChannel.GET_CHANNEL_PATH % (self.pubnub.config.subscribe_key, self._channel) diff --git a/pubnub/endpoints/objects_v2/channel/set_channel.py b/pubnub/endpoints/objects_v2/channel/set_channel.py index 32d4d7a1..778dad7c 100644 --- a/pubnub/endpoints/objects_v2/channel/set_channel.py +++ b/pubnub/endpoints/objects_v2/channel/set_channel.py @@ -1,12 +1,13 @@ from pubnub import utils from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - ChannelEndpoint, CustomAwareEndpoint + ChannelEndpoint, CustomAwareEndpoint, IncludeStatusTypeEndpoint, StatusTypeAwareEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.channel import PNSetChannelMetadataResult -class SetChannel(ObjectsEndpoint, ChannelEndpoint, IncludeCustomEndpoint, CustomAwareEndpoint): +class SetChannel(ObjectsEndpoint, ChannelEndpoint, IncludeCustomEndpoint, CustomAwareEndpoint, + IncludeStatusTypeEndpoint, StatusTypeAwareEndpoint): SET_CHANNEL_PATH = "/v2/objects/%s/channels/%s" def __init__(self, pubnub): @@ -14,14 +15,25 @@ def __init__(self, pubnub): ChannelEndpoint.__init__(self) CustomAwareEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) self._name = None self._description = None + self._status = None + self._type = None def set_name(self, name): self._name = str(name) return self + def set_status(self, status: str = None): + self._status = status + return self + + def set_type(self, type: str = None): + self._type = type + return self + def description(self, description): self._description = str(description) return self @@ -38,6 +50,7 @@ def build_data(self): "description": self._description, "custom": self._custom } + payload = StatusTypeAwareEndpoint.build_data(self, payload) return utils.write_value_as_string(payload) def create_response(self, envelope): diff --git a/pubnub/endpoints/objects_v2/objects_endpoint.py b/pubnub/endpoints/objects_v2/objects_endpoint.py index d6a5675f..3ee6b88a 100644 --- a/pubnub/endpoints/objects_v2/objects_endpoint.py +++ b/pubnub/endpoints/objects_v2/objects_endpoint.py @@ -47,6 +47,12 @@ def custom_params(self): if self._include_custom: inclusions.append("custom") + if isinstance(self, IncludeStatusTypeEndpoint): + if self._include_status: + inclusions.append("status") + if self._include_type: + inclusions.append("type") + if isinstance(self, UUIDIncludeEndpoint): if self._uuid_details_level: if self._uuid_details_level == UUIDIncludeEndpoint.UUID: @@ -100,8 +106,32 @@ def __init__(self): def custom(self, custom): self._custom = dict(custom) + self._include_custom = True + return self + + +class StatusTypeAwareEndpoint: + __metaclass__ = ABCMeta + + def __init__(self): + self._status = None + self._type = None + + def set_status(self, status: str): + self._status = status + return self + + def set_type(self, type): + self._type = type return self + def build_data(self, payload): + if self._status: + payload["status"] = self._status + if self._type: + payload["type"] = self._type + return payload + class ChannelEndpoint: __metaclass__ = ABCMeta @@ -181,6 +211,22 @@ def include_custom(self, include_custom): return self +class IncludeStatusTypeEndpoint: + __metaclass__ = ABCMeta + + def __init__(self): + self._include_status = True + self._include_type = True + + def include_status(self, include_status): + self._include_status = bool(include_status) + return self + + def include_type(self, include_type): + self._include_type = bool(include_type) + return self + + class UUIDIncludeEndpoint: __metaclass__ = ABCMeta diff --git a/pubnub/endpoints/objects_v2/uuid/get_all_uuid.py b/pubnub/endpoints/objects_v2/uuid/get_all_uuid.py index b439b1f0..9e57b969 100644 --- a/pubnub/endpoints/objects_v2/uuid/get_all_uuid.py +++ b/pubnub/endpoints/objects_v2/uuid/get_all_uuid.py @@ -1,17 +1,18 @@ from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \ - IncludeCustomEndpoint + IncludeCustomEndpoint, IncludeStatusTypeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.uuid import PNGetAllUUIDMetadataResult -class GetAllUuid(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint): +class GetAllUuid(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeStatusTypeEndpoint): GET_ALL_UID_PATH = "/v2/objects/%s/uuids" def __init__(self, pubnub): ObjectsEndpoint.__init__(self, pubnub) ListEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) def build_path(self): return GetAllUuid.GET_ALL_UID_PATH % self.pubnub.config.subscribe_key diff --git a/pubnub/endpoints/objects_v2/uuid/get_uuid.py b/pubnub/endpoints/objects_v2/uuid/get_uuid.py index 8fc10cef..9dd0ada7 100644 --- a/pubnub/endpoints/objects_v2/uuid/get_uuid.py +++ b/pubnub/endpoints/objects_v2/uuid/get_uuid.py @@ -1,17 +1,18 @@ from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, \ - IncludeCustomEndpoint, UuidEndpoint + IncludeCustomEndpoint, UuidEndpoint, IncludeStatusTypeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.uuid import PNGetUUIDMetadataResult -class GetUuid(ObjectsEndpoint, UuidEndpoint, IncludeCustomEndpoint): +class GetUuid(ObjectsEndpoint, UuidEndpoint, IncludeCustomEndpoint, IncludeStatusTypeEndpoint): GET_UID_PATH = "/v2/objects/%s/uuids/%s" def __init__(self, pubnub): ObjectsEndpoint.__init__(self, pubnub) UuidEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) def build_path(self): return GetUuid.GET_UID_PATH % (self.pubnub.config.subscribe_key, self._effective_uuid()) diff --git a/pubnub/endpoints/objects_v2/uuid/set_uuid.py b/pubnub/endpoints/objects_v2/uuid/set_uuid.py index bd23ef00..c980e807 100644 --- a/pubnub/endpoints/objects_v2/uuid/set_uuid.py +++ b/pubnub/endpoints/objects_v2/uuid/set_uuid.py @@ -1,12 +1,13 @@ from pubnub import utils from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, UuidEndpoint, \ - IncludeCustomEndpoint, CustomAwareEndpoint + IncludeCustomEndpoint, CustomAwareEndpoint, IncludeStatusTypeEndpoint, StatusTypeAwareEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.objects_v2.uuid import PNSetUUIDMetadataResult -class SetUuid(ObjectsEndpoint, UuidEndpoint, IncludeCustomEndpoint, CustomAwareEndpoint): +class SetUuid(ObjectsEndpoint, UuidEndpoint, IncludeCustomEndpoint, CustomAwareEndpoint, IncludeStatusTypeEndpoint, + StatusTypeAwareEndpoint): SET_UID_PATH = "/v2/objects/%s/uuids/%s" def __init__(self, pubnub): @@ -14,6 +15,8 @@ def __init__(self, pubnub): UuidEndpoint.__init__(self) IncludeCustomEndpoint.__init__(self) CustomAwareEndpoint.__init__(self) + IncludeStatusTypeEndpoint.__init__(self) + StatusTypeAwareEndpoint.__init__(self) self._name = None self._email = None @@ -47,6 +50,7 @@ def build_data(self): "profileUrl": self._profile_url, "custom": self._custom } + payload = StatusTypeAwareEndpoint.build_data(self, payload) return utils.write_value_as_string(payload) def validate_specific_params(self):