Skip to content

Commit

Permalink
Add support for Status and Type fields in app context
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Mar 7, 2024
1 parent 4c03ecd commit 0fc4697
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 13 deletions.
5 changes: 3 additions & 2 deletions pubnub/endpoints/objects_v2/channel/get_all_channels.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions pubnub/endpoints/objects_v2/channel/get_channel.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
17 changes: 15 additions & 2 deletions pubnub/endpoints/objects_v2/channel/set_channel.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
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):
ObjectsEndpoint.__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
Expand All @@ -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):
Expand Down
46 changes: 46 additions & 0 deletions pubnub/endpoints/objects_v2/objects_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions pubnub/endpoints/objects_v2/uuid/get_all_uuid.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions pubnub/endpoints/objects_v2/uuid/get_uuid.py
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
8 changes: 6 additions & 2 deletions pubnub/endpoints/objects_v2/uuid/set_uuid.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
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):
ObjectsEndpoint.__init__(self, pubnub)
UuidEndpoint.__init__(self)
IncludeCustomEndpoint.__init__(self)
CustomAwareEndpoint.__init__(self)
IncludeStatusTypeEndpoint.__init__(self)
StatusTypeAwareEndpoint.__init__(self)

self._name = None
self._email = None
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0fc4697

Please sign in to comment.