Initial commit: Email alerts application

This commit is contained in:
Iyeoluwa Akinrinola
2025-07-25 11:31:36 +01:00
commit adfb625ae9
6322 changed files with 2882826 additions and 0 deletions
@@ -0,0 +1,42 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from typing import Optional
from twilio.base.version import Version
from twilio.base.domain import Domain
from twilio.rest.preview.sync.service import ServiceList
class Sync(Version):
def __init__(self, domain: Domain):
"""
Initialize the Sync version of Preview
:param domain: The Twilio.preview domain
"""
super().__init__(domain, "Sync")
self._services: Optional[ServiceList] = None
@property
def services(self) -> ServiceList:
if self._services is None:
self._services = ServiceList(self)
return self._services
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync>"
@@ -0,0 +1,700 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
from twilio.rest.preview.sync.service.document import DocumentList
from twilio.rest.preview.sync.service.sync_list import SyncListList
from twilio.rest.preview.sync.service.sync_map import SyncMapList
class ServiceInstance(InstanceResource):
"""
:ivar sid:
:ivar account_sid:
:ivar friendly_name:
:ivar date_created:
:ivar date_updated:
:ivar url:
:ivar webhook_url:
:ivar reachability_webhooks_enabled:
:ivar acl_enabled:
:ivar links:
"""
def __init__(
self, version: Version, payload: Dict[str, Any], sid: Optional[str] = None
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.url: Optional[str] = payload.get("url")
self.webhook_url: Optional[str] = payload.get("webhook_url")
self.reachability_webhooks_enabled: Optional[bool] = payload.get(
"reachability_webhooks_enabled"
)
self.acl_enabled: Optional[bool] = payload.get("acl_enabled")
self.links: Optional[Dict[str, object]] = payload.get("links")
self._solution = {
"sid": sid or self.sid,
}
self._context: Optional[ServiceContext] = None
@property
def _proxy(self) -> "ServiceContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: ServiceContext for this ServiceInstance
"""
if self._context is None:
self._context = ServiceContext(
self._version,
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the ServiceInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the ServiceInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "ServiceInstance":
"""
Fetch the ServiceInstance
:returns: The fetched ServiceInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "ServiceInstance":
"""
Asynchronous coroutine to fetch the ServiceInstance
:returns: The fetched ServiceInstance
"""
return await self._proxy.fetch_async()
def update(
self,
webhook_url: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> "ServiceInstance":
"""
Update the ServiceInstance
:param webhook_url:
:param friendly_name:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The updated ServiceInstance
"""
return self._proxy.update(
webhook_url=webhook_url,
friendly_name=friendly_name,
reachability_webhooks_enabled=reachability_webhooks_enabled,
acl_enabled=acl_enabled,
)
async def update_async(
self,
webhook_url: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> "ServiceInstance":
"""
Asynchronous coroutine to update the ServiceInstance
:param webhook_url:
:param friendly_name:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The updated ServiceInstance
"""
return await self._proxy.update_async(
webhook_url=webhook_url,
friendly_name=friendly_name,
reachability_webhooks_enabled=reachability_webhooks_enabled,
acl_enabled=acl_enabled,
)
@property
def documents(self) -> DocumentList:
"""
Access the documents
"""
return self._proxy.documents
@property
def sync_lists(self) -> SyncListList:
"""
Access the sync_lists
"""
return self._proxy.sync_lists
@property
def sync_maps(self) -> SyncMapList:
"""
Access the sync_maps
"""
return self._proxy.sync_maps
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 "<Twilio.Preview.Sync.ServiceInstance {}>".format(context)
class ServiceContext(InstanceContext):
def __init__(self, version: Version, sid: str):
"""
Initialize the ServiceContext
:param version: Version that contains the resource
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"sid": sid,
}
self._uri = "/Services/{sid}".format(**self._solution)
self._documents: Optional[DocumentList] = None
self._sync_lists: Optional[SyncListList] = None
self._sync_maps: Optional[SyncMapList] = None
def delete(self) -> bool:
"""
Deletes the ServiceInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the ServiceInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> ServiceInstance:
"""
Fetch the ServiceInstance
:returns: The fetched ServiceInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return ServiceInstance(
self._version,
payload,
sid=self._solution["sid"],
)
async def fetch_async(self) -> ServiceInstance:
"""
Asynchronous coroutine to fetch the ServiceInstance
:returns: The fetched ServiceInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return ServiceInstance(
self._version,
payload,
sid=self._solution["sid"],
)
def update(
self,
webhook_url: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Update the ServiceInstance
:param webhook_url:
:param friendly_name:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The updated ServiceInstance
"""
data = values.of(
{
"WebhookUrl": webhook_url,
"FriendlyName": friendly_name,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return ServiceInstance(self._version, payload, sid=self._solution["sid"])
async def update_async(
self,
webhook_url: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Asynchronous coroutine to update the ServiceInstance
:param webhook_url:
:param friendly_name:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The updated ServiceInstance
"""
data = values.of(
{
"WebhookUrl": webhook_url,
"FriendlyName": friendly_name,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return ServiceInstance(self._version, payload, sid=self._solution["sid"])
@property
def documents(self) -> DocumentList:
"""
Access the documents
"""
if self._documents is None:
self._documents = DocumentList(
self._version,
self._solution["sid"],
)
return self._documents
@property
def sync_lists(self) -> SyncListList:
"""
Access the sync_lists
"""
if self._sync_lists is None:
self._sync_lists = SyncListList(
self._version,
self._solution["sid"],
)
return self._sync_lists
@property
def sync_maps(self) -> SyncMapList:
"""
Access the sync_maps
"""
if self._sync_maps is None:
self._sync_maps = SyncMapList(
self._version,
self._solution["sid"],
)
return self._sync_maps
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 "<Twilio.Preview.Sync.ServiceContext {}>".format(context)
class ServicePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> ServiceInstance:
"""
Build an instance of ServiceInstance
:param payload: Payload response from the API
"""
return ServiceInstance(self._version, payload)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.ServicePage>"
class ServiceList(ListResource):
def __init__(self, version: Version):
"""
Initialize the ServiceList
:param version: Version that contains the resource
"""
super().__init__(version)
self._uri = "/Services"
def create(
self,
friendly_name: Union[str, object] = values.unset,
webhook_url: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Create the ServiceInstance
:param friendly_name:
:param webhook_url:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The created ServiceInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"WebhookUrl": webhook_url,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return ServiceInstance(self._version, payload)
async def create_async(
self,
friendly_name: Union[str, object] = values.unset,
webhook_url: Union[str, object] = values.unset,
reachability_webhooks_enabled: Union[bool, object] = values.unset,
acl_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Asynchronously create the ServiceInstance
:param friendly_name:
:param webhook_url:
:param reachability_webhooks_enabled:
:param acl_enabled:
:returns: The created ServiceInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"WebhookUrl": webhook_url,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return ServiceInstance(self._version, payload)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[ServiceInstance]:
"""
Streams ServiceInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[ServiceInstance]:
"""
Asynchronously streams ServiceInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ServiceInstance]:
"""
Lists ServiceInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ServiceInstance]:
"""
Asynchronously lists ServiceInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ServicePage:
"""
Retrieve a single page of ServiceInstance 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 ServiceInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return ServicePage(self._version, response)
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,
) -> ServicePage:
"""
Asynchronously retrieve a single page of ServiceInstance 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 ServiceInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return ServicePage(self._version, response)
def get_page(self, target_url: str) -> ServicePage:
"""
Retrieve a specific page of ServiceInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ServiceInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return ServicePage(self._version, response)
async def get_page_async(self, target_url: str) -> ServicePage:
"""
Asynchronously retrieve a specific page of ServiceInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ServiceInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return ServicePage(self._version, response)
def get(self, sid: str) -> ServiceContext:
"""
Constructs a ServiceContext
:param sid:
"""
return ServiceContext(self._version, sid=sid)
def __call__(self, sid: str) -> ServiceContext:
"""
Constructs a ServiceContext
:param sid:
"""
return ServiceContext(self._version, sid=sid)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.ServiceList>"
@@ -0,0 +1,656 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
from twilio.base import deserialize, serialize, values
from twilio.base.instance_context import InstanceContext
from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version
from twilio.base.page import Page
from twilio.rest.preview.sync.service.document.document_permission import (
DocumentPermissionList,
)
class DocumentInstance(InstanceResource):
"""
:ivar sid:
:ivar unique_name:
:ivar account_sid:
:ivar service_sid:
:ivar url:
:ivar links:
:ivar revision:
:ivar data:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.unique_name: Optional[str] = payload.get("unique_name")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self.revision: Optional[str] = payload.get("revision")
self.data: Optional[Dict[str, object]] = payload.get("data")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.created_by: Optional[str] = payload.get("created_by")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[DocumentContext] = None
@property
def _proxy(self) -> "DocumentContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: DocumentContext for this DocumentInstance
"""
if self._context is None:
self._context = DocumentContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the DocumentInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the DocumentInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "DocumentInstance":
"""
Fetch the DocumentInstance
:returns: The fetched DocumentInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "DocumentInstance":
"""
Asynchronous coroutine to fetch the DocumentInstance
:returns: The fetched DocumentInstance
"""
return await self._proxy.fetch_async()
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> "DocumentInstance":
"""
Update the DocumentInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated DocumentInstance
"""
return self._proxy.update(
data=data,
if_match=if_match,
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> "DocumentInstance":
"""
Asynchronous coroutine to update the DocumentInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated DocumentInstance
"""
return await self._proxy.update_async(
data=data,
if_match=if_match,
)
@property
def document_permissions(self) -> DocumentPermissionList:
"""
Access the document_permissions
"""
return self._proxy.document_permissions
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 "<Twilio.Preview.Sync.DocumentInstance {}>".format(context)
class DocumentContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the DocumentContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Documents/{sid}".format(**self._solution)
self._document_permissions: Optional[DocumentPermissionList] = None
def delete(self) -> bool:
"""
Deletes the DocumentInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the DocumentInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> DocumentInstance:
"""
Fetch the DocumentInstance
:returns: The fetched DocumentInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return DocumentInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> DocumentInstance:
"""
Asynchronous coroutine to fetch the DocumentInstance
:returns: The fetched DocumentInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return DocumentInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> DocumentInstance:
"""
Update the DocumentInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated DocumentInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return DocumentInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> DocumentInstance:
"""
Asynchronous coroutine to update the DocumentInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated DocumentInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return DocumentInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def document_permissions(self) -> DocumentPermissionList:
"""
Access the document_permissions
"""
if self._document_permissions is None:
self._document_permissions = DocumentPermissionList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._document_permissions
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 "<Twilio.Preview.Sync.DocumentContext {}>".format(context)
class DocumentPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> DocumentInstance:
"""
Build an instance of DocumentInstance
:param payload: Payload response from the API
"""
return DocumentInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.DocumentPage>"
class DocumentList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the DocumentList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Documents".format(**self._solution)
def create(
self,
unique_name: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
) -> DocumentInstance:
"""
Create the DocumentInstance
:param unique_name:
:param data:
:returns: The created DocumentInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Data": serialize.object(data),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return DocumentInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
unique_name: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
) -> DocumentInstance:
"""
Asynchronously create the DocumentInstance
:param unique_name:
:param data:
:returns: The created DocumentInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Data": serialize.object(data),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return DocumentInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[DocumentInstance]:
"""
Streams DocumentInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[DocumentInstance]:
"""
Asynchronously streams DocumentInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[DocumentInstance]:
"""
Lists DocumentInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[DocumentInstance]:
"""
Asynchronously lists DocumentInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> DocumentPage:
"""
Retrieve a single page of DocumentInstance 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 DocumentInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return DocumentPage(self._version, response, self._solution)
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,
) -> DocumentPage:
"""
Asynchronously retrieve a single page of DocumentInstance 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 DocumentInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return DocumentPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> DocumentPage:
"""
Retrieve a specific page of DocumentInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of DocumentInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return DocumentPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> DocumentPage:
"""
Asynchronously retrieve a specific page of DocumentInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of DocumentInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return DocumentPage(self._version, response, self._solution)
def get(self, sid: str) -> DocumentContext:
"""
Constructs a DocumentContext
:param sid:
"""
return DocumentContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> DocumentContext:
"""
Constructs a DocumentContext
:param sid:
"""
return DocumentContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.DocumentList>"
@@ -0,0 +1,592 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
class DocumentPermissionInstance(InstanceResource):
"""
:ivar account_sid: The unique SID identifier of the Twilio Account.
:ivar service_sid: The unique SID identifier of the Sync Service Instance.
:ivar document_sid: The unique SID identifier of the Sync Document to which the Permission applies.
:ivar identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
:ivar read: Boolean flag specifying whether the identity can read the Sync Document.
:ivar write: Boolean flag specifying whether the identity can update the Sync Document.
:ivar manage: Boolean flag specifying whether the identity can delete the Sync Document.
:ivar url: Contains an absolute URL for this Sync Document Permission.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
document_sid: str,
identity: Optional[str] = None,
):
super().__init__(version)
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.document_sid: Optional[str] = payload.get("document_sid")
self.identity: Optional[str] = payload.get("identity")
self.read: Optional[bool] = payload.get("read")
self.write: Optional[bool] = payload.get("write")
self.manage: Optional[bool] = payload.get("manage")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"document_sid": document_sid,
"identity": identity or self.identity,
}
self._context: Optional[DocumentPermissionContext] = None
@property
def _proxy(self) -> "DocumentPermissionContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: DocumentPermissionContext for this DocumentPermissionInstance
"""
if self._context is None:
self._context = DocumentPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=self._solution["identity"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the DocumentPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the DocumentPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "DocumentPermissionInstance":
"""
Fetch the DocumentPermissionInstance
:returns: The fetched DocumentPermissionInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "DocumentPermissionInstance":
"""
Asynchronous coroutine to fetch the DocumentPermissionInstance
:returns: The fetched DocumentPermissionInstance
"""
return await self._proxy.fetch_async()
def update(
self, read: bool, write: bool, manage: bool
) -> "DocumentPermissionInstance":
"""
Update the DocumentPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Document.
:param write: Boolean flag specifying whether the identity can update the Sync Document.
:param manage: Boolean flag specifying whether the identity can delete the Sync Document.
:returns: The updated DocumentPermissionInstance
"""
return self._proxy.update(
read=read,
write=write,
manage=manage,
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> "DocumentPermissionInstance":
"""
Asynchronous coroutine to update the DocumentPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Document.
:param write: Boolean flag specifying whether the identity can update the Sync Document.
:param manage: Boolean flag specifying whether the identity can delete the Sync Document.
:returns: The updated DocumentPermissionInstance
"""
return await self._proxy.update_async(
read=read,
write=write,
manage=manage,
)
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 "<Twilio.Preview.Sync.DocumentPermissionInstance {}>".format(context)
class DocumentPermissionContext(InstanceContext):
def __init__(
self, version: Version, service_sid: str, document_sid: str, identity: str
):
"""
Initialize the DocumentPermissionContext
:param version: Version that contains the resource
:param service_sid: The unique SID identifier of the Sync Service Instance.
:param document_sid: Identifier of the Sync Document. Either a SID or a unique name.
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"document_sid": document_sid,
"identity": identity,
}
self._uri = "/Services/{service_sid}/Documents/{document_sid}/Permissions/{identity}".format(
**self._solution
)
def delete(self) -> bool:
"""
Deletes the DocumentPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the DocumentPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> DocumentPermissionInstance:
"""
Fetch the DocumentPermissionInstance
:returns: The fetched DocumentPermissionInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return DocumentPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=self._solution["identity"],
)
async def fetch_async(self) -> DocumentPermissionInstance:
"""
Asynchronous coroutine to fetch the DocumentPermissionInstance
:returns: The fetched DocumentPermissionInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return DocumentPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=self._solution["identity"],
)
def update(
self, read: bool, write: bool, manage: bool
) -> DocumentPermissionInstance:
"""
Update the DocumentPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Document.
:param write: Boolean flag specifying whether the identity can update the Sync Document.
:param manage: Boolean flag specifying whether the identity can delete the Sync Document.
:returns: The updated DocumentPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return DocumentPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=self._solution["identity"],
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> DocumentPermissionInstance:
"""
Asynchronous coroutine to update the DocumentPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Document.
:param write: Boolean flag specifying whether the identity can update the Sync Document.
:param manage: Boolean flag specifying whether the identity can delete the Sync Document.
:returns: The updated DocumentPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return DocumentPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=self._solution["identity"],
)
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 "<Twilio.Preview.Sync.DocumentPermissionContext {}>".format(context)
class DocumentPermissionPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> DocumentPermissionInstance:
"""
Build an instance of DocumentPermissionInstance
:param payload: Payload response from the API
"""
return DocumentPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.DocumentPermissionPage>"
class DocumentPermissionList(ListResource):
def __init__(self, version: Version, service_sid: str, document_sid: str):
"""
Initialize the DocumentPermissionList
:param version: Version that contains the resource
:param service_sid:
:param document_sid: Identifier of the Sync Document. Either a SID or a unique name.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"document_sid": document_sid,
}
self._uri = (
"/Services/{service_sid}/Documents/{document_sid}/Permissions".format(
**self._solution
)
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[DocumentPermissionInstance]:
"""
Streams DocumentPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[DocumentPermissionInstance]:
"""
Asynchronously streams DocumentPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[DocumentPermissionInstance]:
"""
Lists DocumentPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[DocumentPermissionInstance]:
"""
Asynchronously lists DocumentPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> DocumentPermissionPage:
"""
Retrieve a single page of DocumentPermissionInstance 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 DocumentPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return DocumentPermissionPage(self._version, response, self._solution)
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,
) -> DocumentPermissionPage:
"""
Asynchronously retrieve a single page of DocumentPermissionInstance 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 DocumentPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return DocumentPermissionPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> DocumentPermissionPage:
"""
Retrieve a specific page of DocumentPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of DocumentPermissionInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return DocumentPermissionPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> DocumentPermissionPage:
"""
Asynchronously retrieve a specific page of DocumentPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of DocumentPermissionInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return DocumentPermissionPage(self._version, response, self._solution)
def get(self, identity: str) -> DocumentPermissionContext:
"""
Constructs a DocumentPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return DocumentPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=identity,
)
def __call__(self, identity: str) -> DocumentPermissionContext:
"""
Constructs a DocumentPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return DocumentPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
document_sid=self._solution["document_sid"],
identity=identity,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.DocumentPermissionList>"
@@ -0,0 +1,570 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
from twilio.rest.preview.sync.service.sync_list.sync_list_item import SyncListItemList
from twilio.rest.preview.sync.service.sync_list.sync_list_permission import (
SyncListPermissionList,
)
class SyncListInstance(InstanceResource):
"""
:ivar sid:
:ivar unique_name:
:ivar account_sid:
:ivar service_sid:
:ivar url:
:ivar links:
:ivar revision:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.unique_name: Optional[str] = payload.get("unique_name")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self.revision: Optional[str] = payload.get("revision")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.created_by: Optional[str] = payload.get("created_by")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[SyncListContext] = None
@property
def _proxy(self) -> "SyncListContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncListContext for this SyncListInstance
"""
if self._context is None:
self._context = SyncListContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the SyncListInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncListInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "SyncListInstance":
"""
Fetch the SyncListInstance
:returns: The fetched SyncListInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncListInstance":
"""
Asynchronous coroutine to fetch the SyncListInstance
:returns: The fetched SyncListInstance
"""
return await self._proxy.fetch_async()
@property
def sync_list_items(self) -> SyncListItemList:
"""
Access the sync_list_items
"""
return self._proxy.sync_list_items
@property
def sync_list_permissions(self) -> SyncListPermissionList:
"""
Access the sync_list_permissions
"""
return self._proxy.sync_list_permissions
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 "<Twilio.Preview.Sync.SyncListInstance {}>".format(context)
class SyncListContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the SyncListContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Lists/{sid}".format(**self._solution)
self._sync_list_items: Optional[SyncListItemList] = None
self._sync_list_permissions: Optional[SyncListPermissionList] = None
def delete(self) -> bool:
"""
Deletes the SyncListInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncListInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> SyncListInstance:
"""
Fetch the SyncListInstance
:returns: The fetched SyncListInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncListInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> SyncListInstance:
"""
Asynchronous coroutine to fetch the SyncListInstance
:returns: The fetched SyncListInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncListInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def sync_list_items(self) -> SyncListItemList:
"""
Access the sync_list_items
"""
if self._sync_list_items is None:
self._sync_list_items = SyncListItemList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._sync_list_items
@property
def sync_list_permissions(self) -> SyncListPermissionList:
"""
Access the sync_list_permissions
"""
if self._sync_list_permissions is None:
self._sync_list_permissions = SyncListPermissionList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._sync_list_permissions
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 "<Twilio.Preview.Sync.SyncListContext {}>".format(context)
class SyncListPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncListInstance:
"""
Build an instance of SyncListInstance
:param payload: Payload response from the API
"""
return SyncListInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListPage>"
class SyncListList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the SyncListList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Lists".format(**self._solution)
def create(
self, unique_name: Union[str, object] = values.unset
) -> SyncListInstance:
"""
Create the SyncListInstance
:param unique_name:
:returns: The created SyncListInstance
"""
data = values.of(
{
"UniqueName": unique_name,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return SyncListInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self, unique_name: Union[str, object] = values.unset
) -> SyncListInstance:
"""
Asynchronously create the SyncListInstance
:param unique_name:
:returns: The created SyncListInstance
"""
data = values.of(
{
"UniqueName": unique_name,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncListInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncListInstance]:
"""
Streams SyncListInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncListInstance]:
"""
Asynchronously streams SyncListInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListInstance]:
"""
Lists SyncListInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListInstance]:
"""
Asynchronously lists SyncListInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncListPage:
"""
Retrieve a single page of SyncListInstance 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 SyncListInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncListPage(self._version, response, self._solution)
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,
) -> SyncListPage:
"""
Asynchronously retrieve a single page of SyncListInstance 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 SyncListInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncListPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncListPage:
"""
Retrieve a specific page of SyncListInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncListPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncListPage:
"""
Asynchronously retrieve a specific page of SyncListInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncListPage(self._version, response, self._solution)
def get(self, sid: str) -> SyncListContext:
"""
Constructs a SyncListContext
:param sid:
"""
return SyncListContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> SyncListContext:
"""
Constructs a SyncListContext
:param sid:
"""
return SyncListContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListList>"
@@ -0,0 +1,722 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
from twilio.base import deserialize, serialize, values
from twilio.base.instance_context import InstanceContext
from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version
from twilio.base.page import Page
class SyncListItemInstance(InstanceResource):
class QueryFromBoundType(object):
INCLUSIVE = "inclusive"
EXCLUSIVE = "exclusive"
class QueryResultOrder(object):
ASC = "asc"
DESC = "desc"
"""
:ivar index:
:ivar account_sid:
:ivar service_sid:
:ivar list_sid:
:ivar url:
:ivar revision:
:ivar data:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
list_sid: str,
index: Optional[int] = None,
):
super().__init__(version)
self.index: Optional[int] = deserialize.integer(payload.get("index"))
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.list_sid: Optional[str] = payload.get("list_sid")
self.url: Optional[str] = payload.get("url")
self.revision: Optional[str] = payload.get("revision")
self.data: Optional[Dict[str, object]] = payload.get("data")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.created_by: Optional[str] = payload.get("created_by")
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
"index": index or self.index,
}
self._context: Optional[SyncListItemContext] = None
@property
def _proxy(self) -> "SyncListItemContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncListItemContext for this SyncListItemInstance
"""
if self._context is None:
self._context = SyncListItemContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=self._solution["index"],
)
return self._context
def delete(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Deletes the SyncListItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
if_match=if_match,
)
async def delete_async(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Asynchronous coroutine that deletes the SyncListItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
if_match=if_match,
)
def fetch(self) -> "SyncListItemInstance":
"""
Fetch the SyncListItemInstance
:returns: The fetched SyncListItemInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncListItemInstance":
"""
Asynchronous coroutine to fetch the SyncListItemInstance
:returns: The fetched SyncListItemInstance
"""
return await self._proxy.fetch_async()
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> "SyncListItemInstance":
"""
Update the SyncListItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncListItemInstance
"""
return self._proxy.update(
data=data,
if_match=if_match,
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> "SyncListItemInstance":
"""
Asynchronous coroutine to update the SyncListItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncListItemInstance
"""
return await self._proxy.update_async(
data=data,
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 "<Twilio.Preview.Sync.SyncListItemInstance {}>".format(context)
class SyncListItemContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, list_sid: str, index: int):
"""
Initialize the SyncListItemContext
:param version: Version that contains the resource
:param service_sid:
:param list_sid:
:param index:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
"index": index,
}
self._uri = "/Services/{service_sid}/Lists/{list_sid}/Items/{index}".format(
**self._solution
)
def delete(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Deletes the SyncListItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"If-Match": if_match,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Asynchronous coroutine that deletes the SyncListItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"If-Match": if_match,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> SyncListItemInstance:
"""
Fetch the SyncListItemInstance
:returns: The fetched SyncListItemInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=self._solution["index"],
)
async def fetch_async(self) -> SyncListItemInstance:
"""
Asynchronous coroutine to fetch the SyncListItemInstance
:returns: The fetched SyncListItemInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=self._solution["index"],
)
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> SyncListItemInstance:
"""
Update the SyncListItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=self._solution["index"],
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> SyncListItemInstance:
"""
Asynchronous coroutine to update the SyncListItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=self._solution["index"],
)
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 "<Twilio.Preview.Sync.SyncListItemContext {}>".format(context)
class SyncListItemPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncListItemInstance:
"""
Build an instance of SyncListItemInstance
:param payload: Payload response from the API
"""
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListItemPage>"
class SyncListItemList(ListResource):
def __init__(self, version: Version, service_sid: str, list_sid: str):
"""
Initialize the SyncListItemList
:param version: Version that contains the resource
:param service_sid:
:param list_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
}
self._uri = "/Services/{service_sid}/Lists/{list_sid}/Items".format(
**self._solution
)
def create(self, data: object) -> SyncListItemInstance:
"""
Create the SyncListItemInstance
:param data:
:returns: The created SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
)
async def create_async(self, data: object) -> SyncListItemInstance:
"""
Asynchronously create the SyncListItemInstance
:param data:
:returns: The created SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncListItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
)
def stream(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncListItemInstance]:
"""
Streams SyncListItemInstance records from the API as a generator stream.
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 &quot;SyncListItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
:returns: Generator that will yield up to limit results
"""
limits = self._version.read_limits(limit, page_size)
page = self.page(
order=order, from_=from_, bounds=bounds, page_size=limits["page_size"]
)
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncListItemInstance]:
"""
Asynchronously streams SyncListItemInstance records from the API as a generator stream.
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 &quot;SyncListItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
:returns: Generator that will yield up to limit results
"""
limits = self._version.read_limits(limit, page_size)
page = await self.page_async(
order=order, from_=from_, bounds=bounds, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListItemInstance]:
"""
Lists SyncListItemInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;SyncListItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
order=order,
from_=from_,
bounds=bounds,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListItemInstance]:
"""
Asynchronously lists SyncListItemInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;SyncListItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return [
record
async for record in await self.stream_async(
order=order,
from_=from_,
bounds=bounds,
limit=limit,
page_size=page_size,
)
]
def page(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncListItemPage:
"""
Retrieve a single page of SyncListItemInstance records from the API.
Request is executed immediately
:param order:
:param from_:
:param bounds:
: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 SyncListItemInstance
"""
data = values.of(
{
"Order": order,
"From": from_,
"Bounds": bounds,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncListItemPage(self._version, response, self._solution)
async def page_async(
self,
order: Union["SyncListItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncListItemInstance.QueryFromBoundType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncListItemPage:
"""
Asynchronously retrieve a single page of SyncListItemInstance records from the API.
Request is executed immediately
:param order:
:param from_:
:param bounds:
: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 SyncListItemInstance
"""
data = values.of(
{
"Order": order,
"From": from_,
"Bounds": bounds,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncListItemPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncListItemPage:
"""
Retrieve a specific page of SyncListItemInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListItemInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncListItemPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncListItemPage:
"""
Asynchronously retrieve a specific page of SyncListItemInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListItemInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncListItemPage(self._version, response, self._solution)
def get(self, index: int) -> SyncListItemContext:
"""
Constructs a SyncListItemContext
:param index:
"""
return SyncListItemContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=index,
)
def __call__(self, index: int) -> SyncListItemContext:
"""
Constructs a SyncListItemContext
:param index:
"""
return SyncListItemContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
index=index,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListItemList>"
@@ -0,0 +1,592 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
class SyncListPermissionInstance(InstanceResource):
"""
:ivar account_sid: The unique SID identifier of the Twilio Account.
:ivar service_sid: The unique SID identifier of the Sync Service Instance.
:ivar list_sid: The unique SID identifier of the Sync List to which the Permission applies.
:ivar identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
:ivar read: Boolean flag specifying whether the identity can read the Sync List and its Items.
:ivar write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync List.
:ivar manage: Boolean flag specifying whether the identity can delete the Sync List.
:ivar url: Contains an absolute URL for this Sync List Permission.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
list_sid: str,
identity: Optional[str] = None,
):
super().__init__(version)
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.list_sid: Optional[str] = payload.get("list_sid")
self.identity: Optional[str] = payload.get("identity")
self.read: Optional[bool] = payload.get("read")
self.write: Optional[bool] = payload.get("write")
self.manage: Optional[bool] = payload.get("manage")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
"identity": identity or self.identity,
}
self._context: Optional[SyncListPermissionContext] = None
@property
def _proxy(self) -> "SyncListPermissionContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncListPermissionContext for this SyncListPermissionInstance
"""
if self._context is None:
self._context = SyncListPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=self._solution["identity"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the SyncListPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncListPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "SyncListPermissionInstance":
"""
Fetch the SyncListPermissionInstance
:returns: The fetched SyncListPermissionInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncListPermissionInstance":
"""
Asynchronous coroutine to fetch the SyncListPermissionInstance
:returns: The fetched SyncListPermissionInstance
"""
return await self._proxy.fetch_async()
def update(
self, read: bool, write: bool, manage: bool
) -> "SyncListPermissionInstance":
"""
Update the SyncListPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync List.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync List.
:param manage: Boolean flag specifying whether the identity can delete the Sync List.
:returns: The updated SyncListPermissionInstance
"""
return self._proxy.update(
read=read,
write=write,
manage=manage,
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> "SyncListPermissionInstance":
"""
Asynchronous coroutine to update the SyncListPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync List.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync List.
:param manage: Boolean flag specifying whether the identity can delete the Sync List.
:returns: The updated SyncListPermissionInstance
"""
return await self._proxy.update_async(
read=read,
write=write,
manage=manage,
)
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 "<Twilio.Preview.Sync.SyncListPermissionInstance {}>".format(context)
class SyncListPermissionContext(InstanceContext):
def __init__(
self, version: Version, service_sid: str, list_sid: str, identity: str
):
"""
Initialize the SyncListPermissionContext
:param version: Version that contains the resource
:param service_sid: The unique SID identifier of the Sync Service Instance.
:param list_sid: Identifier of the Sync List. Either a SID or a unique name.
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
"identity": identity,
}
self._uri = (
"/Services/{service_sid}/Lists/{list_sid}/Permissions/{identity}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the SyncListPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncListPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> SyncListPermissionInstance:
"""
Fetch the SyncListPermissionInstance
:returns: The fetched SyncListPermissionInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncListPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=self._solution["identity"],
)
async def fetch_async(self) -> SyncListPermissionInstance:
"""
Asynchronous coroutine to fetch the SyncListPermissionInstance
:returns: The fetched SyncListPermissionInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncListPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=self._solution["identity"],
)
def update(
self, read: bool, write: bool, manage: bool
) -> SyncListPermissionInstance:
"""
Update the SyncListPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync List.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync List.
:param manage: Boolean flag specifying whether the identity can delete the Sync List.
:returns: The updated SyncListPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return SyncListPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=self._solution["identity"],
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> SyncListPermissionInstance:
"""
Asynchronous coroutine to update the SyncListPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync List.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync List.
:param manage: Boolean flag specifying whether the identity can delete the Sync List.
:returns: The updated SyncListPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncListPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=self._solution["identity"],
)
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 "<Twilio.Preview.Sync.SyncListPermissionContext {}>".format(context)
class SyncListPermissionPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncListPermissionInstance:
"""
Build an instance of SyncListPermissionInstance
:param payload: Payload response from the API
"""
return SyncListPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListPermissionPage>"
class SyncListPermissionList(ListResource):
def __init__(self, version: Version, service_sid: str, list_sid: str):
"""
Initialize the SyncListPermissionList
:param version: Version that contains the resource
:param service_sid:
:param list_sid: Identifier of the Sync List. Either a SID or a unique name.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"list_sid": list_sid,
}
self._uri = "/Services/{service_sid}/Lists/{list_sid}/Permissions".format(
**self._solution
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncListPermissionInstance]:
"""
Streams SyncListPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncListPermissionInstance]:
"""
Asynchronously streams SyncListPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListPermissionInstance]:
"""
Lists SyncListPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncListPermissionInstance]:
"""
Asynchronously lists SyncListPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncListPermissionPage:
"""
Retrieve a single page of SyncListPermissionInstance 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 SyncListPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncListPermissionPage(self._version, response, self._solution)
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,
) -> SyncListPermissionPage:
"""
Asynchronously retrieve a single page of SyncListPermissionInstance 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 SyncListPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncListPermissionPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncListPermissionPage:
"""
Retrieve a specific page of SyncListPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListPermissionInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncListPermissionPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncListPermissionPage:
"""
Asynchronously retrieve a specific page of SyncListPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncListPermissionInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncListPermissionPage(self._version, response, self._solution)
def get(self, identity: str) -> SyncListPermissionContext:
"""
Constructs a SyncListPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return SyncListPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=identity,
)
def __call__(self, identity: str) -> SyncListPermissionContext:
"""
Constructs a SyncListPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return SyncListPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
list_sid=self._solution["list_sid"],
identity=identity,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncListPermissionList>"
@@ -0,0 +1,568 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
from twilio.rest.preview.sync.service.sync_map.sync_map_item import SyncMapItemList
from twilio.rest.preview.sync.service.sync_map.sync_map_permission import (
SyncMapPermissionList,
)
class SyncMapInstance(InstanceResource):
"""
:ivar sid:
:ivar unique_name:
:ivar account_sid:
:ivar service_sid:
:ivar url:
:ivar links:
:ivar revision:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.unique_name: Optional[str] = payload.get("unique_name")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self.revision: Optional[str] = payload.get("revision")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.created_by: Optional[str] = payload.get("created_by")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[SyncMapContext] = None
@property
def _proxy(self) -> "SyncMapContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncMapContext for this SyncMapInstance
"""
if self._context is None:
self._context = SyncMapContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the SyncMapInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "SyncMapInstance":
"""
Fetch the SyncMapInstance
:returns: The fetched SyncMapInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncMapInstance":
"""
Asynchronous coroutine to fetch the SyncMapInstance
:returns: The fetched SyncMapInstance
"""
return await self._proxy.fetch_async()
@property
def sync_map_items(self) -> SyncMapItemList:
"""
Access the sync_map_items
"""
return self._proxy.sync_map_items
@property
def sync_map_permissions(self) -> SyncMapPermissionList:
"""
Access the sync_map_permissions
"""
return self._proxy.sync_map_permissions
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 "<Twilio.Preview.Sync.SyncMapInstance {}>".format(context)
class SyncMapContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the SyncMapContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Maps/{sid}".format(**self._solution)
self._sync_map_items: Optional[SyncMapItemList] = None
self._sync_map_permissions: Optional[SyncMapPermissionList] = None
def delete(self) -> bool:
"""
Deletes the SyncMapInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> SyncMapInstance:
"""
Fetch the SyncMapInstance
:returns: The fetched SyncMapInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncMapInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> SyncMapInstance:
"""
Asynchronous coroutine to fetch the SyncMapInstance
:returns: The fetched SyncMapInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncMapInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def sync_map_items(self) -> SyncMapItemList:
"""
Access the sync_map_items
"""
if self._sync_map_items is None:
self._sync_map_items = SyncMapItemList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._sync_map_items
@property
def sync_map_permissions(self) -> SyncMapPermissionList:
"""
Access the sync_map_permissions
"""
if self._sync_map_permissions is None:
self._sync_map_permissions = SyncMapPermissionList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._sync_map_permissions
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 "<Twilio.Preview.Sync.SyncMapContext {}>".format(context)
class SyncMapPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncMapInstance:
"""
Build an instance of SyncMapInstance
:param payload: Payload response from the API
"""
return SyncMapInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapPage>"
class SyncMapList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the SyncMapList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Maps".format(**self._solution)
def create(self, unique_name: Union[str, object] = values.unset) -> SyncMapInstance:
"""
Create the SyncMapInstance
:param unique_name:
:returns: The created SyncMapInstance
"""
data = values.of(
{
"UniqueName": unique_name,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self, unique_name: Union[str, object] = values.unset
) -> SyncMapInstance:
"""
Asynchronously create the SyncMapInstance
:param unique_name:
:returns: The created SyncMapInstance
"""
data = values.of(
{
"UniqueName": unique_name,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncMapInstance]:
"""
Streams SyncMapInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncMapInstance]:
"""
Asynchronously streams SyncMapInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapInstance]:
"""
Lists SyncMapInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapInstance]:
"""
Asynchronously lists SyncMapInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncMapPage:
"""
Retrieve a single page of SyncMapInstance 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 SyncMapInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncMapPage(self._version, response, self._solution)
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,
) -> SyncMapPage:
"""
Asynchronously retrieve a single page of SyncMapInstance 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 SyncMapInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncMapPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncMapPage:
"""
Retrieve a specific page of SyncMapInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncMapPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncMapPage:
"""
Asynchronously retrieve a specific page of SyncMapInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncMapPage(self._version, response, self._solution)
def get(self, sid: str) -> SyncMapContext:
"""
Constructs a SyncMapContext
:param sid:
"""
return SyncMapContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> SyncMapContext:
"""
Constructs a SyncMapContext
:param sid:
"""
return SyncMapContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapList>"
@@ -0,0 +1,726 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
from twilio.base import deserialize, serialize, values
from twilio.base.instance_context import InstanceContext
from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version
from twilio.base.page import Page
class SyncMapItemInstance(InstanceResource):
class QueryFromBoundType(object):
INCLUSIVE = "inclusive"
EXCLUSIVE = "exclusive"
class QueryResultOrder(object):
ASC = "asc"
DESC = "desc"
"""
:ivar key:
:ivar account_sid:
:ivar service_sid:
:ivar map_sid:
:ivar url:
:ivar revision:
:ivar data:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
map_sid: str,
key: Optional[str] = None,
):
super().__init__(version)
self.key: Optional[str] = payload.get("key")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.map_sid: Optional[str] = payload.get("map_sid")
self.url: Optional[str] = payload.get("url")
self.revision: Optional[str] = payload.get("revision")
self.data: Optional[Dict[str, object]] = payload.get("data")
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_created")
)
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_updated")
)
self.created_by: Optional[str] = payload.get("created_by")
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
"key": key or self.key,
}
self._context: Optional[SyncMapItemContext] = None
@property
def _proxy(self) -> "SyncMapItemContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncMapItemContext for this SyncMapItemInstance
"""
if self._context is None:
self._context = SyncMapItemContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=self._solution["key"],
)
return self._context
def delete(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Deletes the SyncMapItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
if_match=if_match,
)
async def delete_async(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
if_match=if_match,
)
def fetch(self) -> "SyncMapItemInstance":
"""
Fetch the SyncMapItemInstance
:returns: The fetched SyncMapItemInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncMapItemInstance":
"""
Asynchronous coroutine to fetch the SyncMapItemInstance
:returns: The fetched SyncMapItemInstance
"""
return await self._proxy.fetch_async()
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> "SyncMapItemInstance":
"""
Update the SyncMapItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncMapItemInstance
"""
return self._proxy.update(
data=data,
if_match=if_match,
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> "SyncMapItemInstance":
"""
Asynchronous coroutine to update the SyncMapItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncMapItemInstance
"""
return await self._proxy.update_async(
data=data,
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 "<Twilio.Preview.Sync.SyncMapItemInstance {}>".format(context)
class SyncMapItemContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, map_sid: str, key: str):
"""
Initialize the SyncMapItemContext
:param version: Version that contains the resource
:param service_sid:
:param map_sid:
:param key:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
"key": key,
}
self._uri = "/Services/{service_sid}/Maps/{map_sid}/Items/{key}".format(
**self._solution
)
def delete(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Deletes the SyncMapItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"If-Match": if_match,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(self, if_match: Union[str, object] = values.unset) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapItemInstance
:param if_match: The If-Match HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"If-Match": if_match,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> SyncMapItemInstance:
"""
Fetch the SyncMapItemInstance
:returns: The fetched SyncMapItemInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=self._solution["key"],
)
async def fetch_async(self) -> SyncMapItemInstance:
"""
Asynchronous coroutine to fetch the SyncMapItemInstance
:returns: The fetched SyncMapItemInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=self._solution["key"],
)
def update(
self, data: object, if_match: Union[str, object] = values.unset
) -> SyncMapItemInstance:
"""
Update the SyncMapItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncMapItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=self._solution["key"],
)
async def update_async(
self, data: object, if_match: Union[str, object] = values.unset
) -> SyncMapItemInstance:
"""
Asynchronous coroutine to update the SyncMapItemInstance
:param data:
:param if_match: The If-Match HTTP request header
:returns: The updated SyncMapItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
headers = values.of(
{
"If-Match": if_match,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=self._solution["key"],
)
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 "<Twilio.Preview.Sync.SyncMapItemContext {}>".format(context)
class SyncMapItemPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncMapItemInstance:
"""
Build an instance of SyncMapItemInstance
:param payload: Payload response from the API
"""
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapItemPage>"
class SyncMapItemList(ListResource):
def __init__(self, version: Version, service_sid: str, map_sid: str):
"""
Initialize the SyncMapItemList
:param version: Version that contains the resource
:param service_sid:
:param map_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
}
self._uri = "/Services/{service_sid}/Maps/{map_sid}/Items".format(
**self._solution
)
def create(self, key: str, data: object) -> SyncMapItemInstance:
"""
Create the SyncMapItemInstance
:param key:
:param data:
:returns: The created SyncMapItemInstance
"""
data = values.of(
{
"Key": key,
"Data": serialize.object(data),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
)
async def create_async(self, key: str, data: object) -> SyncMapItemInstance:
"""
Asynchronously create the SyncMapItemInstance
:param key:
:param data:
:returns: The created SyncMapItemInstance
"""
data = values.of(
{
"Key": key,
"Data": serialize.object(data),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapItemInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
)
def stream(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncMapItemInstance]:
"""
Streams SyncMapItemInstance records from the API as a generator stream.
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 &quot;SyncMapItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
:returns: Generator that will yield up to limit results
"""
limits = self._version.read_limits(limit, page_size)
page = self.page(
order=order, from_=from_, bounds=bounds, page_size=limits["page_size"]
)
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncMapItemInstance]:
"""
Asynchronously streams SyncMapItemInstance records from the API as a generator stream.
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 &quot;SyncMapItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
:returns: Generator that will yield up to limit results
"""
limits = self._version.read_limits(limit, page_size)
page = await self.page_async(
order=order, from_=from_, bounds=bounds, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapItemInstance]:
"""
Lists SyncMapItemInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;SyncMapItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
order=order,
from_=from_,
bounds=bounds,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapItemInstance]:
"""
Asynchronously lists SyncMapItemInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;SyncMapItemInstance.QueryResultOrder&quot; order:
:param str from_:
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds:
: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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return [
record
async for record in await self.stream_async(
order=order,
from_=from_,
bounds=bounds,
limit=limit,
page_size=page_size,
)
]
def page(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncMapItemPage:
"""
Retrieve a single page of SyncMapItemInstance records from the API.
Request is executed immediately
:param order:
:param from_:
:param bounds:
: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 SyncMapItemInstance
"""
data = values.of(
{
"Order": order,
"From": from_,
"Bounds": bounds,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncMapItemPage(self._version, response, self._solution)
async def page_async(
self,
order: Union["SyncMapItemInstance.QueryResultOrder", object] = values.unset,
from_: Union[str, object] = values.unset,
bounds: Union["SyncMapItemInstance.QueryFromBoundType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncMapItemPage:
"""
Asynchronously retrieve a single page of SyncMapItemInstance records from the API.
Request is executed immediately
:param order:
:param from_:
:param bounds:
: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 SyncMapItemInstance
"""
data = values.of(
{
"Order": order,
"From": from_,
"Bounds": bounds,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncMapItemPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncMapItemPage:
"""
Retrieve a specific page of SyncMapItemInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapItemInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncMapItemPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncMapItemPage:
"""
Asynchronously retrieve a specific page of SyncMapItemInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapItemInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncMapItemPage(self._version, response, self._solution)
def get(self, key: str) -> SyncMapItemContext:
"""
Constructs a SyncMapItemContext
:param key:
"""
return SyncMapItemContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=key,
)
def __call__(self, key: str) -> SyncMapItemContext:
"""
Constructs a SyncMapItemContext
:param key:
"""
return SyncMapItemContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
key=key,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapItemList>"
@@ -0,0 +1,590 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Preview
This is the public Twilio REST API.
NOTE: This class is auto generated by OpenAPI Generator.
https://openapi-generator.tech
Do not edit the class manually.
"""
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
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
from twilio.base.version import Version
from twilio.base.page import Page
class SyncMapPermissionInstance(InstanceResource):
"""
:ivar account_sid: The unique SID identifier of the Twilio Account.
:ivar service_sid: The unique SID identifier of the Sync Service Instance.
:ivar map_sid: The unique SID identifier of the Sync Map to which the Permission applies.
:ivar identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
:ivar read: Boolean flag specifying whether the identity can read the Sync Map and its Items.
:ivar write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync Map.
:ivar manage: Boolean flag specifying whether the identity can delete the Sync Map.
:ivar url: Contains an absolute URL for this Sync Map Permission.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
map_sid: str,
identity: Optional[str] = None,
):
super().__init__(version)
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.map_sid: Optional[str] = payload.get("map_sid")
self.identity: Optional[str] = payload.get("identity")
self.read: Optional[bool] = payload.get("read")
self.write: Optional[bool] = payload.get("write")
self.manage: Optional[bool] = payload.get("manage")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
"identity": identity or self.identity,
}
self._context: Optional[SyncMapPermissionContext] = None
@property
def _proxy(self) -> "SyncMapPermissionContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncMapPermissionContext for this SyncMapPermissionInstance
"""
if self._context is None:
self._context = SyncMapPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=self._solution["identity"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the SyncMapPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "SyncMapPermissionInstance":
"""
Fetch the SyncMapPermissionInstance
:returns: The fetched SyncMapPermissionInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncMapPermissionInstance":
"""
Asynchronous coroutine to fetch the SyncMapPermissionInstance
:returns: The fetched SyncMapPermissionInstance
"""
return await self._proxy.fetch_async()
def update(
self, read: bool, write: bool, manage: bool
) -> "SyncMapPermissionInstance":
"""
Update the SyncMapPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Map.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync Map.
:param manage: Boolean flag specifying whether the identity can delete the Sync Map.
:returns: The updated SyncMapPermissionInstance
"""
return self._proxy.update(
read=read,
write=write,
manage=manage,
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> "SyncMapPermissionInstance":
"""
Asynchronous coroutine to update the SyncMapPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Map.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync Map.
:param manage: Boolean flag specifying whether the identity can delete the Sync Map.
:returns: The updated SyncMapPermissionInstance
"""
return await self._proxy.update_async(
read=read,
write=write,
manage=manage,
)
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 "<Twilio.Preview.Sync.SyncMapPermissionInstance {}>".format(context)
class SyncMapPermissionContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, map_sid: str, identity: str):
"""
Initialize the SyncMapPermissionContext
:param version: Version that contains the resource
:param service_sid: The unique SID identifier of the Sync Service Instance.
:param map_sid: Identifier of the Sync Map. Either a SID or a unique name.
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
"identity": identity,
}
self._uri = (
"/Services/{service_sid}/Maps/{map_sid}/Permissions/{identity}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the SyncMapPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return self._version.delete(
method="DELETE",
uri=self._uri,
)
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncMapPermissionInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> SyncMapPermissionInstance:
"""
Fetch the SyncMapPermissionInstance
:returns: The fetched SyncMapPermissionInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncMapPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=self._solution["identity"],
)
async def fetch_async(self) -> SyncMapPermissionInstance:
"""
Asynchronous coroutine to fetch the SyncMapPermissionInstance
:returns: The fetched SyncMapPermissionInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncMapPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=self._solution["identity"],
)
def update(
self, read: bool, write: bool, manage: bool
) -> SyncMapPermissionInstance:
"""
Update the SyncMapPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Map.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync Map.
:param manage: Boolean flag specifying whether the identity can delete the Sync Map.
:returns: The updated SyncMapPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=self._solution["identity"],
)
async def update_async(
self, read: bool, write: bool, manage: bool
) -> SyncMapPermissionInstance:
"""
Asynchronous coroutine to update the SyncMapPermissionInstance
:param read: Boolean flag specifying whether the identity can read the Sync Map.
:param write: Boolean flag specifying whether the identity can create, update and delete Items of the Sync Map.
:param manage: Boolean flag specifying whether the identity can delete the Sync Map.
:returns: The updated SyncMapPermissionInstance
"""
data = values.of(
{
"Read": read,
"Write": write,
"Manage": manage,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=self._solution["identity"],
)
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 "<Twilio.Preview.Sync.SyncMapPermissionContext {}>".format(context)
class SyncMapPermissionPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncMapPermissionInstance:
"""
Build an instance of SyncMapPermissionInstance
:param payload: Payload response from the API
"""
return SyncMapPermissionInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapPermissionPage>"
class SyncMapPermissionList(ListResource):
def __init__(self, version: Version, service_sid: str, map_sid: str):
"""
Initialize the SyncMapPermissionList
:param version: Version that contains the resource
:param service_sid:
:param map_sid: Identifier of the Sync Map. Either a SID or a unique name.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"map_sid": map_sid,
}
self._uri = "/Services/{service_sid}/Maps/{map_sid}/Permissions".format(
**self._solution
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncMapPermissionInstance]:
"""
Streams SyncMapPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[SyncMapPermissionInstance]:
"""
Asynchronously streams SyncMapPermissionInstance records from the API as a generator stream.
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
the default value of 50 records. If no page_size is defined
but a limit is defined, stream() will attempt to read the
limit with the most efficient page size, i.e. min(limit, 1000)
: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"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapPermissionInstance]:
"""
Lists SyncMapPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
:returns: list that will contain up to limit results
"""
return list(
self.stream(
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[SyncMapPermissionInstance]:
"""
Asynchronously lists SyncMapPermissionInstance 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
the default value of 50 records. If no page_size is defined
but a limit is defined, list() will attempt to read the limit
with the most efficient page size, i.e. min(limit, 1000)
: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,
)
]
def page(
self,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> SyncMapPermissionPage:
"""
Retrieve a single page of SyncMapPermissionInstance 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 SyncMapPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncMapPermissionPage(self._version, response, self._solution)
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,
) -> SyncMapPermissionPage:
"""
Asynchronously retrieve a single page of SyncMapPermissionInstance 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 SyncMapPermissionInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return SyncMapPermissionPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncMapPermissionPage:
"""
Retrieve a specific page of SyncMapPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapPermissionInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncMapPermissionPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncMapPermissionPage:
"""
Asynchronously retrieve a specific page of SyncMapPermissionInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncMapPermissionInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncMapPermissionPage(self._version, response, self._solution)
def get(self, identity: str) -> SyncMapPermissionContext:
"""
Constructs a SyncMapPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return SyncMapPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=identity,
)
def __call__(self, identity: str) -> SyncMapPermissionContext:
"""
Constructs a SyncMapPermissionContext
:param identity: Arbitrary string identifier representing a human user associated with an FPA token, assigned by the developer.
"""
return SyncMapPermissionContext(
self._version,
service_sid=self._solution["service_sid"],
map_sid=self._solution["map_sid"],
identity=identity,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Preview.Sync.SyncMapPermissionList>"