Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion pubnub/endpoints/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def request_headers(self):
headers = {}
if self.__compress_request():
headers["Content-Encoding"] = "gzip"
if self.http_method() == HttpMethod.POST:
if self.http_method() in [HttpMethod.POST, HttpMethod.PATCH]:
headers["Content-type"] = "application/json"

return headers
Expand Down
17 changes: 12 additions & 5 deletions pubnub/endpoints/objects_v2/members/get_channel_members.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
IncludeCustomEndpoint, ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.channel_members import PNGetChannelMembersResult
from pubnub.models.consumer.objects_v2.common import MemberIncludes
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope

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


class GetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
UUIDIncludeEndpoint):
UUIDIncludeEndpoint, IncludeCapableEndpoint):
GET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"

def __init__(self, pubnub, channel: str = None, include_custom: bool = None, limit: int = None, filter: str = None,
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
def __init__(self, pubnub, channel: str = None, include_custom: bool = None,
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
page: PNPage = None, include: MemberIncludes = None):
ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include)
ChannelEndpoint.__init__(self, channel=channel)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
Expand All @@ -32,6 +35,10 @@ def build_path(self):
def validate_specific_params(self):
self._validate_channel()

def include(self, includes: MemberIncludes) -> 'GetChannelMembers':
super().include(includes)
return self

def create_response(self, envelope) -> PNGetChannelMembersResult:
return PNGetChannelMembersResult(envelope)

Expand Down
23 changes: 15 additions & 8 deletions pubnub/endpoints/objects_v2/members/manage_channel_members.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import List
from pubnub import utils
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \
IncludeCustomEndpoint, ChannelEndpoint, UUIDIncludeEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.channel_members import PNManageChannelMembersResult
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNManageChannelMembersResult
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope

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


class ManageChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
UUIDIncludeEndpoint):
IncludeCapableEndpoint, UUIDIncludeEndpoint):
MANAGE_CHANNELS_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"

def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None, uuids_to_remove: List[str] = None,
include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None,
sort_keys: list = None, page: PNPage = None):
def __init__(self, pubnub, channel: str = None, uuids_to_set: List[PNUUID] = None,
Comment thread
marcin-cebo marked this conversation as resolved.
uuids_to_remove: List[PNUUID] = None, include_custom: bool = None, limit: int = None,
filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None,
include: MembershipIncludes = None):
ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include)
ChannelEndpoint.__init__(self, channel=channel)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
Expand All @@ -36,17 +39,21 @@ def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None,
if uuids_to_remove:
utils.extend_list(self._uuids_to_remove, uuids_to_remove)

def set(self, uuids_to_set: List[str]) -> 'ManageChannelMembers':
def set(self, uuids_to_set: List[PNUUID]) -> 'ManageChannelMembers':
self._uuids_to_set = list(uuids_to_set)
return self

def remove(self, uuids_to_remove: List[str]) -> 'ManageChannelMembers':
def remove(self, uuids_to_remove: List[PNUUID]) -> 'ManageChannelMembers':
self._uuids_to_remove = list(uuids_to_remove)
return self

def validate_specific_params(self):
self._validate_channel()

def include(self, includes: MembershipIncludes) -> 'ManageChannelMembers':
super().include(includes)
return self

def build_path(self):
return ManageChannelMembers.MANAGE_CHANNELS_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel)

Expand Down
14 changes: 8 additions & 6 deletions pubnub/endpoints/objects_v2/members/remove_channel_members.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import List
from pubnub import utils
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ChannelEndpoint, ListEndpoint, \
IncludeCustomEndpoint, UUIDIncludeEndpoint
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ChannelEndpoint, \
ListEndpoint, IncludeCustomEndpoint, UUIDIncludeEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.channel_members import PNRemoveChannelMembersResult
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNRemoveChannelMembersResult
from pubnub.models.consumer.objects_v2.common import MemberIncludes
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope

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


class RemoveChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
UUIDIncludeEndpoint):
UUIDIncludeEndpoint, IncludeCapableEndpoint):
REMOVE_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"

def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None,
def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None,
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
page: PNPage = None):
page: PNPage = None, include: MemberIncludes = None):
ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
ChannelEndpoint.__init__(self, channel=channel)
Expand Down
36 changes: 29 additions & 7 deletions pubnub/endpoints/objects_v2/members/set_channel_members.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import List
from pubnub import utils
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
IncludeCustomEndpoint, UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.channel_members import PNSetChannelMembersResult
from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNSetChannelMembersResult
from pubnub.models.consumer.objects_v2.common import MemberIncludes
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope

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


class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint,
class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
UUIDIncludeEndpoint):
SET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids"

def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None,
def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None,
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
page: PNPage = None):
page: PNPage = None, include: MemberIncludes = None):
ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
ChannelEndpoint.__init__(self, channel=channel)
IncludeCustomEndpoint.__init__(self, include_custom=include_custom)
UUIDIncludeEndpoint.__init__(self)

