Skip to content

Commit

Permalink
Fix/Support type and status fields in app context (#182)
Browse files Browse the repository at this point in the history
* Add support for Status and Type fields in app context

* Add tests for metadata fields (app context)

* Update all tests VCRs to include status and type fields

* PubNub SDK v7.4.2 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
seba-aln and pubnub-release-bot authored Mar 7, 2024
1 parent 1c0378b commit 6bea25d
Show file tree
Hide file tree
Showing 58 changed files with 2,586 additions and 1,127 deletions.
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: python
version: 7.4.1
version: 7.4.2
schema: 1
scm: github.com/pubnub/python
sdks:
Expand All @@ -18,7 +18,7 @@ sdks:
distributions:
- distribution-type: library
distribution-repository: package
package-name: pubnub-7.4.1
package-name: pubnub-7.4.2
location: https://pypi.org/project/pubnub/
supported-platforms:
supported-operating-systems:
Expand Down Expand Up @@ -97,8 +97,8 @@ sdks:
-
distribution-type: library
distribution-repository: git release
package-name: pubnub-7.4.1
location: https://github.com/pubnub/python/releases/download/v7.4.1/pubnub-7.4.1.tar.gz
package-name: pubnub-7.4.2
location: https://github.com/pubnub/python/releases/download/v7.4.2/pubnub-7.4.2.tar.gz
supported-platforms:
supported-operating-systems:
Linux:
Expand Down Expand Up @@ -169,6 +169,11 @@ sdks:
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
is-required: Required
changelog:
- date: 2024-03-07
version: v7.4.2
changes:
- type: bug
text: "Add missing status and type fields in app context. Now they are included, by default, in the response for getting channel/uuid metadata ."
- date: 2024-02-26
version: v7.4.1
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v7.4.2
March 07 2024

#### Fixed
- Add missing status and type fields in app context. Now they are included, by default, in the response for getting channel/uuid metadata .

## v7.4.1
February 26 2024

Expand Down
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
2 changes: 1 addition & 1 deletion pubnub/pubnub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

class PubNubCore:
"""A base class for PubNub Python API implementations"""
SDK_VERSION = "7.4.1"
SDK_VERSION = "7.4.2"
SDK_NAME = "PubNub-Python"

TIMESTAMP_DIVIDER = 1000
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pubnub',
version='7.4.1',
version='7.4.2',
description='PubNub Real-time push service in the cloud',
author='PubNub',
author_email='[email protected]',
Expand Down
Loading

0 comments on commit 6bea25d

Please sign in to comment.