Skip to content

Commit e0796b9

Browse files
Sebastian Molendapubnub-release-bot
andauthored
Members and Membership with Include Objects (#202)
* Members with Include Objects * ... and channel members * PubNub SDK 10.1.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 778e05c commit e0796b9

28 files changed

+2732
-123
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 10.0.1
2+
version: 10.1.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-10.0.1
21+
package-name: pubnub-10.1.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -91,8 +91,8 @@ sdks:
9191
-
9292
distribution-type: library
9393
distribution-repository: git release
94-
package-name: pubnub-10.0.1
95-
location: https://github.com/pubnub/python/releases/download/10.0.1/pubnub-10.0.1.tar.gz
94+
package-name: pubnub-10.1.0
95+
location: https://github.com/pubnub/python/releases/download/10.1.0/pubnub-10.1.0.tar.gz
9696
supported-platforms:
9797
supported-operating-systems:
9898
Linux:
@@ -163,6 +163,11 @@ sdks:
163163
license-url: https://github.com/encode/httpx/blob/master/LICENSE.md
164164
is-required: Required
165165
changelog:
166+
- date: 2025-01-30
167+
version: 10.1.0
168+
changes:
169+
- type: feature
170+
text: "Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type."
166171
- date: 2025-01-28
167172
version: 10.0.1
168173
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 10.1.0
2+
January 30 2025
3+
4+
#### Added
5+
- Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type.
6+
17
## 10.0.1
28
January 28 2025
39

pubnub/endpoints/endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def request_headers(self):
9797
headers = {}
9898
if self.__compress_request():
9999
headers["Content-Encoding"] = "gzip"
100-
if self.http_method() == HttpMethod.POST:
100+
if self.http_method() in [HttpMethod.POST, HttpMethod.PATCH]:
101101
headers["Content-type"] = "application/json"
102102

103103
return headers

pubnub/endpoints/objects_v2/members/get_channel_members.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
2-
ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint
1+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
2+
IncludeCustomEndpoint, ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint
33
from pubnub.enums import PNOperationType
44
from pubnub.enums import HttpMethod
55
from pubnub.models.consumer.common import PNStatus
66
from pubnub.models.consumer.objects_v2.channel_members import PNGetChannelMembersResult
7+
from pubnub.models.consumer.objects_v2.common import MemberIncludes
78
from pubnub.models.consumer.objects_v2.page import PNPage
89
from pubnub.structures import Envelope
910

@@ -14,12 +15,14 @@ class PNGetChannelMembersResultEnvelope(Envelope):
1415

1516

1617
class GetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
17-
UUIDIncludeEndpoint):
18+
UUIDIncludeEndpoint, IncludeCapableEndpoint):
1819
GET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"
1920

20-
def __init__(self, pubnub, channel: str = None, include_custom: bool = None, limit: int = None, filter: str = None,
21-
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
21+
def __init__(self, pubnub, channel: str = None, include_custom: bool = None,
22+
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
23+
page: PNPage = None, include: MemberIncludes = None):
2224
ObjectsEndpoint.__init__(self, pubnub)
25+
IncludeCapableEndpoint.__init__(self, include)
2326
ChannelEndpoint.__init__(self, channel=channel)
2427
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2528
sort_keys=sort_keys, page=page)
@@ -32,6 +35,10 @@ def build_path(self):
3235
def validate_specific_params(self):
3336
self._validate_channel()
3437

38+
def include(self, includes: MemberIncludes) -> 'GetChannelMembers':
39+
super().include(includes)
40+
return self
41+
3542
def create_response(self, envelope) -> PNGetChannelMembersResult:
3643
return PNGetChannelMembersResult(envelope)
3744

pubnub/endpoints/objects_v2/members/manage_channel_members.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import List
22
from pubnub import utils
3-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \
3+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \
44
IncludeCustomEndpoint, ChannelEndpoint, UUIDIncludeEndpoint
55
from pubnub.enums import PNOperationType
66
from pubnub.enums import HttpMethod
77
from pubnub.models.consumer.common import PNStatus
8-
from pubnub.models.consumer.objects_v2.channel_members import PNManageChannelMembersResult
8+
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNManageChannelMembersResult
9+
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
910
from pubnub.models.consumer.objects_v2.page import PNPage
1011
from pubnub.structures import Envelope
1112

@@ -16,13 +17,15 @@ class PNManageChannelMembersResultEnvelope(Envelope):
1617

1718

1819
class ManageChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
19-
UUIDIncludeEndpoint):
20+
IncludeCapableEndpoint, UUIDIncludeEndpoint):
2021
MANAGE_CHANNELS_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"
2122

22-
def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None, uuids_to_remove: List[str] = None,
23-
include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None,
24-
sort_keys: list = None, page: PNPage = None):
23+
def __init__(self, pubnub, channel: str = None, uuids_to_set: List[PNUUID] = None,
24+
uuids_to_remove: List[PNUUID] = None, include_custom: bool = None, limit: int = None,
25+
filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None,
26+
include: MembershipIncludes = None):
2527
ObjectsEndpoint.__init__(self, pubnub)
28+
IncludeCapableEndpoint.__init__(self, include)
2629
ChannelEndpoint.__init__(self, channel=channel)
2730
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2831
sort_keys=sort_keys, page=page)
@@ -36,17 +39,21 @@ def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None,
3639
if uuids_to_remove:
3740
utils.extend_list(self._uuids_to_remove, uuids_to_remove)
3841