self._uuids = []
if self._uuids:
if uuids:
utils.extend_list(self._uuids, uuids)

def uuids(self, uuids) -> 'SetChannelMembers':
Expand All @@ -40,6 +42,26 @@ def uuids(self, uuids) -> 'SetChannelMembers':
def validate_specific_params(self):
self._validate_channel()

def include(self, includes: MemberIncludes) -> 'SetChannelMembers':
"""
Include additional information in the members response.

Parameters
----------
includes : MemberIncludes
The additional information to include in the member response.

See Also
--------
pubnub.models.consumer.objects_v2.common.MemberIncludese : For details on the available includes.

Returns
-------
self : SetChannelMembers
"""
super().include(includes)
return self

def build_path(self):
return SetChannelMembers.SET_CHANNEL_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel)

Expand Down
31 changes: 27 additions & 4 deletions pubnub/endpoints/objects_v2/memberships/get_memberships.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \
UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \
IncludeCustomEndpoint, UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
from pubnub.models.consumer.objects_v2.memberships import PNGetMembershipsResult
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope
Expand All @@ -13,13 +14,15 @@ class PNGetMembershipsResultEnvelope(Envelope):
status: PNStatus


class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint,
class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
ChannelIncludeEndpoint):
GET_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels"

def __init__(self, pubnub, uuid: str = None, include_custom: bool = False, limit: int = None, filter: str = None,
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
include_total_count: bool = None, sort_keys: list = None, page: PNPage = None,
include: MembershipIncludes = None):
ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include=include)
UuidEndpoint.__init__(self, uuid=uuid)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
Expand All @@ -32,6 +35,26 @@ def build_path(self):
def validate_specific_params(self):
self._validate_uuid()

def include(self, includes: MembershipIncludes) -> 'GetMemberships':
"""
Include additional information in the membership response.

Parameters
----------
includes : MembershipIncludes
The additional information to include in the membership response.

See Also
--------
pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes.

Returns
-------
self : GetMemberships
"""
super().include(includes)
return self

def create_response(self, envelope) -> PNGetMembershipsResult:
return PNGetMembershipsResult(envelope)

Expand Down
40 changes: 32 additions & 8 deletions pubnub/endpoints/objects_v2/memberships/manage_memberships.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import List
from pubnub import utils
from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \
from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \
IncludeCustomEndpoint, UuidEndpoint, ChannelIncludeEndpoint
from pubnub.enums import PNOperationType
from pubnub.enums import HttpMethod

from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.objects_v2.memberships import PNManageMembershipsResult
from pubnub.models.consumer.objects_v2.common import MembershipIncludes
from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNManageMembershipsResult
from pubnub.models.consumer.objects_v2.page import PNPage
from pubnub.structures import Envelope

Expand All @@ -16,14 +17,17 @@ class PNManageMembershipsResultEnvelope(Envelope):
status: PNStatus


class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint,
class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint,
ChannelIncludeEndpoint):
MANAGE_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels"

def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[str] = None,
channel_memberships_to_remove: List[str] = None, include_custom: bool = False, limit: int = None,
filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None):
def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[PNChannelMembership] = None,
Comment thread
marcin-cebo marked this conversation as resolved.
channel_memberships_to_remove: List[PNChannelMembership] = None, include_custom: bool = False,
limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None,
page: PNPage = None, include: MembershipIncludes = None):

ObjectsEndpoint.__init__(self, pubnub)
IncludeCapableEndpoint.__init__(self, include=include)
UuidEndpoint.__init__(self, uuid=uuid)
ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count,
sort_keys=sort_keys, page=page)
Expand All @@ -38,14 +42,34 @@ def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[st
if channel_memberships_to_remove:
utils.extend_list(self._channel_memberships_to_remove, channel_memberships_to_remove)

def set(self, channel_memberships_to_set: List[str]) -> 'ManageMemberships':
def set(self, channel_memberships_to_set: List[PNChannelMembership]) -> 'ManageMemberships':
self._channel_memberships_to_set = list(channel_memberships_to_set)
return self

def remove(self, channel_memberships_to_remove: List[str]) -> 'ManageMemberships':
def remove(self, channel_memberships_to_remove: List[PNChannelMembership]) -> 'ManageMemberships':
self._channel_memberships_to_remove = list(channel_memberships_to_remove)
return self

def include(self, includes: MembershipIncludes) -> 'ManageMemberships':
"""
Include additional information in the membership response.

Parameters
----------
includes : MembershipIncludes
The additional information to include in the membership response.

See Also
--------
pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes.

Returns
-------
self : GetMemberships
"""
super().include(includes)
return self

def validate_specific_params(self):
self._validate_uuid()

Expand Down
Loading