Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Support type and status fields in app context #182

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
seba-aln marked this conversation as resolved.
Show resolved Hide resolved
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
seba-aln marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "PATCH",
"uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/metadata_channel-two?include=custom%2Cstatus%2Ctype",
"body": "{\"name\": \"name\", \"description\": \"This is a description\", \"custom\": {\"foo\": \"bar\"}, \"status\": \"Testing\", \"type\": \"test\"}",
"headers": {
"User-Agent": [
"PubNub-Python/7.4.0"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
],
"Content-Length": [
"119"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Date": [
"Wed, 06 Mar 2024 20:43:38 GMT"
],
"Content-Length": [
"241"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Content-Type": [
"application/json"
],
"Connection": [
"keep-alive"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"body": {
"string": "{\"status\":200,\"data\":{\"id\":\"metadata_channel-two\",\"name\":\"name\",\"description\":\"This is a description\",\"type\":\"test\",\"status\":\"Testing\",\"custom\":{\"foo\":\"bar\"},\"updated\":\"2024-03-06T20:43:38.231243Z\",\"eTag\":\"f5046bfa9750b8b2cad4cd90ddacec76\"}}"
}
}
},
{
"request": {
"method": "GET",
"uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels?include=custom%2Cstatus%2Ctype",
"body": null,
"headers": {
"User-Agent": [
"PubNub-Python/7.4.0"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Date": [
"Wed, 06 Mar 2024 20:43:38 GMT"
],
"Content-Length": [
"471"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Content-Type": [
"application/json"
],
"Connection": [
"keep-alive"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"body": {
"string": "{\"status\":200,\"data\":[{\"id\":\"metadata_channel\",\"name\":\"name\",\"description\":\"This is a description\",\"type\":\"test\",\"status\":\"Testing\",\"custom\":{\"foo\":\"bar\"},\"updated\":\"2024-03-06T20:43:37.715484Z\",\"eTag\":\"d392f5ad1048cc8980f549c104b9b958\"},{\"id\":\"metadata_channel-two\",\"name\":\"name\",\"description\":\"This is a description\",\"type\":\"test\",\"status\":\"Testing\",\"custom\":{\"foo\":\"bar\"},\"updated\":\"2024-03-06T20:43:38.231243Z\",\"eTag\":\"f5046bfa9750b8b2cad4cd90ddacec76\"}],\"next\":\"Mg\"}"
}
}
}
]
}
Loading
Loading