39-
def set(self, uuids_to_set: List[str]) -> 'ManageChannelMembers':
42+
def set(self, uuids_to_set: List[PNUUID]) -> 'ManageChannelMembers':
4043
self._uuids_to_set = list(uuids_to_set)
4144
return self
4245

43-
def remove(self, uuids_to_remove: List[str]) -> 'ManageChannelMembers':
46+
def remove(self, uuids_to_remove: List[PNUUID]) -> 'ManageChannelMembers':
4447
self._uuids_to_remove = list(uuids_to_remove)
4548
return self
4649

4750
def validate_specific_params(self):
4851
self._validate_channel()
4952

53+
def include(self, includes: MembershipIncludes) -> 'ManageChannelMembers':
54+
super().include(includes)
55+
return self
56+
5057
def build_path(self):
5158
return ManageChannelMembers.MANAGE_CHANNELS_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel)
5259

pubnub/endpoints/objects_v2/members/remove_channel_members.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import List
22
from pubnub import utils
3-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ChannelEndpoint, ListEndpoint, \
4-
IncludeCustomEndpoint, UUIDIncludeEndpoint
3+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ChannelEndpoint, \
4+
ListEndpoint, IncludeCustomEndpoint, UUIDIncludeEndpoint
55
from pubnub.enums import PNOperationType
66
from pubnub.enums import HttpMethod
77
from pubnub.models.consumer.common import PNStatus
8-
from pubnub.models.consumer.objects_v2.channel_members import PNRemoveChannelMembersResult
8+
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNRemoveChannelMembersResult
9+
from pubnub.models.consumer.objects_v2.common import MemberIncludes
910
from pubnub.models.consumer.objects_v2.page import PNPage
1011
from pubnub.structures import Envelope
1112

@@ -16,13 +17,14 @@ class PNRemoveChannelMembersResultEnvelope(Envelope):
1617

1718

1819
class RemoveChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
19-
UUIDIncludeEndpoint):
20+
UUIDIncludeEndpoint, IncludeCapableEndpoint):
2021
REMOVE_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"
2122

22-
def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None,
23+
def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None,
2324
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
24-
page: PNPage = None):
25+
page: PNPage = None, include: MemberIncludes = None):
2526
ObjectsEndpoint.__init__(self, pubnub)
27+
IncludeCapableEndpoint.__init__(self, include)
2628
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2729
sort_keys=sort_keys, page=page)
2830
ChannelEndpoint.__init__(self, channel=channel)

pubnub/endpoints/objects_v2/members/set_channel_members.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import List
22
from pubnub import utils
3-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
4-
UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint
3+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
4+
IncludeCustomEndpoint, UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint
55
from pubnub.enums import PNOperationType
66
from pubnub.enums import HttpMethod
77
from pubnub.models.consumer.common import PNStatus
8-
from pubnub.models.consumer.objects_v2.channel_members import PNSetChannelMembersResult
8+
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNSetChannelMembersResult
9+
from pubnub.models.consumer.objects_v2.common import MemberIncludes
910
from pubnub.models.consumer.objects_v2.page import PNPage
1011
from pubnub.structures import Envelope
1112

@@ -15,22 +16,23 @@ class PNSetChannelMembersResultEnvelope(Envelope):
1516
status: PNStatus
1617

1718

18-
class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
19+
class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
1920
UUIDIncludeEndpoint):
2021
SET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"
2122

22-
def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None,
23+
def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None,
2324
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
24-
page: PNPage = None):
25+
page: PNPage = None, include: MemberIncludes = None):
2526
ObjectsEndpoint.__init__(self, pubnub)
27+
IncludeCapableEndpoint.__init__(self, include)
2628
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2729
sort_keys=sort_keys, page=page)
2830
ChannelEndpoint.__init__(self, channel=channel)
2931
IncludeCustomEndpoint.__init__(self, include_custom=include_custom)
3032
UUIDIncludeEndpoint.__init__(self)
3133

3234
self._uuids = []
33-
if self._uuids:
35+
if uuids:
3436
utils.extend_list(self._uuids, uuids)
3537

3638
def uuids(self, uuids) -> 'SetChannelMembers':
@@ -40,6 +42,26 @@ def uuids(self, uuids) -> 'SetChannelMembers':
4042
def validate_specific_params(self):
4143
self._validate_channel()
4244

45+
def include(self, includes: MemberIncludes) -> 'SetChannelMembers':
46+
"""
47+
Include additional information in the members response.
48+
49+
Parameters
50+
----------
51+
includes : MemberIncludes
52+
The additional information to include in the member response.
53+
54+
See Also
55+
--------
56+
pubnub.models.consumer.objects_v2.common.MemberIncludese : For details on the available includes.
57+
58+
Returns
59+
-------
60+
self : SetChannelMembers
61+
"""
62+
super().include(includes)
63+
return self
64+
4365
def build_path(self):
4466
return SetChannelMembers.SET_CHANNEL_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel)
4567

