Skip to content

Commit 3acbac6

Browse files
author
Sebastian Molenda
committed
MOOOARRR TYPEZZZZZZ HINTZZZZ
1 parent 6fd778e commit 3acbac6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1142
-512
lines changed

pubnub/endpoints/access/grant_token.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,77 @@
1+
from typing import Union, List, Optional
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_TTL_MISSING, PNERR_INVALID_META, PNERR_RESOURCES_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
7+
from pubnub.models.consumer.common import PNStatus
68
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNGrantTokenResultEnvelope(Envelope):
13+
result: PNGrantTokenResult
14+
status: PNStatus
715

816

917
class GrantToken(Endpoint):
1018
GRANT_TOKEN_PATH = "/v3/pam/%s/grant"
1119

12-
def __init__(self, pubnub):
20+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_groups: Union[str, List[str]] = None,
21+
users: Union[str, List[str]] = None, spaces: Union[str, List[str]] = None,
22+
authorized_user_id: str = None, ttl: Optional[int] = None, meta: Optional[any] = None):
1323
Endpoint.__init__(self, pubnub)
14-
self._ttl = None
15-
self._meta = None
16-
self._authorized_uuid = None
24+
self._ttl = ttl
25+
self._meta = meta
26+
self._authorized_uuid = authorized_user_id
1727
self._channels = []
28+
if channels:
29+
utils.extend_list(self._channels, channels)
30+
if spaces:
31+
utils.extend_list(self._channels, spaces)
32+
1833
self._groups = []
34+
if channel_groups:
35+
utils.extend_list(self._groups, channel_groups)
1936
self._uuids = []
37+
if users:
38+
utils.extend_list(self._uuids, users)
2039

2140
self._sort_params = True
2241

23-
def ttl(self, ttl):
42+
def ttl(self, ttl: int) -> 'GrantToken':
2443
self._ttl = ttl
2544
return self
2645

27-
def meta(self, meta):
46+
def meta(self, meta: any) -> 'GrantToken':
2847
self._meta = meta
2948
return self
3049

31-
def authorized_uuid(self, uuid):
50+
def authorized_uuid(self, uuid: str) -> 'GrantToken':
3251
self._authorized_uuid = uuid
3352
return self
3453

35-
def authorized_user(self, user):
54+
def authorized_user(self, user) -> 'GrantToken':
3655
self._authorized_uuid = user
3756
return self
3857

39-
def spaces(self, spaces):
58+
def spaces(self, spaces: Union[str, List[str]]) -> 'GrantToken':
4059
self._channels = spaces
4160
return self
4261

43-
def users(self, users):
62+
def users(self, users: Union[str, List[str]]) -> 'GrantToken':
4463
self._uuids = users
4564
return self
4665

47-
def channels(self, channels):
66+
def channels(self, channels: Union[str, List[str]]) -> 'GrantToken':
4867
self._channels = channels
4968
return self
5069

51-
def groups(self, groups):
70+
def groups(self, groups: Union[str, List[str]]) -> 'GrantToken':
5271
self._groups = groups
5372
return self
5473

55-
def uuids(self, uuids):
74+
def uuids(self, uuids: Union[str, List[str]]) -> 'GrantToken':
5675
self._uuids = uuids
5776
return self
5877

@@ -102,9 +121,12 @@ def validate_params(self):
102121
self.validate_ttl()
103122
self.validate_resources()
104123

105-
def create_response(self, envelope):
124+
def create_response(self, envelope) -> PNGrantTokenResult:
106125
return PNGrantTokenResult.from_json(envelope['data'])
107126

127+
def sync(self):
128+
return super().sync()
129+
108130
def is_auth_required(self):
109131
return False
110132

pubnub/endpoints/access/revoke_token.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
from pubnub.enums import PNOperationType, HttpMethod
22
from pubnub.endpoints.endpoint import Endpoint
3+
from pubnub.models.consumer.common import PNStatus
34
from pubnub.models.consumer.v3.access_manager import PNRevokeTokenResult
45
from pubnub import utils
6+
from pubnub.structures import Envelope
7+
8+
9+
class PNRevokeTokenResultEnvelope(Envelope):
10+
result: PNRevokeTokenResult
11+
status: PNStatus
512

