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,43 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
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.domain import Domain
from twilio.rest import Client
from twilio.rest.sync.v1 import V1
class SyncBase(Domain):
def __init__(self, twilio: Client):
"""
Initialize the Sync Domain
:returns: Domain for Sync
"""
super().__init__(twilio, "https://sync.twilio.com")
self._v1: Optional[V1] = None
@property
def v1(self) -> V1:
"""
:returns: Versions v1 of Sync
"""
if self._v1 is None:
self._v1 = V1(self)
return self._v1
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Sync>"
@@ -0,0 +1,15 @@
from warnings import warn
from twilio.rest.sync.SyncBase import SyncBase
from twilio.rest.sync.v1.service import ServiceList
class Sync(SyncBase):
@property
def services(self) -> ServiceList:
warn(
"services is deprecated. Use v1.services instead.",
DeprecationWarning,
stacklevel=2,
)
return self.v1.services
@@ -0,0 +1,42 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service import ServiceList
class V1(Version):
def __init__(self, domain: Domain):
"""
Initialize the V1 version of Sync
:param domain: The Twilio.sync domain
"""
super().__init__(domain, "v1")
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.Sync.V1>"
@@ -0,0 +1,789 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service.document import DocumentList
from twilio.rest.sync.v1.service.sync_list import SyncListList
from twilio.rest.sync.v1.service.sync_map import SyncMapList
from twilio.rest.sync.v1.service.sync_stream import SyncStreamList
class ServiceInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Service resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource. It is a read-only property, it cannot be assigned using REST API.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Service resource.
:ivar friendly_name: The string that you assigned to describe the resource.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar url: The absolute URL of the Service resource.
:ivar webhook_url: The URL we call when Sync objects are manipulated.
:ivar webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
:ivar reachability_webhooks_enabled: Whether the service instance calls `webhook_url` when client endpoints connect to Sync. The default is `false`.
:ivar acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource. It is disabled (false) by default.
:ivar reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:ivar reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before `webhook_url` is called, if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the reachability event from occurring.
:ivar links: The URLs of related resources.
"""
def __init__(
self, version: Version, payload: Dict[str, Any], 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.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.webhooks_from_rest_enabled: Optional[bool] = payload.get(
"webhooks_from_rest_enabled"
)
self.reachability_webhooks_enabled: Optional[bool] = payload.get(
"reachability_webhooks_enabled"
)
self.acl_enabled: Optional[bool] = payload.get("acl_enabled")
self.reachability_debouncing_enabled: Optional[bool] = payload.get(
"reachability_debouncing_enabled"
)
self.reachability_debouncing_window: Optional[int] = deserialize.integer(
payload.get("reachability_debouncing_window")
)
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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> "ServiceInstance":
"""
Update the ServiceInstance
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param friendly_name: A string that you assign to describe the resource.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the webhook is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the webhook from being called.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
: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,
reachability_debouncing_enabled=reachability_debouncing_enabled,
reachability_debouncing_window=reachability_debouncing_window,
webhooks_from_rest_enabled=webhooks_from_rest_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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> "ServiceInstance":
"""
Asynchronous coroutine to update the ServiceInstance
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param friendly_name: A string that you assign to describe the resource.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the webhook is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the webhook from being called.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
: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,
reachability_debouncing_enabled=reachability_debouncing_enabled,
reachability_debouncing_window=reachability_debouncing_window,
webhooks_from_rest_enabled=webhooks_from_rest_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
@property
def sync_streams(self) -> SyncStreamList:
"""
Access the sync_streams
"""
return self._proxy.sync_streams
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.Sync.V1.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: The SID of the Service resource to update.
"""
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
self._sync_streams: Optional[SyncStreamList] = 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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Update the ServiceInstance
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param friendly_name: A string that you assign to describe the resource.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the webhook is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the webhook from being called.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
:returns: The updated ServiceInstance
"""
data = values.of(
{
"WebhookUrl": webhook_url,
"FriendlyName": friendly_name,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
"ReachabilityDebouncingEnabled": reachability_debouncing_enabled,
"ReachabilityDebouncingWindow": reachability_debouncing_window,
"WebhooksFromRestEnabled": webhooks_from_rest_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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Asynchronous coroutine to update the ServiceInstance
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param friendly_name: A string that you assign to describe the resource.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the webhook is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the webhook from being called.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
:returns: The updated ServiceInstance
"""
data = values.of(
{
"WebhookUrl": webhook_url,
"FriendlyName": friendly_name,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
"ReachabilityDebouncingEnabled": reachability_debouncing_enabled,
"ReachabilityDebouncingWindow": reachability_debouncing_window,
"WebhooksFromRestEnabled": webhooks_from_rest_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
@property
def sync_streams(self) -> SyncStreamList:
"""
Access the sync_streams
"""
if self._sync_streams is None:
self._sync_streams = SyncStreamList(
self._version,
self._solution["sid"],
)
return self._sync_streams
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.Sync.V1.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.Sync.V1.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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Create the ServiceInstance
:param friendly_name: A string that you assign to describe the resource.
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the `webhook_url` is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the call to `webhook_url`.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
:returns: The created ServiceInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"WebhookUrl": webhook_url,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
"ReachabilityDebouncingEnabled": reachability_debouncing_enabled,
"ReachabilityDebouncingWindow": reachability_debouncing_window,
"WebhooksFromRestEnabled": webhooks_from_rest_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,
reachability_debouncing_enabled: Union[bool, object] = values.unset,
reachability_debouncing_window: Union[int, object] = values.unset,
webhooks_from_rest_enabled: Union[bool, object] = values.unset,
) -> ServiceInstance:
"""
Asynchronously create the ServiceInstance
:param friendly_name: A string that you assign to describe the resource.
:param webhook_url: The URL we should call when Sync objects are manipulated.
:param reachability_webhooks_enabled: Whether the service instance should call `webhook_url` when client endpoints connect to Sync. The default is `false`.
:param acl_enabled: Whether token identities in the Service must be granted access to Sync objects by using the [Permissions](https://www.twilio.com/docs/sync/api/sync-permissions) resource.
:param reachability_debouncing_enabled: Whether every `endpoint_disconnected` event should occur after a configurable delay. The default is `false`, where the `endpoint_disconnected` event occurs immediately after disconnection. When `true`, intervening reconnections can prevent the `endpoint_disconnected` event.
:param reachability_debouncing_window: The reachability event delay in milliseconds if `reachability_debouncing_enabled` = `true`. Must be between 1,000 and 30,000 and defaults to 5,000. This is the number of milliseconds after the last running client disconnects, and a Sync identity is declared offline, before the `webhook_url` is called if all endpoints remain offline. A reconnection from the same identity by any endpoint during this interval prevents the call to `webhook_url`.
:param webhooks_from_rest_enabled: Whether the Service instance should call `webhook_url` when the REST API is used to update Sync objects. The default is `false`.
:returns: The created ServiceInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"WebhookUrl": webhook_url,
"ReachabilityWebhooksEnabled": reachability_webhooks_enabled,
"AclEnabled": acl_enabled,
"ReachabilityDebouncingEnabled": reachability_debouncing_enabled,
"ReachabilityDebouncingWindow": reachability_debouncing_window,
"WebhooksFromRestEnabled": webhooks_from_rest_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: The SID of the Service resource to update.
"""
return ServiceContext(self._version, sid=sid)
def __call__(self, sid: str) -> ServiceContext:
"""
Constructs a ServiceContext
:param sid: The SID of the Service resource to update.
"""
return ServiceContext(self._version, sid=sid)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Sync.V1.ServiceList>"
@@ -0,0 +1,686 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service.document.document_permission import (
DocumentPermissionList,
)
class DocumentInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Document resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource and can be up to 320 characters long.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Document resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar url: The absolute URL of the Document resource.
:ivar links: The URLs of resources related to the Sync Document.
:ivar revision: The current revision of the Sync Document, represented as a string. The `revision` property is used with conditional updates to ensure data consistency.
:ivar data: An arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:ivar date_expires: The date and time in GMT when the Sync Document expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the Sync Document does not expire, this value is `null`. The Document resource might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the Sync Document's creator. If the Sync Document is created from the client SDK, the value matches the Access Token's `identity` field. If the Sync Document was created from the REST API, the value is `system`.
"""
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_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> "DocumentInstance":
"""
Update the DocumentInstance
:param if_match: The If-Match HTTP request header
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (time-to-live).
:returns: The updated DocumentInstance
"""
return self._proxy.update(
if_match=if_match,
data=data,
ttl=ttl,
)
async def update_async(
self,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> "DocumentInstance":
"""
Asynchronous coroutine to update the DocumentInstance
:param if_match: The If-Match HTTP request header
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (time-to-live).
:returns: The updated DocumentInstance
"""
return await self._proxy.update_async(
if_match=if_match,
data=data,
ttl=ttl,
)
@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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Document resource to update.
:param sid: The SID of the Document resource to update. Can be the Document resource's `sid` or its `unique_name`.
"""
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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> DocumentInstance:
"""
Update the DocumentInstance
:param if_match: The If-Match HTTP request header
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (time-to-live).
:returns: The updated DocumentInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
}
)
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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> DocumentInstance:
"""
Asynchronous coroutine to update the DocumentInstance
:param if_match: The If-Match HTTP request header
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (time-to-live).
:returns: The updated DocumentInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
}
)
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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Document resources to read.
"""
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,
ttl: Union[int, object] = values.unset,
) -> DocumentInstance:
"""
Create the DocumentInstance
:param unique_name: An application-defined string that uniquely identifies the Sync Document
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (the Sync Document's time-to-live).
:returns: The created DocumentInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Data": serialize.object(data),
"Ttl": ttl,
}
)
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,
ttl: Union[int, object] = values.unset,
) -> DocumentInstance:
"""
Asynchronously create the DocumentInstance
:param unique_name: An application-defined string that uniquely identifies the Sync Document
:param data: A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Document expires and is deleted (the Sync Document's time-to-live).
:returns: The created DocumentInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Data": serialize.object(data),
"Ttl": ttl,
}
)
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: The SID of the Document resource to update. Can be the Document resource's `sid` or its `unique_name`.
"""
return DocumentContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> DocumentContext:
"""
Constructs a DocumentContext
:param sid: The SID of the Document resource to update. Can be the Document resource's `sid` or its `unique_name`.
"""
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.Sync.V1.DocumentList>"
@@ -0,0 +1,592 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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 SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Document Permission resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar document_sid: The SID of the Sync Document to which the Document Permission applies.
:ivar identity: The application-defined string that uniquely identifies the resource's User within the Service to an FPA token.
:ivar read: Whether the identity can read the Sync Document.
:ivar write: Whether the identity can update the Sync Document.
:ivar manage: Whether the identity can delete the Sync Document.
:ivar url: The absolute URL of the Sync Document Permission resource.
"""
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: Whether the identity can read the Sync Document. Default value is `false`.
:param write: Whether the identity can update the Sync Document. Default value is `false`.
:param manage: Whether the identity can delete the Sync Document. Default value is `false`.
: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: Whether the identity can read the Sync Document. Default value is `false`.
:param write: Whether the identity can update the Sync Document. Default value is `false`.
:param manage: Whether the identity can delete the Sync Document. Default value is `false`.
: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.Sync.V1.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 SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Document Permission resource to update.
:param document_sid: The SID of the Sync Document with the Document Permission resource to update. Can be the Document resource's `sid` or its `unique_name`.
:param identity: The application-defined string that uniquely identifies the User's Document Permission resource to update.
"""
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: Whether the identity can read the Sync Document. Default value is `false`.
:param write: Whether the identity can update the Sync Document. Default value is `false`.
:param manage: Whether the identity can delete the Sync Document. Default value is `false`.
: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: Whether the identity can read the Sync Document. Default value is `false`.
:param write: Whether the identity can update the Sync Document. Default value is `false`.
:param manage: Whether the identity can delete the Sync Document. Default value is `false`.
: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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Document Permission resources to read.
:param document_sid: The SID of the Sync Document with the Document Permission resources to read. Can be the Document resource's `sid` or its `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: The application-defined string that uniquely identifies the User's Document Permission resource to update.
"""
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: The application-defined string that uniquely identifies the User's Document Permission resource to update.
"""
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.Sync.V1.DocumentPermissionList>"
@@ -0,0 +1,690 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service.sync_list.sync_list_item import SyncListItemList
from twilio.rest.sync.v1.service.sync_list.sync_list_permission import (
SyncListPermissionList,
)
class SyncListInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Sync List resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Sync List resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar url: The absolute URL of the Sync List resource.
:ivar links: The URLs of the Sync List's nested resources.
:ivar revision: The current revision of the Sync List, represented as a string.
:ivar date_expires: The date and time in GMT when the Sync List expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the Sync List does not expire, this value is `null`. The Sync List might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the Sync List's creator. If the Sync List is created from the client SDK, the value matches the Access Token's `identity` field. If the Sync List was created from the REST API, the value is `system`.
"""
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_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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()
def update(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncListInstance":
"""
Update the SyncListInstance
:param ttl: An alias for `collection_ttl`. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The updated SyncListInstance
"""
return self._proxy.update(
ttl=ttl,
collection_ttl=collection_ttl,
)
async def update_async(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncListInstance":
"""
Asynchronous coroutine to update the SyncListInstance
:param ttl: An alias for `collection_ttl`. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The updated SyncListInstance
"""
return await self._proxy.update_async(
ttl=ttl,
collection_ttl=collection_ttl,
)
@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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync List resource to update.
:param sid: The SID of the Sync List resource to update. Can be the Sync List resource's `sid` or its `unique_name`.
"""
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"],
)
def update(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListInstance:
"""
Update the SyncListInstance
:param ttl: An alias for `collection_ttl`. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The updated SyncListInstance
"""
data = values.of(
{
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return SyncListInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListInstance:
"""
Asynchronous coroutine to update the SyncListInstance
:param ttl: An alias for `collection_ttl`. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The updated SyncListInstance
"""
data = values.of(
{
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync List resources to read.
"""
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,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListInstance:
"""
Create the SyncListInstance
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be unique within its Service and it can be up to 320 characters long. The `unique_name` value can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: Alias for collection_ttl. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The created SyncListInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
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,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListInstance:
"""
Asynchronously create the SyncListInstance
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be unique within its Service and it can be up to 320 characters long. The `unique_name` value can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: Alias for collection_ttl. If both are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync List expires (time-to-live) and is deleted.
:returns: The created SyncListInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
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: The SID of the Sync List resource to update. Can be the Sync List resource's `sid` or its `unique_name`.
"""
return SyncListContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> SyncListContext:
"""
Constructs a SyncListContext
:param sid: The SID of the Sync List resource to update. Can be the Sync List resource's `sid` or its `unique_name`.
"""
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.Sync.V1.SyncListList>"
@@ -0,0 +1,794 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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: The automatically generated index of the List Item. The `index` values of the List Items in a Sync List can have gaps in their sequence.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the List Item resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar list_sid: The SID of the Sync List that contains the List Item.
:ivar url: The absolute URL of the List Item resource.
:ivar revision: The current revision of the item, represented as a string.
:ivar data: An arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:ivar date_expires: The date and time in GMT when the List Item expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the List Item does not expire, this value is `null`. The List Item resource might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the List Item's creator. If the item is created from the client SDK, the value matches the Access Token's `identity` field. If the item was created from the REST API, the value is `system`.
"""
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_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncListItemInstance":
"""
Update the SyncListItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted. This parameter can only be used when the List Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncListItemInstance
"""
return self._proxy.update(
if_match=if_match,
data=data,
ttl=ttl,
item_ttl=item_ttl,
collection_ttl=collection_ttl,
)
async def update_async(
self,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncListItemInstance":
"""
Asynchronous coroutine to update the SyncListItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted. This parameter can only be used when the List Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncListItemInstance
"""
return await self._proxy.update_async(
if_match=if_match,
data=data,
ttl=ttl,
item_ttl=item_ttl,
collection_ttl=collection_ttl,
)
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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync List Item resource to update.
:param list_sid: The SID of the Sync List with the Sync List Item resource to update. Can be the Sync List resource's `sid` or its `unique_name`.
:param index: The index of the Sync List Item resource to update.
"""
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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListItemInstance:
"""
Update the SyncListItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted. This parameter can only be used when the List Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListItemInstance:
"""
Asynchronous coroutine to update the SyncListItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted. This parameter can only be used when the List Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the List Item resources to read.
:param list_sid: The SID of the Sync List with the List Items to read. Can be the Sync List resource's `sid` or its `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}/Items".format(
**self._solution
)
def create(
self,
data: object,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListItemInstance:
"""
Create the SyncListItemInstance
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted.
:returns: The created SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncListItemInstance:
"""
Asynchronously create the SyncListItemInstance
:param data: A JSON string that represents an arbitrary, schema-less object that the List Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the List Item's parent Sync List expires (time-to-live) and is deleted.
:returns: The created SyncListItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param str from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param str from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param str from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param str from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param &quot;SyncListItemInstance.QueryFromBoundType&quot; bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: How to order the List Items returned by their `index` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending.
:param from_: The `index` of the first Sync List Item resource to read. See also `bounds`.
:param bounds: Whether to include the List Item referenced by the `from` parameter. Can be: `inclusive` to include the List Item referenced by the `from` parameter or `exclusive` to start with the next List Item. The default value is `inclusive`.
: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: The index of the Sync List Item resource to update.
"""
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: The index of the Sync List Item resource to update.
"""
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.Sync.V1.SyncListItemList>"
@@ -0,0 +1,592 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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 SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Sync List Permission resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar list_sid: The SID of the Sync List to which the Permission applies.
:ivar identity: The application-defined string that uniquely identifies the resource's User within the Service to an FPA token.
:ivar read: Whether the identity can read the Sync List and its Items.
:ivar write: Whether the identity can create, update, and delete Items in the Sync List.
:ivar manage: Whether the identity can delete the Sync List.
:ivar url: The absolute URL of the Sync List Permission resource.
"""
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: Whether the identity can read the Sync List and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync List. Default value is `false`.
:param manage: Whether the identity can delete the Sync List. Default value is `false`.
: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: Whether the identity can read the Sync List and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync List. Default value is `false`.
:param manage: Whether the identity can delete the Sync List. Default value is `false`.
: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.Sync.V1.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 SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync List Permission resource to update.
:param list_sid: The SID of the Sync List with the Sync List Permission resource to update. Can be the Sync List resource's `sid` or its `unique_name`.
:param identity: The application-defined string that uniquely identifies the User's Sync List Permission resource to update.
"""
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: Whether the identity can read the Sync List and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync List. Default value is `false`.
:param manage: Whether the identity can delete the Sync List. Default value is `false`.
: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: Whether the identity can read the Sync List and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync List. Default value is `false`.
:param manage: Whether the identity can delete the Sync List. Default value is `false`.
: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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync List Permission resources to read.
:param list_sid: The SID of the Sync List with the Sync List Permission resources to read. Can be the Sync List resource's `sid` or its `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: The application-defined string that uniquely identifies the User's Sync List Permission resource to update.
"""
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: The application-defined string that uniquely identifies the User's Sync List Permission resource to update.
"""
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.Sync.V1.SyncListPermissionList>"
@@ -0,0 +1,690 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service.sync_map.sync_map_item import SyncMapItemList
from twilio.rest.sync.v1.service.sync_map.sync_map_permission import (
SyncMapPermissionList,
)
class SyncMapInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Sync Map resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Sync Map resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar url: The absolute URL of the Sync Map resource.
:ivar links: The URLs of the Sync Map's nested resources.
:ivar revision: The current revision of the Sync Map, represented as a string.
:ivar date_expires: The date and time in GMT when the Sync Map expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the Sync Map does not expire, this value is `null`. The Sync Map might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the Sync Map's creator. If the Sync Map is created from the client SDK, the value matches the Access Token's `identity` field. If the Sync Map was created from the REST API, the value is `system`.
"""
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_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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()
def update(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncMapInstance":
"""
Update the SyncMapInstance
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The updated SyncMapInstance
"""
return self._proxy.update(
ttl=ttl,
collection_ttl=collection_ttl,
)
async def update_async(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncMapInstance":
"""
Asynchronous coroutine to update the SyncMapInstance
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The updated SyncMapInstance
"""
return await self._proxy.update_async(
ttl=ttl,
collection_ttl=collection_ttl,
)
@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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Map resource to update.
:param sid: The SID of the Sync Map resource to update. Can be the Sync Map's `sid` or its `unique_name`.
"""
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"],
)
def update(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapInstance:
"""
Update the SyncMapInstance
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The updated SyncMapInstance
"""
data = values.of(
{
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return SyncMapInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapInstance:
"""
Asynchronous coroutine to update the SyncMapInstance
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The updated SyncMapInstance
"""
data = values.of(
{
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Map resources to read.
"""
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,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapInstance:
"""
Create the SyncMapInstance
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The created SyncMapInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
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,
ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapInstance:
"""
Asynchronously create the SyncMapInstance
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: An alias for `collection_ttl`. If both parameters are provided, this value is ignored.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Sync Map expires (time-to-live) and is deleted.
:returns: The created SyncMapInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
"CollectionTtl": collection_ttl,
}
)
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: The SID of the Sync Map resource to update. Can be the Sync Map's `sid` or its `unique_name`.
"""
return SyncMapContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> SyncMapContext:
"""
Constructs a SyncMapContext
:param sid: The SID of the Sync Map resource to update. Can be the Sync Map's `sid` or its `unique_name`.
"""
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.Sync.V1.SyncMapList>"
@@ -0,0 +1,800 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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: The unique, user-defined key for the Map Item.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Map Item resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar map_sid: The SID of the Sync Map that contains the Map Item.
:ivar url: The absolute URL of the Map Item resource.
:ivar revision: The current revision of the Map Item, represented as a string.
:ivar data: An arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:ivar date_expires: The date and time in GMT when the Map Item expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the Map Item does not expire, this value is `null`. The Map Item might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the Map Item's creator. If the Map Item is created from the client SDK, the value matches the Access Token's `identity` field. If the Map Item was created from the REST API, the value is `system`.
"""
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_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncMapItemInstance":
"""
Update the SyncMapItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncMapItemInstance
"""
return self._proxy.update(
if_match=if_match,
data=data,
ttl=ttl,
item_ttl=item_ttl,
collection_ttl=collection_ttl,
)
async def update_async(
self,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> "SyncMapItemInstance":
"""
Asynchronous coroutine to update the SyncMapItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncMapItemInstance
"""
return await self._proxy.update_async(
if_match=if_match,
data=data,
ttl=ttl,
item_ttl=item_ttl,
collection_ttl=collection_ttl,
)
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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Map Item resource to update.
:param map_sid: The SID of the Sync Map with the Sync Map Item resource to update. Can be the Sync Map resource's `sid` or its `unique_name`.
:param key: The `key` value of the Sync Map Item resource to update.
"""
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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
: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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapItemInstance:
"""
Update the SyncMapItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncMapItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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,
if_match: Union[str, object] = values.unset,
data: Union[object, object] = values.unset,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapItemInstance:
"""
Asynchronous coroutine to update the SyncMapItemInstance
:param if_match: If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item's `data` or `ttl` is updated in the same request.
:returns: The updated SyncMapItemInstance
"""
data = values.of(
{
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Map Item resources to read.
:param map_sid: The SID of the Sync Map with the Sync Map Item resource to fetch. Can be the Sync Map resource's `sid` or its `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}/Items".format(
**self._solution
)
def create(
self,
key: str,
data: object,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapItemInstance:
"""
Create the SyncMapItemInstance
:param key: The unique, user-defined key for the Map Item. Can be up to 320 characters long.
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted.
:returns: The created SyncMapItemInstance
"""
data = values.of(
{
"Key": key,
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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,
ttl: Union[int, object] = values.unset,
item_ttl: Union[int, object] = values.unset,
collection_ttl: Union[int, object] = values.unset,
) -> SyncMapItemInstance:
"""
Asynchronously create the SyncMapItemInstance
:param key: The unique, user-defined key for the Map Item. Can be up to 320 characters long.
:param data: A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
:param ttl: An alias for `item_ttl`. If both parameters are provided, this value is ignored.
:param item_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item expires (time-to-live) and is deleted.
:param collection_ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Map Item's parent Sync Map expires (time-to-live) and is deleted.
:returns: The created SyncMapItemInstance
"""
data = values.of(
{
"Key": key,
"Data": serialize.object(data),
"Ttl": ttl,
"ItemTtl": item_ttl,
"CollectionTtl": collection_ttl,
}
)
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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param str from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param str from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param str from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param str from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param &quot;SyncMapItemInstance.QueryFromBoundType&quot; bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: How to order the Map Items returned by their `key` value. Can be: `asc` (ascending) or `desc` (descending) and the default is ascending. Map Items are [ordered lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by Item key.
:param from_: The `key` of the first Sync Map Item resource to read. See also `bounds`.
:param bounds: Whether to include the Map Item referenced by the `from` parameter. Can be: `inclusive` to include the Map Item referenced by the `from` parameter or `exclusive` to start with the next Map Item. The default value is `inclusive`.
: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: The `key` value of the Sync Map Item resource to update.
"""
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: The `key` value of the Sync Map Item resource to update.
"""
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.Sync.V1.SyncMapItemList>"
@@ -0,0 +1,590 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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 SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Sync Map Permission resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar map_sid: The SID of the Sync Map to which the Permission applies.
:ivar identity: The application-defined string that uniquely identifies the resource's User within the Service to an FPA token.
:ivar read: Whether the identity can read the Sync Map and its Items.
:ivar write: Whether the identity can create, update, and delete Items in the Sync Map.
:ivar manage: Whether the identity can delete the Sync Map.
:ivar url: The absolute URL of the Sync Map Permission resource.
"""
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: Whether the identity can read the Sync Map and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync Map. Default value is `false`.
:param manage: Whether the identity can delete the Sync Map. Default value is `false`.
: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: Whether the identity can read the Sync Map and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync Map. Default value is `false`.
:param manage: Whether the identity can delete the Sync Map. Default value is `false`.
: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.Sync.V1.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 SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Map Permission resource to update. Can be the Service's `sid` value or `default`.
:param map_sid: The SID of the Sync Map with the Sync Map Permission resource to update. Can be the Sync Map resource's `sid` or its `unique_name`.
:param identity: The application-defined string that uniquely identifies the User's Sync Map Permission resource to update.
"""
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: Whether the identity can read the Sync Map and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync Map. Default value is `false`.
:param manage: Whether the identity can delete the Sync Map. Default value is `false`.
: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: Whether the identity can read the Sync Map and its Items. Default value is `false`.
:param write: Whether the identity can create, update, and delete Items in the Sync Map. Default value is `false`.
:param manage: Whether the identity can delete the Sync Map. Default value is `false`.
: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.Sync.V1.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.Sync.V1.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: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Map Permission resources to read. Can be the Service's `sid` value or `default`.
:param map_sid: The SID of the Sync Map with the Permission resources to read. Can be the Sync Map resource's `sid` or its `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: The application-defined string that uniquely identifies the User's Sync Map Permission resource to update.
"""
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: The application-defined string that uniquely identifies the User's Sync Map Permission resource to update.
"""
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.Sync.V1.SyncMapPermissionList>"
@@ -0,0 +1,638 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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.sync.v1.service.sync_stream.stream_message import StreamMessageList
class SyncStreamInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Sync Stream resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Sync Stream resource.
:ivar service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) the resource is associated with.
:ivar url: The absolute URL of the Message Stream resource.
:ivar links: The URLs of the Stream's nested resources.
:ivar date_expires: The date and time in GMT when the Message Stream expires and will be deleted, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. If the Message Stream does not expire, this value is `null`. The Stream might not be deleted immediately after it expires.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The identity of the Stream's creator. If the Stream is created from the client SDK, the value matches the Access Token's `identity` field. If the Stream was created from the REST API, the value is 'system'.
"""
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.date_expires: Optional[datetime] = deserialize.iso8601_datetime(
payload.get("date_expires")
)
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[SyncStreamContext] = None
@property
def _proxy(self) -> "SyncStreamContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: SyncStreamContext for this SyncStreamInstance
"""
if self._context is None:
self._context = SyncStreamContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the SyncStreamInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the SyncStreamInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "SyncStreamInstance":
"""
Fetch the SyncStreamInstance
:returns: The fetched SyncStreamInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "SyncStreamInstance":
"""
Asynchronous coroutine to fetch the SyncStreamInstance
:returns: The fetched SyncStreamInstance
"""
return await self._proxy.fetch_async()
def update(self, ttl: Union[int, object] = values.unset) -> "SyncStreamInstance":
"""
Update the SyncStreamInstance
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The updated SyncStreamInstance
"""
return self._proxy.update(
ttl=ttl,
)
async def update_async(
self, ttl: Union[int, object] = values.unset
) -> "SyncStreamInstance":
"""
Asynchronous coroutine to update the SyncStreamInstance
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The updated SyncStreamInstance
"""
return await self._proxy.update_async(
ttl=ttl,
)
@property
def stream_messages(self) -> StreamMessageList:
"""
Access the stream_messages
"""
return self._proxy.stream_messages
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.Sync.V1.SyncStreamInstance {}>".format(context)
class SyncStreamContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the SyncStreamContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Sync Stream resource to update.
:param sid: The SID of the Stream resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Streams/{sid}".format(**self._solution)
self._stream_messages: Optional[StreamMessageList] = None
def delete(self) -> bool:
"""
Deletes the SyncStreamInstance
: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 SyncStreamInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> SyncStreamInstance:
"""
Fetch the SyncStreamInstance
:returns: The fetched SyncStreamInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return SyncStreamInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> SyncStreamInstance:
"""
Asynchronous coroutine to fetch the SyncStreamInstance
:returns: The fetched SyncStreamInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return SyncStreamInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(self, ttl: Union[int, object] = values.unset) -> SyncStreamInstance:
"""
Update the SyncStreamInstance
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The updated SyncStreamInstance
"""
data = values.of(
{
"Ttl": ttl,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return SyncStreamInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self, ttl: Union[int, object] = values.unset
) -> SyncStreamInstance:
"""
Asynchronous coroutine to update the SyncStreamInstance
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The updated SyncStreamInstance
"""
data = values.of(
{
"Ttl": ttl,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncStreamInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def stream_messages(self) -> StreamMessageList:
"""
Access the stream_messages
"""
if self._stream_messages is None:
self._stream_messages = StreamMessageList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._stream_messages
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.Sync.V1.SyncStreamContext {}>".format(context)
class SyncStreamPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> SyncStreamInstance:
"""
Build an instance of SyncStreamInstance
:param payload: Payload response from the API
"""
return SyncStreamInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Sync.V1.SyncStreamPage>"
class SyncStreamList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the SyncStreamList
:param version: Version that contains the resource
:param service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) with the Stream resources to read.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Streams".format(**self._solution)
def create(
self,
unique_name: Union[str, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> SyncStreamInstance:
"""
Create the SyncStreamInstance
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be unique within its Service and it can be up to 320 characters long. The `unique_name` value can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The created SyncStreamInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return SyncStreamInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
unique_name: Union[str, object] = values.unset,
ttl: Union[int, object] = values.unset,
) -> SyncStreamInstance:
"""
Asynchronously create the SyncStreamInstance
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be unique within its Service and it can be up to 320 characters long. The `unique_name` value can be used as an alternative to the `sid` in the URL path to address the resource.
:param ttl: How long, [in seconds](https://www.twilio.com/docs/sync/limits#sync-payload-limits), before the Stream expires and is deleted (time-to-live).
:returns: The created SyncStreamInstance
"""
data = values.of(
{
"UniqueName": unique_name,
"Ttl": ttl,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return SyncStreamInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[SyncStreamInstance]:
"""
Streams SyncStreamInstance 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[SyncStreamInstance]:
"""
Asynchronously streams SyncStreamInstance 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[SyncStreamInstance]:
"""
Lists SyncStreamInstance 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[SyncStreamInstance]:
"""
Asynchronously lists SyncStreamInstance 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,
) -> SyncStreamPage:
"""
Retrieve a single page of SyncStreamInstance 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 SyncStreamInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return SyncStreamPage(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,
) -> SyncStreamPage:
"""
Asynchronously retrieve a single page of SyncStreamInstance 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 SyncStreamInstance
"""
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 SyncStreamPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> SyncStreamPage:
"""
Retrieve a specific page of SyncStreamInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncStreamInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return SyncStreamPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> SyncStreamPage:
"""
Asynchronously retrieve a specific page of SyncStreamInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of SyncStreamInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return SyncStreamPage(self._version, response, self._solution)
def get(self, sid: str) -> SyncStreamContext:
"""
Constructs a SyncStreamContext
:param sid: The SID of the Stream resource to update.
"""
return SyncStreamContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> SyncStreamContext:
"""
Constructs a SyncStreamContext
:param sid: The SID of the Stream resource to update.
"""
return SyncStreamContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Sync.V1.SyncStreamList>"
@@ -0,0 +1,139 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Sync
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, Optional
from twilio.base import serialize, values
from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version
class StreamMessageInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Stream Message resource.
:ivar data: An arbitrary, schema-less object that contains the Stream Message body. Can be up to 4 KiB in length.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
stream_sid: str,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.data: Optional[Dict[str, object]] = payload.get("data")
self._solution = {
"service_sid": service_sid,
"stream_sid": stream_sid,
}
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
return "<Twilio.Sync.V1.StreamMessageInstance {}>".format(context)
class StreamMessageList(ListResource):
def __init__(self, version: Version, service_sid: str, stream_sid: str):
"""
Initialize the StreamMessageList
:param version: Version that contains the resource
:param service_sid: The SID of the [Sync Service](https://www.twilio.com/docs/sync/api/service) to create the new Stream Message in.
:param stream_sid: The SID of the Sync Stream to create the new Stream Message resource for.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"stream_sid": stream_sid,
}
self._uri = "/Services/{service_sid}/Streams/{stream_sid}/Messages".format(
**self._solution
)
def create(self, data: object) -> StreamMessageInstance:
"""
Create the StreamMessageInstance
:param data: A JSON string that represents an arbitrary, schema-less object that makes up the Stream Message body. Can be up to 4 KiB in length.
:returns: The created StreamMessageInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return StreamMessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
stream_sid=self._solution["stream_sid"],
)
async def create_async(self, data: object) -> StreamMessageInstance:
"""
Asynchronously create the StreamMessageInstance
:param data: A JSON string that represents an arbitrary, schema-less object that makes up the Stream Message body. Can be up to 4 KiB in length.
:returns: The created StreamMessageInstance
"""
data = values.of(
{
"Data": serialize.object(data),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return StreamMessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
stream_sid=self._solution["stream_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Sync.V1.StreamMessageList>"