pubnub/endpoints/objects_v2/memberships/get_memberships.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
2-
UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint
1+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
2+
IncludeCustomEndpoint, UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint
33
from pubnub.enums import PNOperationType
44
from pubnub.enums import HttpMethod
55
from pubnub.models.consumer.common import PNStatus
6+
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
67
from pubnub.models.consumer.objects_v2.memberships import PNGetMembershipsResult
78
from pubnub.models.consumer.objects_v2.page import PNPage
89
from pubnub.structures import Envelope
@@ -13,13 +14,15 @@ class PNGetMembershipsResultEnvelope(Envelope):
1314
status: PNStatus
1415

1516

16-
class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint,
17+
class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
1718
ChannelIncludeEndpoint):
1819
GET_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels"
1920

2021
def __init__(self, pubnub, uuid: str = None, include_custom: bool = False, limit: int = None, filter: str = None,
21-
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
22+
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None,
23+
include: MembershipIncludes = None):
2224
ObjectsEndpoint.__init__(self, pubnub)
25+
IncludeCapableEndpoint.__init__(self, include=include)
2326
UuidEndpoint.__init__(self, uuid=uuid)
2427
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2528
sort_keys=sort_keys, page=page)
@@ -32,6 +35,26 @@ def build_path(self):
3235
def validate_specific_params(self):
3336
self._validate_uuid()
3437

38+
def include(self, includes: MembershipIncludes) -> 'GetMemberships':
39+
"""
40+
Include additional information in the membership response.
41+
42+
Parameters
43+
----------
44+
includes : MembershipIncludes
45+
The additional information to include in the membership response.
46+
47+
See Also
48+
--------
49+
pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes.
50+
51+
Returns
52+
-------
53+
self : GetMemberships
54+
"""
55+
super().include(includes)
56+
return self
57+
3558
def create_response(self, envelope) -> PNGetMembershipsResult:
3659
return PNGetMembershipsResult(envelope)
3760

pubnub/endpoints/objects_v2/memberships/manage_memberships.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from typing import List
22
from pubnub import utils
3-
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \
3+
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \
44
IncludeCustomEndpoint, UuidEndpoint, ChannelIncludeEndpoint
55
from pubnub.enums import PNOperationType
66
from pubnub.enums import HttpMethod
77

88
from pubnub.models.consumer.common import PNStatus
9-
from pubnub.models.consumer.objects_v2.memberships import PNManageMembershipsResult
9+
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
10+
from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNManageMembershipsResult
1011
from pubnub.models.consumer.objects_v2.page import PNPage
1112
from pubnub.structures import Envelope
1213

@@ -16,14 +17,17 @@ class PNManageMembershipsResultEnvelope(Envelope):
1617
status: PNStatus
1718

1819

19-
class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint,
20+
class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
2021
ChannelIncludeEndpoint):
2122
MANAGE_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels"
2223

23-
def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[str] = None,
24-
channel_memberships_to_remove: List[str] = None, include_custom: bool = False, limit: int = None,
25-
filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
24+
def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[PNChannelMembership] = None,
25+
channel_memberships_to_remove: List[PNChannelMembership] = None, include_custom: bool = False,
26+
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
27+
page: PNPage = None, include: MembershipIncludes = None):
28+
2629
ObjectsEndpoint.__init__(self, pubnub)
30+
IncludeCapableEndpoint.__init__(self, include=include)
2731
UuidEndpoint.__init__(self, uuid=uuid)
2832
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
2933
sort_keys=sort_keys, page=page)
@@ -38,14 +42,34 @@ def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[st
3842
if channel_memberships_to_remove:
3943
utils.extend_list(self._channel_memberships_to_remove, channel_memberships_to_remove)
4044

41-
def set(self, channel_memberships_to_set: List[str]) -> 'ManageMemberships':
45+
def set(self, channel_memberships_to_set: List[PNChannelMembership]) -> 'ManageMemberships':
4246
self._channel_memberships_to_set = list(channel_memberships_to_set)
4347
return self
4448

45-
def remove(self, channel_memberships_to_remove: List[str]) -> 'ManageMemberships':
49+
def remove(self, channel_memberships_to_remove: List[PNChannelMembership]) -> 'ManageMemberships':
4650
self._channel_memberships_to_remove = list(channel_memberships_to_remove)
4751
return self
4852

53+
def include(self, includes: MembershipIncludes) -> 'ManageMemberships':
54+
"""
55+
Include additional information in the membership response.
56+
57+
Parameters
58+
----------
59+
includes : MembershipIncludes
60+
The additional information to include in the membership response.
61+
62+
See Also
63+
--------
64+
pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes.
65+
66+
Returns
67+
-------
68+
self : GetMemberships
69+
"""
70+
super().include(includes)
71+
return self
72+
4973
def validate_specific_params(self):
5074
self._validate_uuid()
5175

0 commit comments

Comments
 (0)