613

714
class RevokeToken(Endpoint):
815
REVOKE_TOKEN_PATH = "/v3/pam/%s/grant/%s"
916

10-
def __init__(self, pubnub, token):
17+
def __init__(self, pubnub, token: str):
1118
Endpoint.__init__(self, pubnub)
1219
self.token = token
1320

@@ -18,6 +25,9 @@ def validate_params(self):
1825
def create_response(self, envelope):
1926
return PNRevokeTokenResult(envelope)
2027

28+
def sync(self) -> PNRevokeTokenResultEnvelope:
29+
return PNRevokeTokenResultEnvelope(super().sync())
30+
2131
def is_auth_required(self):
2232
return False
2333

pubnub/endpoints/channel_groups/add_channel_to_channel_group.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1+
from typing import List, Union
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_CHANNELS_MISSING, PNERR_GROUP_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
67
from pubnub.models.consumer.channel_group import PNChannelGroupsAddChannelResult
8+
from pubnub.models.consumer.common import PNStatus
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNChannelGroupsAddChannelResultEnvelope(Envelope):
13+
result: PNChannelGroupsAddChannelResult
14+
status: PNStatus
715

816

917
class AddChannelToChannelGroup(Endpoint):
1018
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>?add=ch1,ch2
1119
ADD_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
1220

13-
def __init__(self, pubnub):
21+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_group: str = None):
1422
Endpoint.__init__(self, pubnub)
1523
self._channels = []
16-
self._channel_group = None
17-
18-
def channels(self, channels):
19-
if isinstance(channels, (list, tuple)):
20-
self._channels.extend(channels)
21-
else:
22-
self._channels.extend(utils.split_items(channels))
24+
if channels:
25+
utils.extend_list(self._channels, channels)
26+
self._channel_group = channel_group
2327

28+
def channels(self, channels) -> 'AddChannelToChannelGroup':
29+
utils.extend_list(self._channels, channels)
2430
return self
2531

26-
def channel_group(self, channel_group):
32+
def channel_group(self, channel_group: str) -> 'AddChannelToChannelGroup':
2733
self._channel_group = channel_group
28-
2934
return self
3035

3136
def custom_params(self):
@@ -50,9 +55,12 @@ def validate_params(self):
5055
def is_auth_required(self):
5156
return True
5257

53-
def create_response(self, envelope):
58+
def create_response(self, envelope) -> PNChannelGroupsAddChannelResult:
5459
return PNChannelGroupsAddChannelResult()
5560

61+
def sync(self):
62+
return PNChannelGroupsAddChannelResultEnvelope(super().sync())
63+
5664
def request_timeout(self):
5765
return self.pubnub.config.non_subscribe_request_timeout
5866

pubnub/endpoints/channel_groups/list_channels_in_channel_group.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
from pubnub.exceptions import PubNubException
55
from pubnub.enums import HttpMethod, PNOperationType
66
from pubnub.models.consumer.channel_group import PNChannelGroupsListResult
7+
from pubnub.models.consumer.common import PNStatus
8+
from pubnub.structures import Envelope
9+
10+
11+
class PNChannelGroupsListResultEnvelope(Envelope):
12+
result: PNChannelGroupsListResult
13+
status: PNStatus
714

815

916
class ListChannelsInChannelGroup(Endpoint):
1017
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>
1118
LIST_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
1219

13-
def __init__(self, pubnub):
20+
def __init__(self, pubnub, channel_group: str = None):
1421
Endpoint.__init__(self, pubnub)
15-
self._channel_group = None
16-
17-
def channel_group(self, channel_group):
1822
self._channel_group = channel_group
1923

24+
def channel_group(self, channel_group: str) -> 'ListChannelsInChannelGroup':
25+
self._channel_group = channel_group
2026
return self
2127

2228
def custom_params(self):
@@ -35,12 +41,15 @@ def validate_params(self):
3541
if not isinstance(self._channel_group, str) or len(self._channel_group) == 0:
3642
raise PubNubException(pn_error=PNERR_GROUP_MISSING)
3743

