diff --git a/twilio/auth_strategy/token_auth_strategy.py b/twilio/auth_strategy/token_auth_strategy.py index 1989f4b57..ee51f05a4 100644 --- a/twilio/auth_strategy/token_auth_strategy.py +++ b/twilio/auth_strategy/token_auth_strategy.py @@ -27,7 +27,11 @@ def requires_authentication(self) -> bool: def fetch_token(self): if self.token is None or self.token == "" or self.is_token_expired(self.token): with self.lock: - if self.token is None or self.token == "" or self.is_token_expired(self.token): + if ( + self.token is None + or self.token == "" + or self.is_token_expired(self.token) + ): self.logger.info("New token fetched for accessing organization API") self.token = self.token_manager.fetch_access_token() diff --git a/twilio/base/client_base.py b/twilio/base/client_base.py index b0205804f..b16f85bf5 100644 --- a/twilio/base/client_base.py +++ b/twilio/base/client_base.py @@ -4,7 +4,6 @@ from urllib.parse import urlparse, urlunparse from twilio import __version__ -from twilio.base.exceptions import TwilioException from twilio.http import HttpClient from twilio.http.http_client import TwilioHttpClient from twilio.http.response import Response @@ -99,7 +98,7 @@ def request( else: auth = None - if method == 'DELETE': + if method == "DELETE": del headers["Accept"] uri = self.get_hostname(uri) @@ -148,7 +147,7 @@ async def request_async( ) headers = self.get_headers(method, headers) - if method == 'DELETE': + if method == "DELETE": del headers["Accept"] if self.credential_provider: @@ -174,9 +173,15 @@ async def request_async( def copy_non_none_values(self, data): if isinstance(data, dict): - return {k: self.copy_non_none_values(v) for k, v in data.items() if v is not None} + return { + k: self.copy_non_none_values(v) + for k, v in data.items() + if v is not None + } elif isinstance(data, list): - return [self.copy_non_none_values(item) for item in data if item is not None] + return [ + self.copy_non_none_values(item) for item in data if item is not None + ] return data def get_auth(self, auth: Optional[Tuple[str, str]]) -> Tuple[str, str]: diff --git a/twilio/rest/preview/__init__.py b/twilio/rest/preview/__init__.py index 2f6334ae0..501ae417d 100644 --- a/twilio/rest/preview/__init__.py +++ b/twilio/rest/preview/__init__.py @@ -15,7 +15,6 @@ class Preview(PreviewBase): - @property def authorization_documents(self) -> AuthorizationDocumentList: warn( diff --git a/twilio/rest/preview_iam/PreviewIamBase.py b/twilio/rest/preview_iam/PreviewIamBase.py index e512bb2c2..d8735295d 100644 --- a/twilio/rest/preview_iam/PreviewIamBase.py +++ b/twilio/rest/preview_iam/PreviewIamBase.py @@ -16,6 +16,7 @@ from twilio.rest.preview_iam.v1 import V1 from twilio.rest.preview_iam.versionless import Versionless + class PreviewIamBase(Domain): def __init__(self, twilio: Client): """ @@ -27,7 +28,6 @@ def __init__(self, twilio: Client): self._versionless: Optional[Versionless] = None self._v1: Optional[V1] = None - @property def versionless(self) -> Versionless: """ diff --git a/twilio/rest/preview_iam/__init__.py b/twilio/rest/preview_iam/__init__.py index 9d10225fb..910343622 100644 --- a/twilio/rest/preview_iam/__init__.py +++ b/twilio/rest/preview_iam/__init__.py @@ -1,12 +1,5 @@ -from warnings import warn from twilio.rest.preview_iam.PreviewIamBase import PreviewIamBase -from twilio.rest.preview_iam.versionless.organization.account import ( - AccountList, -) -from twilio.rest.preview_iam.versionless.organization.role_assignment import ( - RoleAssignmentList, -) from twilio.rest.preview_iam.v1.authorize import ( AuthorizeList, ) @@ -17,12 +10,12 @@ OrganizationList, ) + class PreviewIam(PreviewIamBase): @property def organization(self) -> OrganizationList: return self.versionless.organization - @property def authorize(self) -> AuthorizeList: return self.v1.authorize diff --git a/twilio/rest/preview_iam/v1/__init__.py b/twilio/rest/preview_iam/v1/__init__.py index 7bb47b159..224327779 100644 --- a/twilio/rest/preview_iam/v1/__init__.py +++ b/twilio/rest/preview_iam/v1/__init__.py @@ -30,7 +30,7 @@ def __init__(self, domain: Domain): super().__init__(domain, "v1") self._authorize: Optional[AuthorizeList] = None self._token: Optional[TokenList] = None - + @property def authorize(self) -> AuthorizeList: if self._authorize is None: diff --git a/twilio/rest/preview_iam/v1/authorize.py b/twilio/rest/preview_iam/v1/authorize.py index f63090521..051f13a8e 100644 --- a/twilio/rest/preview_iam/v1/authorize.py +++ b/twilio/rest/preview_iam/v1/authorize.py @@ -12,20 +12,15 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from typing import Any, Dict, Optional, Union +from twilio.base import values from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource from twilio.base.version import Version - class AuthorizeInstance(InstanceResource): - """ :ivar redirect_to: The callback URL """ @@ -33,95 +28,99 @@ class AuthorizeInstance(InstanceResource): def __init__(self, version: Version, payload: Dict[str, Any]): super().__init__(version) - self.redirect_to: Optional[str] = payload.get("redirect_to") - - - def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - - return '' - + return "" class AuthorizeList(ListResource): - + def __init__(self, version: Version): """ Initialize the AuthorizeList :param version: Version that contains the resource - + """ super().__init__(version) - - self._uri = '/authorize' - - - - def fetch(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: + self._uri = "/authorize" + + def fetch( + self, + response_type: Union[str, object] = values.unset, + client_id: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + state: Union[str, object] = values.unset, + ) -> AuthorizeInstance: """ Asynchronously fetch the AuthorizeInstance :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback :returns: The fetched AuthorizeInstance """ - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - params = values.of({ - 'response_type': response_type, - 'client_id': client_id, - 'redirect_uri': redirect_uri, - 'scope': scope, - 'state': state, - - }) - - payload = self._version.fetch(method='GET', uri=self._uri, headers=headers, params=params) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + params = values.of( + { + "response_type": response_type, + "client_id": client_id, + "redirect_uri": redirect_uri, + "scope": scope, + "state": state, + } + ) + + payload = self._version.fetch( + method="GET", uri=self._uri, headers=headers, params=params + ) return AuthorizeInstance(self._version, payload) - async def fetch_async(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: + async def fetch_async( + self, + response_type: Union[str, object] = values.unset, + client_id: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + state: Union[str, object] = values.unset, + ) -> AuthorizeInstance: """ Asynchronously fetch the AuthorizeInstance :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback :returns: The fetched AuthorizeInstance """ - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - params = values.of({ - 'response_type': response_type, - 'client_id': client_id, - 'redirect_uri': redirect_uri, - 'scope': scope, - 'state': state, - - }) - - payload = await self._version.fetch_async(method='GET', uri=self._uri, headers=headers, params=params) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + params = values.of( + { + "response_type": response_type, + "client_id": client_id, + "redirect_uri": redirect_uri, + "scope": scope, + "state": state, + } + ) + + payload = await self._version.fetch_async( + method="GET", uri=self._uri, headers=headers, params=params + ) return AuthorizeInstance(self._version, payload) - - def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - return '' - + return "" diff --git a/twilio/rest/preview_iam/v1/token.py b/twilio/rest/preview_iam/v1/token.py index d6d7fc463..81eed237f 100644 --- a/twilio/rest/preview_iam/v1/token.py +++ b/twilio/rest/preview_iam/v1/token.py @@ -12,70 +12,66 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from typing import Any, Dict, Optional, Union +from twilio.base import values from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource from twilio.base.version import Version - class TokenInstance(InstanceResource): - """ :ivar access_token: Token which carries the necessary information to access a Twilio resource directly. :ivar refresh_token: Token which carries the information necessary to get a new access token. :ivar id_token: Token which carries the information necessary of user profile. :ivar token_type: Token type - :ivar expires_in: + :ivar expires_in: """ def __init__(self, version: Version, payload: Dict[str, Any]): super().__init__(version) - self.access_token: Optional[str] = payload.get("access_token") self.refresh_token: Optional[str] = payload.get("refresh_token") self.id_token: Optional[str] = payload.get("id_token") self.token_type: Optional[str] = payload.get("token_type") self.expires_in: Optional[int] = payload.get("expires_in") - - - def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - - return '' - + return "" class TokenList(ListResource): - + def __init__(self, version: Version): """ Initialize the TokenList :param version: Version that contains the resource - + """ super().__init__(version) - - self._uri = '/token' - - - - def create(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + self._uri = "/token" + + def create( + self, + grant_type: str, + client_id: str, + client_secret: Union[str, object] = values.unset, + code: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + audience: Union[str, object] = values.unset, + refresh_token: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + ) -> TokenInstance: """ Create the TokenInstance @@ -87,30 +83,41 @@ def create(self, grant_type: str, client_id: str, client_secret: Union[str, obje :param audience: The targeted audience uri :param refresh_token: JWT token related to refresh access token. :param scope: The scope of token - + :returns: The created TokenInstance """ - - data = values.of({ - 'grant_type': grant_type, - 'client_id': client_id, - 'client_secret': client_secret, - 'code': code, - 'redirect_uri': redirect_uri, - 'audience': audience, - 'refresh_token': refresh_token, - 'scope': scope, - }) - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - - payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) + + data = values.of( + { + "grant_type": grant_type, + "client_id": client_id, + "client_secret": client_secret, + "code": code, + "redirect_uri": redirect_uri, + "audience": audience, + "refresh_token": refresh_token, + "scope": scope, + } + ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) return TokenInstance(self._version, payload) - async def create_async(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + async def create_async( + self, + grant_type: str, + client_id: str, + client_secret: Union[str, object] = values.unset, + code: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + audience: Union[str, object] = values.unset, + refresh_token: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + ) -> TokenInstance: """ Asynchronously create the TokenInstance @@ -122,31 +129,29 @@ async def create_async(self, grant_type: str, client_id: str, client_secret: Uni :param audience: The targeted audience uri :param refresh_token: JWT token related to refresh access token. :param scope: The scope of token - + :returns: The created TokenInstance """ - - data = values.of({ - 'grant_type': grant_type, - 'client_id': client_id, - 'client_secret': client_secret, - 'code': code, - 'redirect_uri': redirect_uri, - 'audience': audience, - 'refresh_token': refresh_token, - 'scope': scope, - }) - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - - payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) - - return TokenInstance(self._version, payload) - + data = values.of( + { + "grant_type": grant_type, + "client_id": client_id, + "client_secret": client_secret, + "code": code, + "redirect_uri": redirect_uri, + "audience": audience, + "refresh_token": refresh_token, + "scope": scope, + } + ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + return TokenInstance(self._version, payload) def __repr__(self) -> str: """ @@ -154,5 +159,4 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' - + return "" diff --git a/twilio/rest/preview_iam/versionless/__init__.py b/twilio/rest/preview_iam/versionless/__init__.py index 946f389d9..7d6d210f1 100644 --- a/twilio/rest/preview_iam/versionless/__init__.py +++ b/twilio/rest/preview_iam/versionless/__init__.py @@ -28,7 +28,7 @@ def __init__(self, domain: Domain): """ super().__init__(domain, "Organizations") self._organization: Optional[OrganizationList] = None - + @property def organization(self) -> OrganizationList: if self._organization is None: diff --git a/twilio/rest/preview_iam/versionless/organization/__init__.py b/twilio/rest/preview_iam/versionless/organization/__init__.py index 00b99a9a2..ce6e70e97 100644 --- a/twilio/rest/preview_iam/versionless/organization/__init__.py +++ b/twilio/rest/preview_iam/versionless/organization/__init__.py @@ -12,22 +12,19 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from typing import Optional from twilio.base.instance_context import InstanceContext from twilio.base.list_resource import ListResource from twilio.base.version import Version from twilio.rest.preview_iam.versionless.organization.account import AccountList -from twilio.rest.preview_iam.versionless.organization.role_assignment import RoleAssignmentList +from twilio.rest.preview_iam.versionless.organization.role_assignment import ( + RoleAssignmentList, +) from twilio.rest.preview_iam.versionless.organization.user import UserList - class OrganizationContext(InstanceContext): def __init__(self, version: Version, organization_sid: str): @@ -35,23 +32,20 @@ def __init__(self, version: Version, organization_sid: str): Initialize the OrganizationContext :param version: Version that contains the resource - :param organization_sid: + :param organization_sid: """ super().__init__(version) - # Path Solution - self._solution = { - 'organization_sid': organization_sid, + self._solution = { + "organization_sid": organization_sid, } - self._uri = '/{organization_sid}'.format(**self._solution) - + self._uri = "/{organization_sid}".format(**self._solution) + self._accounts: Optional[AccountList] = None self._role_assignments: Optional[RoleAssignmentList] = None self._users: Optional[UserList] = None - - - + @property def accounts(self) -> AccountList: """ @@ -59,11 +53,11 @@ def accounts(self) -> AccountList: """ if self._accounts is None: self._accounts = AccountList( - self._version, - self._solution['organization_sid'], + self._version, + self._solution["organization_sid"], ) return self._accounts - + @property def role_assignments(self) -> RoleAssignmentList: """ @@ -71,11 +65,11 @@ def role_assignments(self) -> RoleAssignmentList: """ if self._role_assignments is None: self._role_assignments = RoleAssignmentList( - self._version, - self._solution['organization_sid'], + self._version, + self._solution["organization_sid"], ) return self._role_assignments - + @property def users(self) -> UserList: """ @@ -83,57 +77,45 @@ def users(self) -> UserList: """ if self._users is None: self._users = UserList( - self._version, - self._solution['organization_sid'], + self._version, + self._solution["organization_sid"], ) return self._users - + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format(context) class OrganizationList(ListResource): - + def __init__(self, version: Version): """ Initialize the OrganizationList :param version: Version that contains the resource - + """ super().__init__(version) - - - - - - - - - - - def get(self, organization_sid: str) -> OrganizationContext: """ Constructs a OrganizationContext - - :param organization_sid: + + :param organization_sid: """ return OrganizationContext(self._version, organization_sid=organization_sid) def __call__(self, organization_sid: str) -> OrganizationContext: """ Constructs a OrganizationContext - - :param organization_sid: + + :param organization_sid: """ return OrganizationContext(self._version, organization_sid=organization_sid) @@ -143,5 +125,4 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' - + return "" diff --git a/twilio/rest/preview_iam/versionless/organization/account.py b/twilio/rest/preview_iam/versionless/organization/account.py index e7203f1e8..f1c801986 100644 --- a/twilio/rest/preview_iam/versionless/organization/account.py +++ b/twilio/rest/preview_iam/versionless/organization/account.py @@ -12,11 +12,9 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal +from datetime import datetime from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from twilio.base import deserialize, values from twilio.base.instance_context import InstanceContext from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource @@ -25,8 +23,6 @@ class AccountInstance(InstanceResource): - - """ :ivar account_sid: Twilio account sid :ivar friendly_name: Account friendly name @@ -35,18 +31,24 @@ class AccountInstance(InstanceResource): :ivar date_created: The date and time when the account was created in the system """ - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: str, account_sid: Optional[str] = None): + def __init__( + self, + version: Version, + payload: Dict[str, Any], + organization_sid: str, + account_sid: Optional[str] = None, + ): super().__init__(version) - self.account_sid: Optional[str] = payload.get("account_sid") self.friendly_name: Optional[str] = payload.get("friendly_name") self.status: Optional[str] = payload.get("status") self.owner_sid: Optional[str] = payload.get("owner_sid") - self.date_created: Optional[datetime] = deserialize.iso8601_datetime(payload.get("date_created")) + self.date_created: Optional[datetime] = deserialize.iso8601_datetime( + payload.get("date_created") + ) - - self._solution = { + self._solution = { "organization_sid": organization_sid, "account_sid": account_sid or self.account_sid, } @@ -61,14 +63,17 @@ def _proxy(self) -> "AccountContext": :returns: AccountContext for this AccountInstance """ if self._context is None: - self._context = AccountContext(self._version, organization_sid=self._solution['organization_sid'], account_sid=self._solution['account_sid'],) + self._context = AccountContext( + self._version, + organization_sid=self._solution["organization_sid"], + account_sid=self._solution["account_sid"], + ) return self._context - - + def fetch(self) -> "AccountInstance": """ Fetch the AccountInstance - + :returns: The fetched AccountInstance """ @@ -77,20 +82,21 @@ def fetch(self) -> "AccountInstance": async def fetch_async(self) -> "AccountInstance": """ Asynchronous coroutine to fetch the AccountInstance - + :returns: The fetched AccountInstance """ return await self._proxy.fetch_async() - + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format(context) + class AccountContext(InstanceContext): @@ -99,81 +105,72 @@ def __init__(self, version: Version, organization_sid: str, account_sid: str): Initialize the AccountContext :param version: Version that contains the resource - :param organization_sid: - :param account_sid: + :param organization_sid: + :param account_sid: """ super().__init__(version) - # Path Solution - self._solution = { - 'organization_sid': organization_sid, - 'account_sid': account_sid, + self._solution = { + "organization_sid": organization_sid, + "account_sid": account_sid, } - self._uri = '/{organization_sid}/Accounts/{account_sid}'.format(**self._solution) - - - + self._uri = "/{organization_sid}/Accounts/{account_sid}".format( + **self._solution + ) + def fetch(self) -> AccountInstance: """ Fetch the AccountInstance - + :returns: The fetched AccountInstance """ - headers = values.of({}) - - + headers["Accept"] = "application/json" - - payload = self._version.fetch(method='GET', uri=self._uri , headers=headers) + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return AccountInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - account_sid=self._solution['account_sid'], - + organization_sid=self._solution["organization_sid"], + account_sid=self._solution["account_sid"], ) async def fetch_async(self) -> AccountInstance: """ Asynchronous coroutine to fetch the AccountInstance - + :returns: The fetched AccountInstance """ - headers = values.of({}) - - + headers["Accept"] = "application/json" - - payload = await self._version.fetch_async(method='GET', uri=self._uri , headers=headers) + + payload = await self._version.fetch_async( + method="GET", uri=self._uri, headers=headers + ) return AccountInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - account_sid=self._solution['account_sid'], - + organization_sid=self._solution["organization_sid"], + account_sid=self._solution["account_sid"], ) - - + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format(context) class AccountPage(Page): @@ -184,7 +181,9 @@ def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: :param payload: Payload response from the API """ - return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + return AccountInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) def __repr__(self) -> str: """ @@ -195,31 +194,26 @@ def __repr__(self) -> str: return "" - - - class AccountList(ListResource): - + def __init__(self, version: Version, organization_sid: str): """ Initialize the AccountList :param version: Version that contains the resource - :param organization_sid: - + :param organization_sid: + """ super().__init__(version) - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/Accounts'.format(**self._solution) - - - - - def stream(self, - + self._solution = { + "organization_sid": organization_sid, + } + self._uri = "/{organization_sid}/Accounts".format(**self._solution) + + def stream( + self, limit: Optional[int] = None, page_size: Optional[int] = None, ) -> Iterator[AccountInstance]: @@ -228,7 +222,7 @@ def stream(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - + :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -239,14 +233,12 @@ def stream(self, :returns: Generator that will yield up to limit results """ limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) + page = self.page(page_size=limits["page_size"]) - return self._version.stream(page, limits['limit']) + return self._version.stream(page, limits["limit"]) - async def stream_async(self, - + async def stream_async( + self, limit: Optional[int] = None, page_size: Optional[int] = None, ) -> AsyncIterator[AccountInstance]: @@ -255,7 +247,7 @@ async def stream_async(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - + :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -266,14 +258,12 @@ async def stream_async(self, :returns: Generator that will yield up to limit results """ limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) + page = await self.page_async(page_size=limits["page_size"]) - return self._version.stream_async(page, limits['limit']) + return self._version.stream_async(page, limits["limit"]) - def list(self, - + def list( + self, limit: Optional[int] = None, page_size: Optional[int] = None, ) -> List[AccountInstance]: @@ -281,7 +271,7 @@ def list(self, Lists AccountInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - + :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -291,13 +281,15 @@ def list(self, :returns: list that will contain up to limit results """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) + return list( + self.stream( + limit=limit, + page_size=page_size, + ) + ) - async def list_async(self, - + async def list_async( + self, limit: Optional[int] = None, page_size: Optional[int] = None, ) -> List[AccountInstance]: @@ -305,7 +297,7 @@ async def list_async(self, Asynchronously lists AccountInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - + :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -315,13 +307,16 @@ async def list_async(self, :returns: list that will contain up to limit results """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] + return [ + record + async for record in await self.stream_async( + limit=limit, + page_size=page_size, + ) + ] - def page(self, - + def page( + self, page_token: Union[str, object] = values.unset, page_number: Union[int, object] = values.unset, page_size: Union[int, object] = values.unset, @@ -329,32 +324,32 @@ def page(self, """ Retrieve a single page of AccountInstance records from the API. Request is executed immediately - + :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of AccountInstance """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/json" - - response = self._version.page(method='GET', uri=self._uri, params=data, headers=headers) + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return AccountPage(self._version, response, self._solution) - async def page_async(self, - + async def page_async( + self, page_token: Union[str, object] = values.unset, page_number: Union[int, object] = values.unset, page_size: Union[int, object] = values.unset, @@ -362,28 +357,28 @@ async def page_async(self, """ Asynchronously retrieve a single page of AccountInstance records from the API. Request is executed immediately - + :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of AccountInstance """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/json" - - response = await self._version.page_async(method='GET', uri=self._uri, params=data, headers=headers) + response = await self._version.page_async( + method="GET", uri=self._uri, params=data, headers=headers + ) return AccountPage(self._version, response, self._solution) def get_page(self, target_url: str) -> AccountPage: @@ -395,10 +390,7 @@ def get_page(self, target_url: str) -> AccountPage: :returns: Page of AccountInstance """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) + response = self._version.domain.twilio.request("GET", target_url) return AccountPage(self._version, response, self._solution) async def get_page_async(self, target_url: str) -> AccountPage: @@ -410,29 +402,32 @@ async def get_page_async(self, target_url: str) -> AccountPage: :returns: Page of AccountInstance """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) + response = await self._version.domain.twilio.request_async("GET", target_url) return AccountPage(self._version, response, self._solution) - - def get(self, account_sid: str) -> AccountContext: """ Constructs a AccountContext - - :param account_sid: + + :param account_sid: """ - return AccountContext(self._version, organization_sid=self._solution['organization_sid'], account_sid=account_sid) + return AccountContext( + self._version, + organization_sid=self._solution["organization_sid"], + account_sid=account_sid, + ) def __call__(self, account_sid: str) -> AccountContext: """ Constructs a AccountContext - - :param account_sid: + + :param account_sid: """ - return AccountContext(self._version, organization_sid=self._solution['organization_sid'], account_sid=account_sid) + return AccountContext( + self._version, + organization_sid=self._solution["organization_sid"], + account_sid=account_sid, + ) def __repr__(self) -> str: """ @@ -440,5 +435,4 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' - + return "" diff --git a/twilio/rest/preview_iam/versionless/organization/role_assignment.py b/twilio/rest/preview_iam/versionless/organization/role_assignment.py index 50c2dc219..9d356f2c7 100644 --- a/twilio/rest/preview_iam/versionless/organization/role_assignment.py +++ b/twilio/rest/preview_iam/versionless/organization/role_assignment.py @@ -12,11 +12,8 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from twilio.base import values from twilio.base.instance_context import InstanceContext from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource @@ -28,28 +25,24 @@ class RoleAssignmentInstance(InstanceResource): class PublicApiCreateRoleAssignmentRequest(object): """ - :ivar role_sid: Twilio Role Sid representing assigned role - :ivar scope: Twilio Sid representing scope of this assignment - :ivar identity: Twilio Sid representing identity of this assignment + :ivar role_sid: Twilio Role Sid representing assigned role + :ivar scope: Twilio Sid representing scope of this assignment + :ivar identity: Twilio Sid representing identity of this assignment """ def __init__(self, payload: Dict[str, Any]): - self.role_sid: Optional[str] = payload.get("role_sid") self.scope: Optional[str] = payload.get("scope") self.identity: Optional[str] = payload.get("identity") def to_dict(self): return { - - "role_sid": self.role_sid, - "scope": self.scope, - "identity": self.identity, + "role_sid": self.role_sid, + "scope": self.scope, + "identity": self.identity, } - - """ :ivar sid: Twilio Role Assignment Sid representing this role assignment :ivar role_sid: Twilio Role Sid representing assigned role @@ -61,10 +54,15 @@ def to_dict(self): :ivar status: HTTP response status code """ - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: str, sid: Optional[str] = None): + def __init__( + self, + version: Version, + payload: Dict[str, Any], + organization_sid: str, + sid: Optional[str] = None, + ): super().__init__(version) - self.sid: Optional[str] = payload.get("sid") self.role_sid: Optional[str] = payload.get("role_sid") self.scope: Optional[str] = payload.get("scope") @@ -74,8 +72,7 @@ def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: self.more_info: Optional[str] = payload.get("moreInfo") self.status: Optional[int] = payload.get("status") - - self._solution = { + self._solution = { "organization_sid": organization_sid, "sid": sid or self.sid, } @@ -90,128 +87,122 @@ def _proxy(self) -> "RoleAssignmentContext": :returns: RoleAssignmentContext for this RoleAssignmentInstance """ if self._context is None: - self._context = RoleAssignmentContext(self._version, organization_sid=self._solution['organization_sid'], sid=self._solution['sid'],) + self._context = RoleAssignmentContext( + self._version, + organization_sid=self._solution["organization_sid"], + sid=self._solution["sid"], + ) return self._context - - + def delete(self) -> bool: """ Deletes the RoleAssignmentInstance - + :returns: True if delete succeeds, False otherwise """ return self._proxy.delete() + async def delete_async(self) -> bool: """ Asynchronous coroutine that deletes the RoleAssignmentInstance - + :returns: True if delete succeeds, False otherwise """ return await self._proxy.delete_async() - + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format( + context + ) + class RoleAssignmentContext(InstanceContext): class PublicApiCreateRoleAssignmentRequest(object): """ - :ivar role_sid: Twilio Role Sid representing assigned role - :ivar scope: Twilio Sid representing scope of this assignment - :ivar identity: Twilio Sid representing identity of this assignment + :ivar role_sid: Twilio Role Sid representing assigned role + :ivar scope: Twilio Sid representing scope of this assignment + :ivar identity: Twilio Sid representing identity of this assignment """ def __init__(self, payload: Dict[str, Any]): - self.role_sid: Optional[str] = payload.get("role_sid") self.scope: Optional[str] = payload.get("scope") self.identity: Optional[str] = payload.get("identity") def to_dict(self): return { - - "role_sid": self.role_sid, - "scope": self.scope, - "identity": self.identity, + "role_sid": self.role_sid, + "scope": self.scope, + "identity": self.identity, } - def __init__(self, version: Version, organization_sid: str, sid: str): """ Initialize the RoleAssignmentContext :param version: Version that contains the resource - :param organization_sid: - :param sid: + :param organization_sid: + :param sid: """ super().__init__(version) - # Path Solution - self._solution = { - 'organization_sid': organization_sid, - 'sid': sid, + self._solution = { + "organization_sid": organization_sid, + "sid": sid, } - self._uri = '/{organization_sid}/RoleAssignments/{sid}'.format(**self._solution) - - - + self._uri = "/{organization_sid}/RoleAssignments/{sid}".format(**self._solution) + def delete(self) -> bool: """ Deletes the RoleAssignmentInstance - + :returns: True if delete succeeds, False otherwise """ - headers = values.of({}) - - - + headers["Accept"] = "application/scim+json" - - return self._version.delete(method='DELETE', uri=self._uri, headers=headers) + + return self._version.delete(method="DELETE", uri=self._uri, headers=headers) async def delete_async(self) -> bool: """ Asynchronous coroutine that deletes the RoleAssignmentInstance - + :returns: True if delete succeeds, False otherwise """ - + headers = values.of({}) - - - + headers["Accept"] = "application/scim+json" - - return await self._version.delete_async(method='DELETE', uri=self._uri, headers=headers) - - + + return await self._version.delete_async( + method="DELETE", uri=self._uri, headers=headers + ) + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - - - + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format( + context + ) class RoleAssignmentPage(Page): @@ -222,7 +213,9 @@ def get_instance(self, payload: Dict[str, Any]) -> RoleAssignmentInstance: :param payload: Payload response from the API """ - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + return RoleAssignmentInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) def __repr__(self) -> str: """ @@ -233,103 +226,100 @@ def __repr__(self) -> str: return "" - - - class RoleAssignmentList(ListResource): - + class PublicApiCreateRoleAssignmentRequest(object): """ - :ivar role_sid: Twilio Role Sid representing assigned role - :ivar scope: Twilio Sid representing scope of this assignment - :ivar identity: Twilio Sid representing identity of this assignment + :ivar role_sid: Twilio Role Sid representing assigned role + :ivar scope: Twilio Sid representing scope of this assignment + :ivar identity: Twilio Sid representing identity of this assignment """ def __init__(self, payload: Dict[str, Any]): - self.role_sid: Optional[str] = payload.get("role_sid") self.scope: Optional[str] = payload.get("scope") self.identity: Optional[str] = payload.get("identity") def to_dict(self): return { - - "role_sid": self.role_sid, - "scope": self.scope, - "identity": self.identity, + "role_sid": self.role_sid, + "scope": self.scope, + "identity": self.identity, } - def __init__(self, version: Version, organization_sid: str): """ Initialize the RoleAssignmentList :param version: Version that contains the resource - :param organization_sid: - + :param organization_sid: + """ super().__init__(version) - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/RoleAssignments'.format(**self._solution) - - - - - def create(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: + self._solution = { + "organization_sid": organization_sid, + } + self._uri = "/{organization_sid}/RoleAssignments".format(**self._solution) + + def create( + self, + public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest, + ) -> RoleAssignmentInstance: """ Create the RoleAssignmentInstance - :param public_api_create_role_assignment_request: - + :param public_api_create_role_assignment_request: + :returns: The created RoleAssignmentInstance """ data = public_api_create_role_assignment_request.to_dict() - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/json" - - + headers["Accept"] = "application/json" - - - payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return RoleAssignmentInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) - async def create_async(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: + async def create_async( + self, + public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest, + ) -> RoleAssignmentInstance: """ Asynchronously create the RoleAssignmentInstance - :param public_api_create_role_assignment_request: - + :param public_api_create_role_assignment_request: + :returns: The created RoleAssignmentInstance """ data = public_api_create_role_assignment_request.to_dict() - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/json" - - + headers["Accept"] = "application/json" - - - payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) - - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) - - - def stream(self, - + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return RoleAssignmentInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) + + def stream( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, limit: Optional[int] = None, @@ -340,9 +330,9 @@ def stream(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - - :param str identity: - :param str scope: + + :param str identity: + :param str scope: :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -353,16 +343,12 @@ def stream(self, :returns: Generator that will yield up to limit results """ limits = self._version.read_limits(limit, page_size) - page = self.page( - identity=identity, - scope=scope, - page_size=limits['page_size'] - ) + page = self.page(identity=identity, scope=scope, page_size=limits["page_size"]) - return self._version.stream(page, limits['limit']) + return self._version.stream(page, limits["limit"]) - async def stream_async(self, - + async def stream_async( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, limit: Optional[int] = None, @@ -373,9 +359,9 @@ async def stream_async(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - - :param str identity: - :param str scope: + + :param str identity: + :param str scope: :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -387,15 +373,13 @@ async def stream_async(self, """ limits = self._version.read_limits(limit, page_size) page = await self.page_async( - identity=identity, - scope=scope, - page_size=limits['page_size'] + identity=identity, scope=scope, page_size=limits["page_size"] ) - return self._version.stream_async(page, limits['limit']) + return self._version.stream_async(page, limits["limit"]) - def list(self, - + def list( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, limit: Optional[int] = None, @@ -405,9 +389,9 @@ def list(self, Lists RoleAssignmentInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - - :param str identity: - :param str scope: + + :param str identity: + :param str scope: :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -417,15 +401,17 @@ def list(self, :returns: list that will contain up to limit results """ - return list(self.stream( - identity=identity, - scope=scope, - limit=limit, - page_size=page_size, - )) + return list( + self.stream( + identity=identity, + scope=scope, + limit=limit, + page_size=page_size, + ) + ) - async def list_async(self, - + async def list_async( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, limit: Optional[int] = None, @@ -435,9 +421,9 @@ async def list_async(self, Asynchronously lists RoleAssignmentInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - - :param str identity: - :param str scope: + + :param str identity: + :param str scope: :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -447,15 +433,18 @@ async def list_async(self, :returns: list that will contain up to limit results """ - return [record async for record in await self.stream_async( - identity=identity, - scope=scope, - limit=limit, - page_size=page_size, - )] - - def page(self, - + return [ + record + async for record in await self.stream_async( + identity=identity, + scope=scope, + limit=limit, + page_size=page_size, + ) + ] + + def page( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, page_token: Union[str, object] = values.unset, @@ -465,36 +454,36 @@ def page(self, """ Retrieve a single page of RoleAssignmentInstance records from the API. Request is executed immediately - - :param identity: - :param scope: + + :param identity: + :param scope: :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of RoleAssignmentInstance """ - data = values.of({ - 'Identity': identity, - 'Scope': scope, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "Identity": identity, + "Scope": scope, + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/json" - - response = self._version.page(method='GET', uri=self._uri, params=data, headers=headers) + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return RoleAssignmentPage(self._version, response, self._solution) - async def page_async(self, - + async def page_async( + self, identity: Union[str, object] = values.unset, scope: Union[str, object] = values.unset, page_token: Union[str, object] = values.unset, @@ -504,32 +493,32 @@ async def page_async(self, """ Asynchronously retrieve a single page of RoleAssignmentInstance records from the API. Request is executed immediately - - :param identity: - :param scope: + + :param identity: + :param scope: :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of RoleAssignmentInstance """ - data = values.of({ - 'Identity': identity, - 'Scope': scope, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "Identity": identity, + "Scope": scope, + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/json" - - response = await self._version.page_async(method='GET', uri=self._uri, params=data, headers=headers) + response = await self._version.page_async( + method="GET", uri=self._uri, params=data, headers=headers + ) return RoleAssignmentPage(self._version, response, self._solution) def get_page(self, target_url: str) -> RoleAssignmentPage: @@ -541,10 +530,7 @@ def get_page(self, target_url: str) -> RoleAssignmentPage: :returns: Page of RoleAssignmentInstance """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) + response = self._version.domain.twilio.request("GET", target_url) return RoleAssignmentPage(self._version, response, self._solution) async def get_page_async(self, target_url: str) -> RoleAssignmentPage: @@ -556,29 +542,28 @@ async def get_page_async(self, target_url: str) -> RoleAssignmentPage: :returns: Page of RoleAssignmentInstance """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) + response = await self._version.domain.twilio.request_async("GET", target_url) return RoleAssignmentPage(self._version, response, self._solution) - - def get(self, sid: str) -> RoleAssignmentContext: """ Constructs a RoleAssignmentContext - - :param sid: + + :param sid: """ - return RoleAssignmentContext(self._version, organization_sid=self._solution['organization_sid'], sid=sid) + return RoleAssignmentContext( + self._version, organization_sid=self._solution["organization_sid"], sid=sid + ) def __call__(self, sid: str) -> RoleAssignmentContext: """ Constructs a RoleAssignmentContext - - :param sid: + + :param sid: """ - return RoleAssignmentContext(self._version, organization_sid=self._solution['organization_sid'], sid=sid) + return RoleAssignmentContext( + self._version, organization_sid=self._solution["organization_sid"], sid=sid + ) def __repr__(self) -> str: """ @@ -586,5 +571,4 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' - + return "" diff --git a/twilio/rest/preview_iam/versionless/organization/user.py b/twilio/rest/preview_iam/versionless/organization/user.py index 038d110b4..166f76b42 100644 --- a/twilio/rest/preview_iam/versionless/organization/user.py +++ b/twilio/rest/preview_iam/versionless/organization/user.py @@ -12,11 +12,9 @@ Do not edit the class manually. """ - -from datetime import date, datetime -from decimal import Decimal +from datetime import datetime from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values +from twilio.base import values from twilio.base.instance_context import InstanceContext from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource @@ -28,37 +26,34 @@ class UserInstance(InstanceResource): class ScimEmailAddress(object): """ - :ivar primary: Indicates if this email address is the primary one - :ivar value: The actual email address value - :ivar type: The type of email address (e.g., work, home, etc.) + :ivar primary: Indicates if this email address is the primary one + :ivar value: The actual email address value + :ivar type: The type of email address (e.g., work, home, etc.) """ def __init__(self, payload: Dict[str, Any]): - self.primary: Optional[bool] = payload.get("primary") self.value: Optional[str] = payload.get("value") self.type: Optional[str] = payload.get("type") def to_dict(self): return { - - "primary": self.primary, - "value": self.value, - "type": self.type, + "primary": self.primary, + "value": self.value, + "type": self.type, } class ScimMeta(object): """ - :ivar resource_type: Indicates the type of the resource - :ivar created: The date and time when the resource was created in the system - :ivar last_modified: The date and time when the resource was last modified - :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. + :ivar resource_type: Indicates the type of the resource + :ivar created: The date and time when the resource was created in the system + :ivar last_modified: The date and time when the resource was last modified + :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. """ def __init__(self, payload: Dict[str, Any]): - self.resource_type: Optional[str] = payload.get("resource_type") self.created: Optional[datetime] = payload.get("created") self.last_modified: Optional[datetime] = payload.get("last_modified") @@ -66,61 +61,59 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "resource_type": self.resource_type, - "created": self.created, - "last_modified": self.last_modified, - "version": self.version, + "resource_type": self.resource_type, + "created": self.created, + "last_modified": self.last_modified, + "version": self.version, } class ScimName(object): """ - :ivar given_name: The user's first or given name - :ivar family_name: The user's last or family name + :ivar given_name: The user's first or given name + :ivar family_name: The user's last or family name """ def __init__(self, payload: Dict[str, Any]): - self.given_name: Optional[str] = payload.get("given_name") self.family_name: Optional[str] = payload.get("family_name") def to_dict(self): return { - - "given_name": self.given_name, - "family_name": self.family_name, + "given_name": self.given_name, + "family_name": self.family_name, } class ScimUser(object): """ - :ivar id: Unique Twilio user sid - :ivar external_id: External unique resource id defined by provisioning client - :ivar user_name: Unique username, MUST be same as primary email address - :ivar display_name: User friendly display name - :ivar name: - :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - :ivar active: Indicates whether the user is active - :ivar locale: User's locale - :ivar timezone: User's time zone - :ivar schemas: An array of URIs that indicate the schemas supported for this user resource - :ivar meta: - :ivar detail: A human-readable description of the error - :ivar scim_type: A scimType error code as defined in RFC7644 - :ivar status: Http status code - :ivar code: Twilio-specific error code - :ivar more_info: Link to Error Code References + :ivar id: Unique Twilio user sid + :ivar external_id: External unique resource id defined by provisioning client + :ivar user_name: Unique username, MUST be same as primary email address + :ivar display_name: User friendly display name + :ivar name: + :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. + :ivar active: Indicates whether the user is active + :ivar locale: User's locale + :ivar timezone: User's time zone + :ivar schemas: An array of URIs that indicate the schemas supported for this user resource + :ivar meta: + :ivar detail: A human-readable description of the error + :ivar scim_type: A scimType error code as defined in RFC7644 + :ivar status: Http status code + :ivar code: Twilio-specific error code + :ivar more_info: Link to Error Code References """ def __init__(self, payload: Dict[str, Any]): - self.id: Optional[str] = payload.get("id") self.external_id: Optional[str] = payload.get("external_id") self.user_name: Optional[str] = payload.get("user_name") self.display_name: Optional[str] = payload.get("display_name") self.name: Optional[UserList.ScimName] = payload.get("name") - self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get("emails") + self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get( + "emails" + ) self.active: Optional[bool] = payload.get("active") self.locale: Optional[str] = payload.get("locale") self.timezone: Optional[str] = payload.get("timezone") @@ -134,27 +127,28 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "id": self.id, - "externalId": self.external_id, - "userName": self.user_name, - "displayName": self.display_name, - "name": self.name.to_dict() if self.name is not None else None , - "emails": [emails.to_dict() for emails in self.emails] if self.emails is not None else None, - "active": self.active, - "locale": self.locale, - "timezone": self.timezone, - "schemas": self.schemas, - "meta": self.meta.to_dict() if self.meta is not None else None , - "detail": self.detail, - "scimType": self.scim_type, - "status": self.status, - "code": self.code, - "moreInfo": self.more_info, + "id": self.id, + "externalId": self.external_id, + "userName": self.user_name, + "displayName": self.display_name, + "name": self.name.to_dict() if self.name is not None else None, + "emails": ( + [emails.to_dict() for emails in self.emails] + if self.emails is not None + else None + ), + "active": self.active, + "locale": self.locale, + "timezone": self.timezone, + "schemas": self.schemas, + "meta": self.meta.to_dict() if self.meta is not None else None, + "detail": self.detail, + "scimType": self.scim_type, + "status": self.status, + "code": self.code, + "moreInfo": self.more_info, } - - """ :ivar id: Unique Twilio user sid :ivar external_id: External unique resource id defined by provisioning client @@ -174,10 +168,15 @@ def to_dict(self): :ivar more_info: Link to Error Code References """ - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: str, id: Optional[str] = None): + def __init__( + self, + version: Version, + payload: Dict[str, Any], + organization_sid: str, + id: Optional[str] = None, + ): super().__init__(version) - self.id: Optional[str] = payload.get("id") self.external_id: Optional[str] = payload.get("externalId") self.user_name: Optional[str] = payload.get("userName") @@ -195,8 +194,7 @@ def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: self.code: Optional[int] = payload.get("code") self.more_info: Optional[str] = payload.get("moreInfo") - - self._solution = { + self._solution = { "organization_sid": organization_sid, "id": id or self.id, } @@ -211,32 +209,35 @@ def _proxy(self) -> "UserContext": :returns: UserContext for this UserInstance """ if self._context is None: - self._context = UserContext(self._version, organization_sid=self._solution['organization_sid'], id=self._solution['id'],) + self._context = UserContext( + self._version, + organization_sid=self._solution["organization_sid"], + id=self._solution["id"], + ) return self._context - - + def delete(self) -> bool: """ Deletes the UserInstance - + :returns: True if delete succeeds, False otherwise """ return self._proxy.delete() + async def delete_async(self) -> bool: """ Asynchronous coroutine that deletes the UserInstance - + :returns: True if delete succeeds, False otherwise """ return await self._proxy.delete_async() - - + def fetch(self) -> "UserInstance": """ Fetch the UserInstance - + :returns: The fetched UserInstance """ @@ -245,79 +246,86 @@ def fetch(self) -> "UserInstance": async def fetch_async(self) -> "UserInstance": """ Asynchronous coroutine to fetch the UserInstance - + :returns: The fetched UserInstance """ return await self._proxy.fetch_async() - - - def update(self, scim_user: ScimUser, if_match: Union[str, object]=values.unset) -> "UserInstance": + + def update( + self, scim_user: ScimUser, if_match: Union[str, object] = values.unset + ) -> "UserInstance": """ Update the UserInstance - - :param scim_user: - :param if_match: + + :param scim_user: + :param if_match: :returns: The updated UserInstance """ - return self._proxy.update(scim_user=scim_user, if_match=if_match, ) + return self._proxy.update( + scim_user=scim_user, + if_match=if_match, + ) - async def update_async(self, scim_user: ScimUser, if_match: Union[str, object]=values.unset) -> "UserInstance": + async def update_async( + self, scim_user: ScimUser, if_match: Union[str, object] = values.unset + ) -> "UserInstance": """ Asynchronous coroutine to update the UserInstance - - :param scim_user: - :param if_match: + + :param scim_user: + :param if_match: :returns: The updated UserInstance """ - return await self._proxy.update_async(scim_user=scim_user, if_match=if_match, ) - + return await self._proxy.update_async( + scim_user=scim_user, + if_match=if_match, + ) + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format(context) + class UserContext(InstanceContext): class ScimEmailAddress(object): """ - :ivar primary: Indicates if this email address is the primary one - :ivar value: The actual email address value - :ivar type: The type of email address (e.g., work, home, etc.) + :ivar primary: Indicates if this email address is the primary one + :ivar value: The actual email address value + :ivar type: The type of email address (e.g., work, home, etc.) """ def __init__(self, payload: Dict[str, Any]): - self.primary: Optional[bool] = payload.get("primary") self.value: Optional[str] = payload.get("value") self.type: Optional[str] = payload.get("type") def to_dict(self): return { - - "primary": self.primary, - "value": self.value, - "type": self.type, + "primary": self.primary, + "value": self.value, + "type": self.type, } class ScimMeta(object): """ - :ivar resource_type: Indicates the type of the resource - :ivar created: The date and time when the resource was created in the system - :ivar last_modified: The date and time when the resource was last modified - :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. + :ivar resource_type: Indicates the type of the resource + :ivar created: The date and time when the resource was created in the system + :ivar last_modified: The date and time when the resource was last modified + :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. """ def __init__(self, payload: Dict[str, Any]): - self.resource_type: Optional[str] = payload.get("resource_type") self.created: Optional[datetime] = payload.get("created") self.last_modified: Optional[datetime] = payload.get("last_modified") @@ -325,61 +333,59 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "resource_type": self.resource_type, - "created": self.created, - "last_modified": self.last_modified, - "version": self.version, + "resource_type": self.resource_type, + "created": self.created, + "last_modified": self.last_modified, + "version": self.version, } class ScimName(object): """ - :ivar given_name: The user's first or given name - :ivar family_name: The user's last or family name + :ivar given_name: The user's first or given name + :ivar family_name: The user's last or family name """ def __init__(self, payload: Dict[str, Any]): - self.given_name: Optional[str] = payload.get("given_name") self.family_name: Optional[str] = payload.get("family_name") def to_dict(self): return { - - "given_name": self.given_name, - "family_name": self.family_name, + "given_name": self.given_name, + "family_name": self.family_name, } class ScimUser(object): """ - :ivar id: Unique Twilio user sid - :ivar external_id: External unique resource id defined by provisioning client - :ivar user_name: Unique username, MUST be same as primary email address - :ivar display_name: User friendly display name - :ivar name: - :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - :ivar active: Indicates whether the user is active - :ivar locale: User's locale - :ivar timezone: User's time zone - :ivar schemas: An array of URIs that indicate the schemas supported for this user resource - :ivar meta: - :ivar detail: A human-readable description of the error - :ivar scim_type: A scimType error code as defined in RFC7644 - :ivar status: Http status code - :ivar code: Twilio-specific error code - :ivar more_info: Link to Error Code References + :ivar id: Unique Twilio user sid + :ivar external_id: External unique resource id defined by provisioning client + :ivar user_name: Unique username, MUST be same as primary email address + :ivar display_name: User friendly display name + :ivar name: + :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. + :ivar active: Indicates whether the user is active + :ivar locale: User's locale + :ivar timezone: User's time zone + :ivar schemas: An array of URIs that indicate the schemas supported for this user resource + :ivar meta: + :ivar detail: A human-readable description of the error + :ivar scim_type: A scimType error code as defined in RFC7644 + :ivar status: Http status code + :ivar code: Twilio-specific error code + :ivar more_info: Link to Error Code References """ def __init__(self, payload: Dict[str, Any]): - self.id: Optional[str] = payload.get("id") self.external_id: Optional[str] = payload.get("external_id") self.user_name: Optional[str] = payload.get("user_name") self.display_name: Optional[str] = payload.get("display_name") self.name: Optional[UserList.ScimName] = payload.get("name") - self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get("emails") + self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get( + "emails" + ) self.active: Optional[bool] = payload.get("active") self.locale: Optional[str] = payload.get("locale") self.timezone: Optional[str] = payload.get("timezone") @@ -393,216 +399,201 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "id": self.id, - "externalId": self.external_id, - "userName": self.user_name, - "displayName": self.display_name, - "name": self.name.to_dict() if self.name is not None else None , - "emails": [emails.to_dict() for emails in self.emails] if self.emails is not None else None, - "active": self.active, - "locale": self.locale, - "timezone": self.timezone, - "schemas": self.schemas, - "meta": self.meta.to_dict() if self.meta is not None else None , - "detail": self.detail, - "scimType": self.scim_type, - "status": self.status, - "code": self.code, - "moreInfo": self.more_info, + "id": self.id, + "externalId": self.external_id, + "userName": self.user_name, + "displayName": self.display_name, + "name": self.name.to_dict() if self.name is not None else None, + "emails": ( + [emails.to_dict() for emails in self.emails] + if self.emails is not None + else None + ), + "active": self.active, + "locale": self.locale, + "timezone": self.timezone, + "schemas": self.schemas, + "meta": self.meta.to_dict() if self.meta is not None else None, + "detail": self.detail, + "scimType": self.scim_type, + "status": self.status, + "code": self.code, + "moreInfo": self.more_info, } - def __init__(self, version: Version, organization_sid: str, id: str): """ Initialize the UserContext :param version: Version that contains the resource - :param organization_sid: - :param id: + :param organization_sid: + :param id: """ super().__init__(version) - # Path Solution - self._solution = { - 'organization_sid': organization_sid, - 'id': id, + self._solution = { + "organization_sid": organization_sid, + "id": id, } - self._uri = '/{organization_sid}/scim/Users/{id}'.format(**self._solution) - - - + self._uri = "/{organization_sid}/scim/Users/{id}".format(**self._solution) + def delete(self) -> bool: """ Deletes the UserInstance - + :returns: True if delete succeeds, False otherwise """ - headers = values.of({}) - - - + headers["Accept"] = "application/scim+json" - - return self._version.delete(method='DELETE', uri=self._uri, headers=headers) + + return self._version.delete(method="DELETE", uri=self._uri, headers=headers) async def delete_async(self) -> bool: """ Asynchronous coroutine that deletes the UserInstance - + :returns: True if delete succeeds, False otherwise """ - + headers = values.of({}) - - - + headers["Accept"] = "application/scim+json" - - return await self._version.delete_async(method='DELETE', uri=self._uri, headers=headers) - - + + return await self._version.delete_async( + method="DELETE", uri=self._uri, headers=headers + ) + def fetch(self) -> UserInstance: """ Fetch the UserInstance - + :returns: The fetched UserInstance """ - headers = values.of({}) - - + headers["Accept"] = "application/scim+json" - - payload = self._version.fetch(method='GET', uri=self._uri , headers=headers) + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return UserInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - id=self._solution['id'], - + organization_sid=self._solution["organization_sid"], + id=self._solution["id"], ) async def fetch_async(self) -> UserInstance: """ Asynchronous coroutine to fetch the UserInstance - + :returns: The fetched UserInstance """ - headers = values.of({}) - - + headers["Accept"] = "application/scim+json" - - payload = await self._version.fetch_async(method='GET', uri=self._uri , headers=headers) + + payload = await self._version.fetch_async( + method="GET", uri=self._uri, headers=headers + ) return UserInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - id=self._solution['id'], - + organization_sid=self._solution["organization_sid"], + id=self._solution["id"], ) - - - def update(self, scim_user: ScimUser, if_match: Union[str, object]=values.unset) -> UserInstance: + + def update( + self, scim_user: ScimUser, if_match: Union[str, object] = values.unset + ) -> UserInstance: """ Update the UserInstance - - :param scim_user: - :param if_match: + + :param scim_user: + :param if_match: :returns: The updated UserInstance """ data = scim_user.to_dict() - + headers = values.of({}) - - - if not (if_match is values.unset or (isinstance(if_match, str) and not if_match)): - headers['If-Match'] = if_match - + + if not ( + if_match is values.unset or (isinstance(if_match, str) and not if_match) + ): + headers["If-Match"] = if_match + headers["Content-Type"] = "application/json" - + headers["Content-Type"] = "application/scim+json" - - + headers["Accept"] = "application/scim+json" - - payload = self._version.update(method='PUT', uri=self._uri, data=data, headers=headers) + payload = self._version.update( + method="PUT", uri=self._uri, data=data, headers=headers + ) return UserInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - id=self._solution['id'] + organization_sid=self._solution["organization_sid"], + id=self._solution["id"], ) - async def update_async(self, scim_user: ScimUser, if_match: Union[str, object]=values.unset) -> UserInstance: + async def update_async( + self, scim_user: ScimUser, if_match: Union[str, object] = values.unset + ) -> UserInstance: """ Asynchronous coroutine to update the UserInstance - - :param scim_user: - :param if_match: + + :param scim_user: + :param if_match: :returns: The updated UserInstance """ data = scim_user.to_dict() - + headers = values.of({}) - - - if not (if_match is values.unset or (isinstance(if_match, str) and not if_match)): - headers['If-Match'] = if_match - - + + if not ( + if_match is values.unset or (isinstance(if_match, str) and not if_match) + ): + headers["If-Match"] = if_match + headers["Content-Type"] = "application/json" - + headers["Content-Type"] = "application/scim+json" - - + headers["Accept"] = "application/scim+json" - - payload = await self._version.update_async(method='PUT', uri=self._uri, data=data, headers=headers) + payload = await self._version.update_async( + method="PUT", uri=self._uri, data=data, headers=headers + ) return UserInstance( self._version, payload, - organization_sid=self._solution['organization_sid'], - id=self._solution['id'] + organization_sid=self._solution["organization_sid"], + id=self._solution["id"], ) - - + def __repr__(self) -> str: """ Provide a friendly representation :returns: Machine friendly representation """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - - - - - - - + context = " ".join("{}={}".format(k, v) for k, v in self._solution.items()) + return "".format(context) class UserPage(Page): @@ -613,7 +604,9 @@ def get_instance(self, payload: Dict[str, Any]) -> UserInstance: :param payload: Payload response from the API """ - return UserInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + return UserInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) def __repr__(self) -> str: """ @@ -624,44 +617,38 @@ def __repr__(self) -> str: return "" - - - class UserList(ListResource): - + class ScimEmailAddress(object): """ - :ivar primary: Indicates if this email address is the primary one - :ivar value: The actual email address value - :ivar type: The type of email address (e.g., work, home, etc.) + :ivar primary: Indicates if this email address is the primary one + :ivar value: The actual email address value + :ivar type: The type of email address (e.g., work, home, etc.) """ def __init__(self, payload: Dict[str, Any]): - self.primary: Optional[bool] = payload.get("primary") self.value: Optional[str] = payload.get("value") self.type: Optional[str] = payload.get("type") def to_dict(self): return { - - "primary": self.primary, - "value": self.value, - "type": self.type, + "primary": self.primary, + "value": self.value, + "type": self.type, } class ScimMeta(object): """ - :ivar resource_type: Indicates the type of the resource - :ivar created: The date and time when the resource was created in the system - :ivar last_modified: The date and time when the resource was last modified - :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. + :ivar resource_type: Indicates the type of the resource + :ivar created: The date and time when the resource was created in the system + :ivar last_modified: The date and time when the resource was last modified + :ivar version: A version identifier for the resource. This can be used to manage resource versioning and concurrency control. """ def __init__(self, payload: Dict[str, Any]): - self.resource_type: Optional[str] = payload.get("resource_type") self.created: Optional[datetime] = payload.get("created") self.last_modified: Optional[datetime] = payload.get("last_modified") @@ -669,61 +656,59 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "resource_type": self.resource_type, - "created": self.created, - "last_modified": self.last_modified, - "version": self.version, + "resource_type": self.resource_type, + "created": self.created, + "last_modified": self.last_modified, + "version": self.version, } class ScimName(object): """ - :ivar given_name: The user's first or given name - :ivar family_name: The user's last or family name + :ivar given_name: The user's first or given name + :ivar family_name: The user's last or family name """ def __init__(self, payload: Dict[str, Any]): - self.given_name: Optional[str] = payload.get("given_name") self.family_name: Optional[str] = payload.get("family_name") def to_dict(self): return { - - "given_name": self.given_name, - "family_name": self.family_name, + "given_name": self.given_name, + "family_name": self.family_name, } class ScimUser(object): """ - :ivar id: Unique Twilio user sid - :ivar external_id: External unique resource id defined by provisioning client - :ivar user_name: Unique username, MUST be same as primary email address - :ivar display_name: User friendly display name - :ivar name: - :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - :ivar active: Indicates whether the user is active - :ivar locale: User's locale - :ivar timezone: User's time zone - :ivar schemas: An array of URIs that indicate the schemas supported for this user resource - :ivar meta: - :ivar detail: A human-readable description of the error - :ivar scim_type: A scimType error code as defined in RFC7644 - :ivar status: Http status code - :ivar code: Twilio-specific error code - :ivar more_info: Link to Error Code References + :ivar id: Unique Twilio user sid + :ivar external_id: External unique resource id defined by provisioning client + :ivar user_name: Unique username, MUST be same as primary email address + :ivar display_name: User friendly display name + :ivar name: + :ivar emails: Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. + :ivar active: Indicates whether the user is active + :ivar locale: User's locale + :ivar timezone: User's time zone + :ivar schemas: An array of URIs that indicate the schemas supported for this user resource + :ivar meta: + :ivar detail: A human-readable description of the error + :ivar scim_type: A scimType error code as defined in RFC7644 + :ivar status: Http status code + :ivar code: Twilio-specific error code + :ivar more_info: Link to Error Code References """ def __init__(self, payload: Dict[str, Any]): - self.id: Optional[str] = payload.get("id") self.external_id: Optional[str] = payload.get("external_id") self.user_name: Optional[str] = payload.get("user_name") self.display_name: Optional[str] = payload.get("display_name") self.name: Optional[UserList.ScimName] = payload.get("name") - self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get("emails") + self.emails: Optional[List[UserList.ScimEmailAddress]] = payload.get( + "emails" + ) self.active: Optional[bool] = payload.get("active") self.locale: Optional[str] = payload.get("locale") self.timezone: Optional[str] = payload.get("timezone") @@ -737,100 +722,98 @@ def __init__(self, payload: Dict[str, Any]): def to_dict(self): return { - - "id": self.id, - "externalId": self.external_id, - "userName": self.user_name, - "displayName": self.display_name, - "name": self.name.to_dict() if self.name is not None else None , - "emails": [emails.to_dict() for emails in self.emails] if self.emails is not None else None, - "active": self.active, - "locale": self.locale, - "timezone": self.timezone, - "schemas": self.schemas, - "meta": self.meta.to_dict() if self.meta is not None else None , - "detail": self.detail, - "scimType": self.scim_type, - "status": self.status, - "code": self.code, - "moreInfo": self.more_info, + "id": self.id, + "externalId": self.external_id, + "userName": self.user_name, + "displayName": self.display_name, + "name": self.name.to_dict() if self.name is not None else None, + "emails": ( + [emails.to_dict() for emails in self.emails] + if self.emails is not None + else None + ), + "active": self.active, + "locale": self.locale, + "timezone": self.timezone, + "schemas": self.schemas, + "meta": self.meta.to_dict() if self.meta is not None else None, + "detail": self.detail, + "scimType": self.scim_type, + "status": self.status, + "code": self.code, + "moreInfo": self.more_info, } - def __init__(self, version: Version, organization_sid: str): """ Initialize the UserList :param version: Version that contains the resource - :param organization_sid: - + :param organization_sid: + """ super().__init__(version) - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/scim/Users'.format(**self._solution) - - - - - - + self._solution = { + "organization_sid": organization_sid, + } + self._uri = "/{organization_sid}/scim/Users".format(**self._solution) + def create(self, scim_user: ScimUser) -> UserInstance: """ Create the UserInstance - :param scim_user: - + :param scim_user: + :returns: The created UserInstance """ data = scim_user.to_dict() - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/json" - + headers["Content-Type"] = "application/scim+json" - - + headers["Accept"] = "application/scim+json" - - - payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) - return UserInstance(self._version, payload, organization_sid=self._solution['organization_sid']) + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return UserInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) async def create_async(self, scim_user: ScimUser) -> UserInstance: """ Asynchronously create the UserInstance - :param scim_user: - + :param scim_user: + :returns: The created UserInstance """ data = scim_user.to_dict() - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/json" - + headers["Content-Type"] = "application/scim+json" - - + headers["Accept"] = "application/scim+json" - - - payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) - - return UserInstance(self._version, payload, organization_sid=self._solution['organization_sid']) - - - def stream(self, + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return UserInstance( + self._version, payload, organization_sid=self._solution["organization_sid"] + ) + + def stream( + self, filter: Union[str, object] = values.unset, limit: Optional[int] = None, page_size: Optional[int] = None, @@ -840,8 +823,8 @@ def stream(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - - :param str filter: + + :param str filter: :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -852,14 +835,12 @@ def stream(self, :returns: Generator that will yield up to limit results """ limits = self._version.read_limits(limit, page_size) - page = self.page( - filter=filter, - page_size=limits['page_size'] - ) + page = self.page(filter=filter, page_size=limits["page_size"]) - return self._version.stream(page, limits['limit']) + return self._version.stream(page, limits["limit"]) - async def stream_async(self, + async def stream_async( + self, filter: Union[str, object] = values.unset, limit: Optional[int] = None, page_size: Optional[int] = None, @@ -869,8 +850,8 @@ async def stream_async(self, This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. - - :param str filter: + + :param str filter: :param limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -881,14 +862,12 @@ async def stream_async(self, :returns: Generator that will yield up to limit results """ limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - filter=filter, - page_size=limits['page_size'] - ) + page = await self.page_async(filter=filter, page_size=limits["page_size"]) - return self._version.stream_async(page, limits['limit']) + return self._version.stream_async(page, limits["limit"]) - def list(self, + def list( + self, filter: Union[str, object] = values.unset, limit: Optional[int] = None, page_size: Optional[int] = None, @@ -897,8 +876,8 @@ def list(self, Lists UserInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - - :param str filter: + + :param str filter: :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -908,13 +887,16 @@ def list(self, :returns: list that will contain up to limit results """ - return list(self.stream( - filter=filter, - limit=limit, - page_size=page_size, - )) + return list( + self.stream( + filter=filter, + limit=limit, + page_size=page_size, + ) + ) - async def list_async(self, + async def list_async( + self, filter: Union[str, object] = values.unset, limit: Optional[int] = None, page_size: Optional[int] = None, @@ -923,8 +905,8 @@ async def list_async(self, Asynchronously lists UserInstance records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. - - :param str filter: + + :param str filter: :param limit: Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit :param page_size: Number of records to fetch per request, when not set will use @@ -934,13 +916,17 @@ async def list_async(self, :returns: list that will contain up to limit results """ - return [record async for record in await self.stream_async( - filter=filter, - limit=limit, - page_size=page_size, - )] - - def page(self, + return [ + record + async for record in await self.stream_async( + filter=filter, + limit=limit, + page_size=page_size, + ) + ] + + def page( + self, filter: Union[str, object] = values.unset, page_token: Union[str, object] = values.unset, page_number: Union[int, object] = values.unset, @@ -949,33 +935,34 @@ def page(self, """ Retrieve a single page of UserInstance records from the API. Request is executed immediately - - :param filter: + + :param filter: :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of UserInstance """ - data = values.of({ - 'filter': filter, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "filter": filter, + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/scim+json" - - response = self._version.page(method='GET', uri=self._uri, params=data, headers=headers) + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return UserPage(self._version, response, self._solution) - async def page_async(self, + async def page_async( + self, filter: Union[str, object] = values.unset, page_token: Union[str, object] = values.unset, page_number: Union[int, object] = values.unset, @@ -984,30 +971,30 @@ async def page_async(self, """ Asynchronously retrieve a single page of UserInstance records from the API. Request is executed immediately - - :param filter: + + :param filter: :param page_token: PageToken provided by the API :param page_number: Page Number, this value is simply for client state :param page_size: Number of records to return, defaults to 50 :returns: Page of UserInstance """ - data = values.of({ - 'filter': filter, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - headers = values.of({ - 'Content-Type': 'application/x-www-form-urlencoded' - }) - - + data = values.of( + { + "filter": filter, + "PageToken": page_token, + "Page": page_number, + "PageSize": page_size, + } + ) + + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Accept"] = "application/scim+json" - - response = await self._version.page_async(method='GET', uri=self._uri, params=data, headers=headers) + response = await self._version.page_async( + method="GET", uri=self._uri, params=data, headers=headers + ) return UserPage(self._version, response, self._solution) def get_page(self, target_url: str) -> UserPage: @@ -1019,10 +1006,7 @@ def get_page(self, target_url: str) -> UserPage: :returns: Page of UserInstance """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) + response = self._version.domain.twilio.request("GET", target_url) return UserPage(self._version, response, self._solution) async def get_page_async(self, target_url: str) -> UserPage: @@ -1034,29 +1018,28 @@ async def get_page_async(self, target_url: str) -> UserPage: :returns: Page of UserInstance """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) + response = await self._version.domain.twilio.request_async("GET", target_url) return UserPage(self._version, response, self._solution) - - def get(self, id: str) -> UserContext: """ Constructs a UserContext - - :param id: + + :param id: """ - return UserContext(self._version, organization_sid=self._solution['organization_sid'], id=id) + return UserContext( + self._version, organization_sid=self._solution["organization_sid"], id=id + ) def __call__(self, id: str) -> UserContext: """ Constructs a UserContext - - :param id: + + :param id: """ - return UserContext(self._version, organization_sid=self._solution['organization_sid'], id=id) + return UserContext( + self._version, organization_sid=self._solution["organization_sid"], id=id + ) def __repr__(self) -> str: """ @@ -1064,5 +1047,4 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' - + return ""