-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add type hints to customer facing interfaces #195
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,77 @@ | ||
from typing import Union, List, Optional | ||
from pubnub import utils | ||
from pubnub.endpoints.endpoint import Endpoint | ||
from pubnub.errors import PNERR_TTL_MISSING, PNERR_INVALID_META, PNERR_RESOURCES_MISSING | ||
from pubnub.exceptions import PubNubException | ||
from pubnub.enums import HttpMethod, PNOperationType | ||
from pubnub.models.consumer.common import PNStatus | ||
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult | ||
from pubnub.structures import Envelope | ||
|
||
|
||
class PNGrantTokenResultEnvelope(Envelope): | ||
result: PNGrantTokenResult | ||
status: PNStatus | ||
|
||
|
||
class GrantToken(Endpoint): | ||
GRANT_TOKEN_PATH = "/v3/pam/%s/grant" | ||
|
||
def __init__(self, pubnub): | ||
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_groups: Union[str, List[str]] = None, | ||
users: Union[str, List[str]] = None, spaces: Union[str, List[str]] = None, | ||
authorized_user_id: str = None, ttl: Optional[int] = None, meta: Optional[any] = None): | ||
Endpoint.__init__(self, pubnub) | ||
self._ttl = None | ||
self._meta = None | ||
self._authorized_uuid = None | ||
self._ttl = ttl | ||
self._meta = meta | ||
self._authorized_uuid = authorized_user_id | ||
self._channels = [] | ||
if channels: | ||
utils.extend_list(self._channels, channels) | ||
if spaces: | ||
utils.extend_list(self._channels, spaces) | ||
|
||
self._groups = [] | ||
if channel_groups: | ||
utils.extend_list(self._groups, channel_groups) | ||
self._uuids = [] | ||
if users: | ||
utils.extend_list(self._uuids, users) | ||
|
||
self._sort_params = True | ||
|
||
def ttl(self, ttl): | ||
def ttl(self, ttl: int) -> 'GrantToken': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a common pattern to extract a variable that repeats into constants? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah. this is python's way of saying :
|
||
self._ttl = ttl | ||
return self | ||
|
||
def meta(self, meta): | ||
def meta(self, meta: any) -> 'GrantToken': | ||
self._meta = meta | ||
return self | ||
|
||
def authorized_uuid(self, uuid): | ||
def authorized_uuid(self, uuid: str) -> 'GrantToken': | ||
self._authorized_uuid = uuid | ||
return self | ||
|
||
def authorized_user(self, user): | ||
def authorized_user(self, user) -> 'GrantToken': | ||
self._authorized_uuid = user | ||
return self | ||
|
||
def spaces(self, spaces): | ||
def spaces(self, spaces: Union[str, List[str]]) -> 'GrantToken': | ||
self._channels = spaces | ||
return self | ||
|
||
def users(self, users): | ||
def users(self, users: Union[str, List[str]]) -> 'GrantToken': | ||
self._uuids = users | ||
return self | ||
|
||
def channels(self, channels): | ||
def channels(self, channels: Union[str, List[str]]) -> 'GrantToken': | ||
self._channels = channels | ||
return self | ||
|
||
def groups(self, groups): | ||
def groups(self, groups: Union[str, List[str]]) -> 'GrantToken': | ||
self._groups = groups | ||
return self | ||
|
||
def uuids(self, uuids): | ||
def uuids(self, uuids: Union[str, List[str]]) -> 'GrantToken': | ||
self._uuids = uuids | ||
return self | ||
|
||
|
@@ -102,9 +121,12 @@ def validate_params(self): | |
self.validate_ttl() | ||
self.validate_resources() | ||
|
||
def create_response(self, envelope): | ||
def create_response(self, envelope) -> PNGrantTokenResult: | ||
return PNGrantTokenResult.from_json(envelope['data']) | ||
|
||
def sync(self) -> PNGrantTokenResultEnvelope: | ||
return PNGrantTokenResultEnvelope(super().sync()) | ||
|
||
def is_auth_required(self): | ||
return False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need
users
andspaces
parameters?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the users and spaces were already in there so I just bubbled them up to the constructor