38-
def create_response(self, envelope):
44+
def create_response(self, envelope) -> PNChannelGroupsListResult:
3945
if 'payload' in envelope and 'channels' in envelope['payload']:
4046
return PNChannelGroupsListResult(envelope['payload']['channels'])
4147
else:
4248
return PNChannelGroupsListResult([])
4349

50+
def sync(self) -> PNChannelGroupsListResultEnvelope:
51+
return PNChannelGroupsListResultEnvelope(super().sync())
52+
4453
def is_auth_required(self):
4554
return True
4655

pubnub/endpoints/channel_groups/remove_channel_from_channel_group.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
from typing import List, Union
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_CHANNELS_MISSING, PNERR_GROUP_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
67
from pubnub.models.consumer.channel_group import PNChannelGroupsRemoveChannelResult
8+
from pubnub.models.consumer.common import PNStatus
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNChannelGroupsRemoveChannelResultEnvelope(Envelope):
13+
result: PNChannelGroupsRemoveChannelResult
14+
status: PNStatus
715

816

917
class RemoveChannelFromChannelGroup(Endpoint):
1018
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>?remove=ch1,ch2
1119
REMOVE_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
20+
_channels: list = []
21+
_channel_group: str = None
1222

13-
def __init__(self, pubnub):
23+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_group: str = None):
1424
Endpoint.__init__(self, pubnub)
1525
self._channels = []
16-
self._channel_group = None
17-
18-
def channels(self, channels):
19-
if isinstance(channels, (list, tuple)):
20-
self._channels.extend(channels)
21-
else:
22-
self._channels.extend(utils.split_items(channels))
26+
if channels:
27+
utils.extend_list(self._channels, channels)
28+
self._channel_group = channel_group
2329

30+
def channels(self, channels) -> 'RemoveChannelFromChannelGroup':
31+
utils.extend_list(self._channels, channels)
2432
return self
2533

26-
def channel_group(self, channel_group):
34+
def channel_group(self, channel_group: str) -> 'RemoveChannelFromChannelGroup':
2735
self._channel_group = channel_group
28-
2936
return self
3037

3138
def custom_params(self):
@@ -50,9 +57,12 @@ def validate_params(self):
5057
def is_auth_required(self):
5158
return True
5259

53-
def create_response(self, envelope):
60+
def create_response(self, envelope) -> PNChannelGroupsRemoveChannelResult:
5461
return PNChannelGroupsRemoveChannelResult()
5562

63+
def sync(self):
64+
return PNChannelGroupsRemoveChannelResultEnvelope(super().sync())
65+
5666
def request_timeout(self):
5767
return self.pubnub.config.non_subscribe_request_timeout
5868

pubnub/endpoints/channel_groups/remove_channel_group.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
from pubnub.exceptions import PubNubException
55
from pubnub.enums import HttpMethod, PNOperationType
66
from pubnub.models.consumer.channel_group import PNChannelGroupsRemoveGroupResult
7+
from pubnub.models.consumer.common import PNStatus
8+
from pubnub.structures import Envelope
9+
10+
11+
class PNChannelGroupsRemoveGroupResultEnvelope(Envelope):
12+
result: PNChannelGroupsRemoveGroupResult
13+
status: PNStatus
714

815

916
class RemoveChannelGroup(Endpoint):
1017
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>/remove
1118
REMOVE_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s/remove"
1219

13-
def __init__(self, pubnub):
20+
def __init__(self, pubnub, channel_group: str = None):
1421
Endpoint.__init__(self, pubnub)
15-
self._channel_group = None
16-
17-
def channel_group(self, channel_group):
1822
self._channel_group = channel_group
1923

24+
def channel_group(self, channel_group: str) -> 'RemoveChannelGroup':
25+
self._channel_group = channel_group
2026
return self
2127

2228
def custom_params(self):
@@ -41,6 +47,9 @@ def is_auth_required(self):
4147
def create_response(self, envelope):
4248
return PNChannelGroupsRemoveGroupResult()
4349

50+
def sync(self) -> PNChannelGroupsRemoveGroupResultEnvelope:
51+
return PNChannelGroupsRemoveGroupResultEnvelope(super().sync())
52+
4453
def request_timeout(self):
4554
return self.pubnub.config.non_subscribe_request_timeout
4655

0 commit comments

Comments
 (0)