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,54 @@
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.ip_messaging.v1 import V1
from twilio.rest.ip_messaging.v2 import V2
class IpMessagingBase(Domain):
def __init__(self, twilio: Client):
"""
Initialize the IpMessaging Domain
:returns: Domain for IpMessaging
"""
super().__init__(twilio, "https://ip-messaging.twilio.com")
self._v1: Optional[V1] = None
self._v2: Optional[V2] = None
@property
def v1(self) -> V1:
"""
:returns: Versions v1 of IpMessaging
"""
if self._v1 is None:
self._v1 = V1(self)
return self._v1
@property
def v2(self) -> V2:
"""
:returns: Versions v2 of IpMessaging
"""
if self._v2 is None:
self._v2 = V2(self)
return self._v2
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging>"
@@ -0,0 +1,25 @@
from warnings import warn
from twilio.rest.ip_messaging.IpMessagingBase import IpMessagingBase
from twilio.rest.ip_messaging.v2.credential import CredentialList
from twilio.rest.ip_messaging.v2.service import ServiceList
class IpMessaging(IpMessagingBase):
@property
def credentials(self) -> CredentialList:
warn(
"credentials is deprecated. Use v2.credentials instead.",
DeprecationWarning,
stacklevel=2,
)
return self.v2.credentials
@property
def services(self) -> ServiceList:
warn(
"services is deprecated. Use v2.services instead.",
DeprecationWarning,
stacklevel=2,
)
return self.v2.services
@@ -0,0 +1,50 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v1.credential import CredentialList
from twilio.rest.ip_messaging.v1.service import ServiceList
class V1(Version):
def __init__(self, domain: Domain):
"""
Initialize the V1 version of IpMessaging
:param domain: The Twilio.ip_messaging domain
"""
super().__init__(domain, "v1")
self._credentials: Optional[CredentialList] = None
self._services: Optional[ServiceList] = None
@property
def credentials(self) -> CredentialList:
if self._credentials is None:
self._credentials = CredentialList(self)
return self._credentials
@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.IpMessaging.V1>"
@@ -0,0 +1,676 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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
class CredentialInstance(InstanceResource):
class PushService(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid:
:ivar account_sid:
:ivar friendly_name:
:ivar type:
:ivar sandbox:
:ivar date_created:
:ivar date_updated:
:ivar url:
"""
def __init__(
self, version: Version, payload: Dict[str, Any], sid: Optional[str] = None
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["CredentialInstance.PushService"] = payload.get("type")
self.sandbox: Optional[str] = payload.get("sandbox")
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._solution = {
"sid": sid or self.sid,
}
self._context: Optional[CredentialContext] = None
@property
def _proxy(self) -> "CredentialContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: CredentialContext for this CredentialInstance
"""
if self._context is None:
self._context = CredentialContext(
self._version,
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "CredentialInstance":
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "CredentialInstance":
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return await self._proxy.fetch_async()
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
return await self._proxy.update_async(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
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.IpMessaging.V1.CredentialInstance {}>".format(context)
class CredentialContext(InstanceContext):
def __init__(self, version: Version, sid: str):
"""
Initialize the CredentialContext
:param version: Version that contains the resource
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"sid": sid,
}
self._uri = "/Credentials/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the CredentialInstance
: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 CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> CredentialInstance:
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
async def fetch_async(self) -> CredentialInstance:
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, sid=self._solution["sid"])
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, sid=self._solution["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.IpMessaging.V1.CredentialContext {}>".format(context)
class CredentialPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> CredentialInstance:
"""
Build an instance of CredentialInstance
:param payload: Payload response from the API
"""
return CredentialInstance(self._version, payload)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.CredentialPage>"
class CredentialList(ListResource):
def __init__(self, version: Version):
"""
Initialize the CredentialList
:param version: Version that contains the resource
"""
super().__init__(version)
self._uri = "/Credentials"
def create(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Create the CredentialInstance
:param type:
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
async def create_async(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronously create the CredentialInstance
:param type:
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[CredentialInstance]:
"""
Streams CredentialInstance 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[CredentialInstance]:
"""
Asynchronously streams CredentialInstance 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[CredentialInstance]:
"""
Lists CredentialInstance 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[CredentialInstance]:
"""
Asynchronously lists CredentialInstance 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,
) -> CredentialPage:
"""
Retrieve a single page of CredentialInstance 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 CredentialInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return CredentialPage(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,
) -> CredentialPage:
"""
Asynchronously retrieve a single page of CredentialInstance 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 CredentialInstance
"""
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 CredentialPage(self._version, response)
def get_page(self, target_url: str) -> CredentialPage:
"""
Retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return CredentialPage(self._version, response)
async def get_page_async(self, target_url: str) -> CredentialPage:
"""
Asynchronously retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return CredentialPage(self._version, response)
def get(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid:
"""
return CredentialContext(self._version, sid=sid)
def __call__(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid:
"""
return CredentialContext(self._version, sid=sid)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.CredentialList>"
@@ -0,0 +1,755 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v1.service.channel.invite import InviteList
from twilio.rest.ip_messaging.v1.service.channel.member import MemberList
from twilio.rest.ip_messaging.v1.service.channel.message import MessageList
class ChannelInstance(InstanceResource):
class ChannelType(object):
PUBLIC = "public"
PRIVATE = "private"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar friendly_name:
:ivar unique_name:
:ivar attributes:
:ivar type:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
:ivar members_count:
:ivar messages_count:
:ivar url:
:ivar links:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.unique_name: Optional[str] = payload.get("unique_name")
self.attributes: Optional[str] = payload.get("attributes")
self.type: Optional["ChannelInstance.ChannelType"] = payload.get("type")
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.members_count: Optional[int] = deserialize.integer(
payload.get("members_count")
)
self.messages_count: Optional[int] = deserialize.integer(
payload.get("messages_count")
)
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[ChannelContext] = None
@property
def _proxy(self) -> "ChannelContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: ChannelContext for this ChannelInstance
"""
if self._context is None:
self._context = ChannelContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "ChannelInstance":
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "ChannelInstance":
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return await self._proxy.fetch_async()
def update(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Update the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:returns: The updated ChannelInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Asynchronous coroutine to update the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:returns: The updated ChannelInstance
"""
return await self._proxy.update_async(
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
return self._proxy.invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
return self._proxy.members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
return self._proxy.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.IpMessaging.V1.ChannelInstance {}>".format(context)
class ChannelContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the ChannelContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Channels/{sid}".format(**self._solution)
self._invites: Optional[InviteList] = None
self._members: Optional[MemberList] = None
self._messages: Optional[MessageList] = None
def delete(self) -> bool:
"""
Deletes the ChannelInstance
: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 ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> ChannelInstance:
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> ChannelInstance:
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Update the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronous coroutine to update the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
if self._invites is None:
self._invites = InviteList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
if self._members is None:
self._members = MemberList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
if self._messages is None:
self._messages = MessageList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._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.IpMessaging.V1.ChannelContext {}>".format(context)
class ChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> ChannelInstance:
"""
Build an instance of ChannelInstance
:param payload: Payload response from the API
"""
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.ChannelPage>"
class ChannelList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the ChannelList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Channels".format(**self._solution)
def create(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
) -> ChannelInstance:
"""
Create the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:param type:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
) -> ChannelInstance:
"""
Asynchronously create the ChannelInstance
:param friendly_name:
:param unique_name:
:param attributes:
:param type:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[ChannelInstance]:
"""
Streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(type=type, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[ChannelInstance]:
"""
Asynchronously streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(type=type, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(
type=type,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Asynchronously lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(
type=type,
limit=limit,
page_size=page_size,
)
]
def page(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type:
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return ChannelPage(self._version, response, self._solution)
async def page_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Asynchronously retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type:
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return ChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> ChannelPage:
"""
Retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return ChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> ChannelPage:
"""
Asynchronously retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return ChannelPage(self._version, response, self._solution)
def get(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid:
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid:
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.ChannelList>"
@@ -0,0 +1,573 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 InviteInstance(InstanceResource):
"""
:ivar sid:
:ivar account_sid:
:ivar channel_sid:
:ivar service_sid:
:ivar identity:
:ivar date_created:
:ivar date_updated:
:ivar role_sid:
:ivar created_by:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.created_by: Optional[str] = payload.get("created_by")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[InviteContext] = None
@property
def _proxy(self) -> "InviteContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: InviteContext for this InviteInstance
"""
if self._context is None:
self._context = InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "InviteInstance":
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "InviteInstance":
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
return await self._proxy.fetch_async()
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
return "<Twilio.IpMessaging.V1.InviteInstance {}>".format(context)
class InviteContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the InviteContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Invites/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the InviteInstance
: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 InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> InviteInstance:
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> InviteInstance:
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V1.InviteContext {}>".format(context)
class InvitePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> InviteInstance:
"""
Build an instance of InviteInstance
:param payload: Payload response from the API
"""
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.InvitePage>"
class InviteList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the InviteList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Invites".format(
**self._solution
)
def create(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Create the InviteInstance
:param identity:
:param role_sid:
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Asynchronously create the InviteInstance
:param identity:
:param role_sid:
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[InviteInstance]:
"""
Streams InviteInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[InviteInstance]:
"""
Asynchronously streams InviteInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Asynchronously lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity:
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return InvitePage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Asynchronously retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity:
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return InvitePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> InvitePage:
"""
Retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return InvitePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> InvitePage:
"""
Asynchronously retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return InvitePage(self._version, response, self._solution)
def get(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid:
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid:
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.InviteList>"
@@ -0,0 +1,683 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 MemberInstance(InstanceResource):
"""
:ivar sid:
:ivar account_sid:
:ivar channel_sid:
:ivar service_sid:
:ivar identity:
:ivar date_created:
:ivar date_updated:
:ivar role_sid:
:ivar last_consumed_message_index:
:ivar last_consumption_timestamp:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.last_consumption_timestamp: Optional[
datetime
] = deserialize.iso8601_datetime(payload.get("last_consumption_timestamp"))
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MemberContext] = None
@property
def _proxy(self) -> "MemberContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MemberContext for this MemberInstance
"""
if self._context is None:
self._context = MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "MemberInstance":
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MemberInstance":
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return await self._proxy.fetch_async()
def update(
self,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> "MemberInstance":
"""
Update the MemberInstance
:param role_sid:
:param last_consumed_message_index:
:returns: The updated MemberInstance
"""
return self._proxy.update(
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
)
async def update_async(
self,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> "MemberInstance":
"""
Asynchronous coroutine to update the MemberInstance
:param role_sid:
:param last_consumed_message_index:
:returns: The updated MemberInstance
"""
return await self._proxy.update_async(
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_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.IpMessaging.V1.MemberInstance {}>".format(context)
class MemberContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MemberContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Members/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the MemberInstance
: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 MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> MemberInstance:
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MemberInstance:
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> MemberInstance:
"""
Update the MemberInstance
:param role_sid:
:param last_consumed_message_index:
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> MemberInstance:
"""
Asynchronous coroutine to update the MemberInstance
:param role_sid:
:param last_consumed_message_index:
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V1.MemberContext {}>".format(context)
class MemberPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MemberInstance:
"""
Build an instance of MemberInstance
:param payload: Payload response from the API
"""
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.MemberPage>"
class MemberList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MemberList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Members".format(
**self._solution
)
def create(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> MemberInstance:
"""
Create the MemberInstance
:param identity:
:param role_sid:
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> MemberInstance:
"""
Asynchronously create the MemberInstance
:param identity:
:param role_sid:
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MemberInstance]:
"""
Streams MemberInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MemberInstance]:
"""
Asynchronously streams MemberInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Asynchronously lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity:
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MemberPage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Asynchronously retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity:
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MemberPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MemberPage:
"""
Retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MemberPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MemberPage:
"""
Asynchronously retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MemberPage(self._version, response, self._solution)
def get(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid:
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid:
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.MemberList>"
@@ -0,0 +1,696 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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
class MessageInstance(InstanceResource):
class OrderType(object):
ASC = "asc"
DESC = "desc"
"""
:ivar sid:
:ivar account_sid:
:ivar attributes:
:ivar service_sid:
:ivar to:
:ivar channel_sid:
:ivar date_created:
:ivar date_updated:
:ivar was_edited:
:ivar _from:
:ivar body:
:ivar index:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.attributes: Optional[str] = payload.get("attributes")
self.service_sid: Optional[str] = payload.get("service_sid")
self.to: Optional[str] = payload.get("to")
self.channel_sid: Optional[str] = payload.get("channel_sid")
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.was_edited: Optional[bool] = payload.get("was_edited")
self._from: Optional[str] = payload.get("from")
self.body: Optional[str] = payload.get("body")
self.index: Optional[int] = deserialize.integer(payload.get("index"))
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MessageContext] = None
@property
def _proxy(self) -> "MessageContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MessageContext for this MessageInstance
"""
if self._context is None:
self._context = MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "MessageInstance":
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MessageInstance":
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return await self._proxy.fetch_async()
def update(
self,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Update the MessageInstance
:param body:
:param attributes:
:returns: The updated MessageInstance
"""
return self._proxy.update(
body=body,
attributes=attributes,
)
async def update_async(
self,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Asynchronous coroutine to update the MessageInstance
:param body:
:param attributes:
:returns: The updated MessageInstance
"""
return await self._proxy.update_async(
body=body,
attributes=attributes,
)
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.IpMessaging.V1.MessageInstance {}>".format(context)
class MessageContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MessageContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Messages/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the MessageInstance
: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 MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> MessageInstance:
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MessageInstance:
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Update the MessageInstance
:param body:
:param attributes:
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronous coroutine to update the MessageInstance
:param body:
:param attributes:
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V1.MessageContext {}>".format(context)
class MessagePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MessageInstance:
"""
Build an instance of MessageInstance
:param payload: Payload response from the API
"""
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.MessagePage>"
class MessageList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MessageList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Messages".format(
**self._solution
)
def create(
self,
body: str,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Create the MessageInstance
:param body:
:param from_:
:param attributes:
:returns: The created MessageInstance
"""
data = values.of(
{
"Body": body,
"From": from_,
"Attributes": attributes,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
body: str,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronously create the MessageInstance
:param body:
:param from_:
:param attributes:
:returns: The created MessageInstance
"""
data = values.of(
{
"Body": body,
"From": from_,
"Attributes": attributes,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MessageInstance]:
"""
Streams MessageInstance 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;MessageInstance.OrderType&quot; order:
: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, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MessageInstance]:
"""
Asynchronously streams MessageInstance 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;MessageInstance.OrderType&quot; order:
: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, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order:
: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,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Asynchronously lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order:
: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,
limit=limit,
page_size=page_size,
)
]
def page(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order:
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MessagePage(self._version, response, self._solution)
async def page_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Asynchronously retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order:
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MessagePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MessagePage:
"""
Retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MessagePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MessagePage:
"""
Asynchronously retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MessagePage(self._version, response, self._solution)
def get(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid:
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid:
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.MessageList>"
@@ -0,0 +1,610 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 RoleInstance(InstanceResource):
class RoleType(object):
CHANNEL = "channel"
DEPLOYMENT = "deployment"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar friendly_name:
:ivar type:
:ivar permissions:
:ivar date_created:
:ivar date_updated:
:ivar url:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["RoleInstance.RoleType"] = payload.get("type")
self.permissions: Optional[List[str]] = payload.get("permissions")
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._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[RoleContext] = None
@property
def _proxy(self) -> "RoleContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: RoleContext for this RoleInstance
"""
if self._context is None:
self._context = RoleContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "RoleInstance":
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "RoleInstance":
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return await self._proxy.fetch_async()
def update(self, permission: List[str]) -> "RoleInstance":
"""
Update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
return self._proxy.update(
permission=permission,
)
async def update_async(self, permission: List[str]) -> "RoleInstance":
"""
Asynchronous coroutine to update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
return await self._proxy.update_async(
permission=permission,
)
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.IpMessaging.V1.RoleInstance {}>".format(context)
class RoleContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the RoleContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Roles/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the RoleInstance
: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 RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> RoleInstance:
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> RoleInstance:
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(self, permission: List[str]) -> RoleInstance:
"""
Update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(self, permission: List[str]) -> RoleInstance:
"""
Asynchronous coroutine to update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["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.IpMessaging.V1.RoleContext {}>".format(context)
class RolePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> RoleInstance:
"""
Build an instance of RoleInstance
:param payload: Payload response from the API
"""
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.RolePage>"
class RoleList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the RoleList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Roles".format(**self._solution)
def create(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Create the RoleInstance
:param friendly_name:
:param type:
:param permission:
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Asynchronously create the RoleInstance
:param friendly_name:
:param type:
:param permission:
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[RoleInstance]:
"""
Streams RoleInstance 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[RoleInstance]:
"""
Asynchronously streams RoleInstance 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[RoleInstance]:
"""
Lists RoleInstance 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[RoleInstance]:
"""
Asynchronously lists RoleInstance 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,
) -> RolePage:
"""
Retrieve a single page of RoleInstance 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 RoleInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return RolePage(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,
) -> RolePage:
"""
Asynchronously retrieve a single page of RoleInstance 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 RoleInstance
"""
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 RolePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> RolePage:
"""
Retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return RolePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> RolePage:
"""
Asynchronously retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return RolePage(self._version, response, self._solution)
def get(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid:
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid:
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.RoleList>"
@@ -0,0 +1,690 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v1.service.user.user_channel import UserChannelList
class UserInstance(InstanceResource):
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar attributes:
:ivar friendly_name:
:ivar role_sid:
:ivar identity:
:ivar is_online:
:ivar is_notifiable:
:ivar date_created:
:ivar date_updated:
:ivar joined_channels_count:
:ivar links:
:ivar url:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.attributes: Optional[str] = payload.get("attributes")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.role_sid: Optional[str] = payload.get("role_sid")
self.identity: Optional[str] = payload.get("identity")
self.is_online: Optional[bool] = payload.get("is_online")
self.is_notifiable: Optional[bool] = payload.get("is_notifiable")
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.joined_channels_count: Optional[int] = deserialize.integer(
payload.get("joined_channels_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[UserContext] = None
@property
def _proxy(self) -> "UserContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserContext for this UserInstance
"""
if self._context is None:
self._context = UserContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserInstance":
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserInstance":
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
return await self._proxy.fetch_async()
def update(
self,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Update the UserInstance
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
return self._proxy.update(
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
async def update_async(
self,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Asynchronous coroutine to update the UserInstance
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
return await self._proxy.update_async(
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
return self._proxy.user_channels
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.IpMessaging.V1.UserInstance {}>".format(context)
class UserContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the UserContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Users/{sid}".format(**self._solution)
self._user_channels: Optional[UserChannelList] = None
def delete(self) -> bool:
"""
Deletes the UserInstance
: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 UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserInstance:
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> UserInstance:
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Update the UserInstance
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronous coroutine to update the UserInstance
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
if self._user_channels is None:
self._user_channels = UserChannelList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._user_channels
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.IpMessaging.V1.UserContext {}>".format(context)
class UserPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserInstance:
"""
Build an instance of UserInstance
:param payload: Payload response from the API
"""
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.UserPage>"
class UserList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the UserList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Users".format(**self._solution)
def create(
self,
identity: str,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Create the UserInstance
:param identity:
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
identity: str,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronously create the UserInstance
:param identity:
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserInstance]:
"""
Streams UserInstance 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[UserInstance]:
"""
Asynchronously streams UserInstance 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[UserInstance]:
"""
Lists UserInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param 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[UserInstance]:
"""
Asynchronously lists UserInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param 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,
) -> UserPage:
"""
Retrieve a single page of UserInstance 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 UserInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserPage(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,
) -> UserPage:
"""
Asynchronously retrieve a single page of UserInstance 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 UserInstance
"""
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 UserPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserPage:
"""
Retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserPage:
"""
Asynchronously retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserPage(self._version, response, self._solution)
def get(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid:
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid:
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.UserList>"
@@ -0,0 +1,310 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 deserialize, values
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 UserChannelInstance(InstanceResource):
class ChannelStatus(object):
JOINED = "joined"
INVITED = "invited"
NOT_PARTICIPATING = "not_participating"
"""
:ivar account_sid:
:ivar service_sid:
:ivar channel_sid:
:ivar member_sid:
:ivar status:
:ivar last_consumed_message_index:
:ivar unread_messages_count:
:ivar links:
"""
def __init__(
self, version: Version, payload: Dict[str, Any], service_sid: str, user_sid: str
):
super().__init__(version)
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.member_sid: Optional[str] = payload.get("member_sid")
self.status: Optional["UserChannelInstance.ChannelStatus"] = payload.get(
"status"
)
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.unread_messages_count: Optional[int] = deserialize.integer(
payload.get("unread_messages_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self._solution = {
"service_sid": service_sid,
"user_sid": user_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.IpMessaging.V1.UserChannelInstance {}>".format(context)
class UserChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserChannelInstance:
"""
Build an instance of UserChannelInstance
:param payload: Payload response from the API
"""
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.UserChannelPage>"
class UserChannelList(ListResource):
def __init__(self, version: Version, service_sid: str, user_sid: str):
"""
Initialize the UserChannelList
:param version: Version that contains the resource
:param service_sid:
:param user_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Channels".format(
**self._solution
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserChannelInstance]:
"""
Streams UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously streams UserChannelInstance 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[UserChannelInstance]:
"""
Lists UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously lists UserChannelInstance 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,
) -> UserChannelPage:
"""
Retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserChannelPage(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,
) -> UserChannelPage:
"""
Asynchronously retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
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 UserChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserChannelPage:
"""
Retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserChannelPage:
"""
Asynchronously retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V1.UserChannelList>"
@@ -0,0 +1,50 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v2.credential import CredentialList
from twilio.rest.ip_messaging.v2.service import ServiceList
class V2(Version):
def __init__(self, domain: Domain):
"""
Initialize the V2 version of IpMessaging
:param domain: The Twilio.ip_messaging domain
"""
super().__init__(domain, "v2")
self._credentials: Optional[CredentialList] = None
self._services: Optional[ServiceList] = None
@property
def credentials(self) -> CredentialList:
if self._credentials is None:
self._credentials = CredentialList(self)
return self._credentials
@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.IpMessaging.V2>"
@@ -0,0 +1,676 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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
class CredentialInstance(InstanceResource):
class PushService(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid:
:ivar account_sid:
:ivar friendly_name:
:ivar type:
:ivar sandbox:
:ivar date_created:
:ivar date_updated:
:ivar url:
"""
def __init__(
self, version: Version, payload: Dict[str, Any], sid: Optional[str] = None
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["CredentialInstance.PushService"] = payload.get("type")
self.sandbox: Optional[str] = payload.get("sandbox")
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._solution = {
"sid": sid or self.sid,
}
self._context: Optional[CredentialContext] = None
@property
def _proxy(self) -> "CredentialContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: CredentialContext for this CredentialInstance
"""
if self._context is None:
self._context = CredentialContext(
self._version,
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "CredentialInstance":
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "CredentialInstance":
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return await self._proxy.fetch_async()
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
return await self._proxy.update_async(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
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.IpMessaging.V2.CredentialInstance {}>".format(context)
class CredentialContext(InstanceContext):
def __init__(self, version: Version, sid: str):
"""
Initialize the CredentialContext
:param version: Version that contains the resource
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"sid": sid,
}
self._uri = "/Credentials/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the CredentialInstance
: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 CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> CredentialInstance:
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
async def fetch_async(self) -> CredentialInstance:
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, sid=self._solution["sid"])
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, sid=self._solution["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.IpMessaging.V2.CredentialContext {}>".format(context)
class CredentialPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> CredentialInstance:
"""
Build an instance of CredentialInstance
:param payload: Payload response from the API
"""
return CredentialInstance(self._version, payload)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.CredentialPage>"
class CredentialList(ListResource):
def __init__(self, version: Version):
"""
Initialize the CredentialList
:param version: Version that contains the resource
"""
super().__init__(version)
self._uri = "/Credentials"
def create(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Create the CredentialInstance
:param type:
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
async def create_async(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronously create the CredentialInstance
:param type:
:param friendly_name:
:param certificate:
:param private_key:
:param sandbox:
:param api_key:
:param secret:
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[CredentialInstance]:
"""
Streams CredentialInstance 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[CredentialInstance]:
"""
Asynchronously streams CredentialInstance 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[CredentialInstance]:
"""
Lists CredentialInstance 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[CredentialInstance]:
"""
Asynchronously lists CredentialInstance 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,
) -> CredentialPage:
"""
Retrieve a single page of CredentialInstance 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 CredentialInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return CredentialPage(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,
) -> CredentialPage:
"""
Asynchronously retrieve a single page of CredentialInstance 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 CredentialInstance
"""
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 CredentialPage(self._version, response)
def get_page(self, target_url: str) -> CredentialPage:
"""
Retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return CredentialPage(self._version, response)
async def get_page_async(self, target_url: str) -> CredentialPage:
"""
Asynchronously retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return CredentialPage(self._version, response)
def get(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid:
"""
return CredentialContext(self._version, sid=sid)
def __call__(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid:
"""
return CredentialContext(self._version, sid=sid)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.CredentialList>"
@@ -0,0 +1,517 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 BindingInstance(InstanceResource):
class BindingType(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar date_created:
:ivar date_updated:
:ivar endpoint:
:ivar identity:
:ivar credential_sid:
:ivar binding_type:
:ivar message_types:
:ivar url:
:ivar links:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
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.endpoint: Optional[str] = payload.get("endpoint")
self.identity: Optional[str] = payload.get("identity")
self.credential_sid: Optional[str] = payload.get("credential_sid")
self.binding_type: Optional["BindingInstance.BindingType"] = payload.get(
"binding_type"
)
self.message_types: Optional[List[str]] = payload.get("message_types")
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[BindingContext] = None
@property
def _proxy(self) -> "BindingContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: BindingContext for this BindingInstance
"""
if self._context is None:
self._context = BindingContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "BindingInstance":
"""
Fetch the BindingInstance
:returns: The fetched BindingInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "BindingInstance":
"""
Asynchronous coroutine to fetch the BindingInstance
:returns: The fetched BindingInstance
"""
return await self._proxy.fetch_async()
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
return "<Twilio.IpMessaging.V2.BindingInstance {}>".format(context)
class BindingContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the BindingContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Bindings/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the BindingInstance
: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 BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> BindingInstance:
"""
Fetch the BindingInstance
:returns: The fetched BindingInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return BindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> BindingInstance:
"""
Asynchronous coroutine to fetch the BindingInstance
:returns: The fetched BindingInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return BindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["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.IpMessaging.V2.BindingContext {}>".format(context)
class BindingPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> BindingInstance:
"""
Build an instance of BindingInstance
:param payload: Payload response from the API
"""
return BindingInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.BindingPage>"
class BindingList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the BindingList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Bindings".format(**self._solution)
def stream(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[BindingInstance]:
"""
Streams BindingInstance 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 List[&quot;BindingInstance.BindingType&quot;] binding_type:
:param List[str] identity:
: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(
binding_type=binding_type, identity=identity, page_size=limits["page_size"]
)
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[BindingInstance]:
"""
Asynchronously streams BindingInstance 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 List[&quot;BindingInstance.BindingType&quot;] binding_type:
:param List[str] identity:
: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(
binding_type=binding_type, identity=identity, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[BindingInstance]:
"""
Lists BindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;BindingInstance.BindingType&quot;] binding_type:
:param List[str] identity:
: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(
binding_type=binding_type,
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[BindingInstance]:
"""
Asynchronously lists BindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;BindingInstance.BindingType&quot;] binding_type:
:param List[str] identity:
: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(
binding_type=binding_type,
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> BindingPage:
"""
Retrieve a single page of BindingInstance records from the API.
Request is executed immediately
:param binding_type:
:param identity:
: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 BindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return BindingPage(self._version, response, self._solution)
async def page_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> BindingPage:
"""
Asynchronously retrieve a single page of BindingInstance records from the API.
Request is executed immediately
:param binding_type:
:param identity:
: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 BindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return BindingPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> BindingPage:
"""
Retrieve a specific page of BindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of BindingInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return BindingPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> BindingPage:
"""
Asynchronously retrieve a specific page of BindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of BindingInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return BindingPage(self._version, response, self._solution)
def get(self, sid: str) -> BindingContext:
"""
Constructs a BindingContext
:param sid:
"""
return BindingContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> BindingContext:
"""
Constructs a BindingContext
:param sid:
"""
return BindingContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.BindingList>"
@@ -0,0 +1,907 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v2.service.channel.invite import InviteList
from twilio.rest.ip_messaging.v2.service.channel.member import MemberList
from twilio.rest.ip_messaging.v2.service.channel.message import MessageList
from twilio.rest.ip_messaging.v2.service.channel.webhook import WebhookList
class ChannelInstance(InstanceResource):
class ChannelType(object):
PUBLIC = "public"
PRIVATE = "private"
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar friendly_name:
:ivar unique_name:
:ivar attributes:
:ivar type:
:ivar date_created:
:ivar date_updated:
:ivar created_by:
:ivar members_count:
:ivar messages_count:
:ivar url:
:ivar links:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.unique_name: Optional[str] = payload.get("unique_name")
self.attributes: Optional[str] = payload.get("attributes")
self.type: Optional["ChannelInstance.ChannelType"] = payload.get("type")
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.members_count: Optional[int] = deserialize.integer(
payload.get("members_count")
)
self.messages_count: Optional[int] = deserialize.integer(
payload.get("messages_count")
)
self.url: Optional[str] = payload.get("url")
self.links: Optional[Dict[str, object]] = payload.get("links")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[ChannelContext] = None
@property
def _proxy(self) -> "ChannelContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: ChannelContext for this ChannelInstance
"""
if self._context is None:
self._context = ChannelContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "ChannelInstance":
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "ChannelInstance":
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param date_created:
:param date_updated:
:param created_by:
:returns: The updated ChannelInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
created_by=created_by,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Asynchronous coroutine to update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param date_created:
:param date_updated:
:param created_by:
:returns: The updated ChannelInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
created_by=created_by,
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
return self._proxy.invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
return self._proxy.members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
return self._proxy.messages
@property
def webhooks(self) -> WebhookList:
"""
Access the webhooks
"""
return self._proxy.webhooks
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.IpMessaging.V2.ChannelInstance {}>".format(context)
class ChannelContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the ChannelContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Channels/{sid}".format(**self._solution)
self._invites: Optional[InviteList] = None
self._members: Optional[MemberList] = None
self._messages: Optional[MessageList] = None
self._webhooks: Optional[WebhookList] = None
def delete(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> ChannelInstance:
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> ChannelInstance:
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param date_created:
:param date_updated:
:param created_by:
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronous coroutine to update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param date_created:
:param date_updated:
:param created_by:
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
if self._invites is None:
self._invites = InviteList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
if self._members is None:
self._members = MemberList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
if self._messages is None:
self._messages = MessageList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._messages
@property
def webhooks(self) -> WebhookList:
"""
Access the webhooks
"""
if self._webhooks is None:
self._webhooks = WebhookList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._webhooks
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.IpMessaging.V2.ChannelContext {}>".format(context)
class ChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> ChannelInstance:
"""
Build an instance of ChannelInstance
:param payload: Payload response from the API
"""
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.ChannelPage>"
class ChannelList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the ChannelList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Channels".format(**self._solution)
def create(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Create the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param type:
:param date_created:
:param date_updated:
:param created_by:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronously create the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name:
:param unique_name:
:param attributes:
:param type:
:param date_created:
:param date_updated:
:param created_by:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[ChannelInstance]:
"""
Streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(type=type, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[ChannelInstance]:
"""
Asynchronously streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(type=type, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(
type=type,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Asynchronously lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type:
: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(
type=type,
limit=limit,
page_size=page_size,
)
]
def page(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type:
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return ChannelPage(self._version, response, self._solution)
async def page_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Asynchronously retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type:
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return ChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> ChannelPage:
"""
Retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return ChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> ChannelPage:
"""
Asynchronously retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return ChannelPage(self._version, response, self._solution)
def get(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid:
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid:
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.ChannelList>"
@@ -0,0 +1,573 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 InviteInstance(InstanceResource):
"""
:ivar sid:
:ivar account_sid:
:ivar channel_sid:
:ivar service_sid:
:ivar identity:
:ivar date_created:
:ivar date_updated:
:ivar role_sid:
:ivar created_by:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.created_by: Optional[str] = payload.get("created_by")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[InviteContext] = None
@property
def _proxy(self) -> "InviteContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: InviteContext for this InviteInstance
"""
if self._context is None:
self._context = InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "InviteInstance":
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "InviteInstance":
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
return await self._proxy.fetch_async()
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
return "<Twilio.IpMessaging.V2.InviteInstance {}>".format(context)
class InviteContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the InviteContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Invites/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the InviteInstance
: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 InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> InviteInstance:
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> InviteInstance:
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V2.InviteContext {}>".format(context)
class InvitePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> InviteInstance:
"""
Build an instance of InviteInstance
:param payload: Payload response from the API
"""
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.InvitePage>"
class InviteList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the InviteList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Invites".format(
**self._solution
)
def create(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Create the InviteInstance
:param identity:
:param role_sid:
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Asynchronously create the InviteInstance
:param identity:
:param role_sid:
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[InviteInstance]:
"""
Streams InviteInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[InviteInstance]:
"""
Asynchronously streams InviteInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Asynchronously lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity:
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return InvitePage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Asynchronously retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity:
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return InvitePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> InvitePage:
"""
Retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return InvitePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> InvitePage:
"""
Asynchronously retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return InvitePage(self._version, response, self._solution)
def get(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid:
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid:
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.InviteList>"
@@ -0,0 +1,850 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 MemberInstance(InstanceResource):
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid:
:ivar account_sid:
:ivar channel_sid:
:ivar service_sid:
:ivar identity:
:ivar date_created:
:ivar date_updated:
:ivar role_sid:
:ivar last_consumed_message_index:
:ivar last_consumption_timestamp:
:ivar url:
:ivar attributes:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.last_consumption_timestamp: Optional[
datetime
] = deserialize.iso8601_datetime(payload.get("last_consumption_timestamp"))
self.url: Optional[str] = payload.get("url")
self.attributes: Optional[str] = payload.get("attributes")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MemberContext] = None
@property
def _proxy(self) -> "MemberContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MemberContext for this MemberInstance
"""
if self._context is None:
self._context = MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "MemberInstance":
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MemberInstance":
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MemberInstance":
"""
Update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The updated MemberInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
date_created=date_created,
date_updated=date_updated,
attributes=attributes,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MemberInstance":
"""
Asynchronous coroutine to update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The updated MemberInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
date_created=date_created,
date_updated=date_updated,
attributes=attributes,
)
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.IpMessaging.V2.MemberInstance {}>".format(context)
class MemberContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MemberContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Members/{sid}".format(
**self._solution
)
)
def delete(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> MemberInstance:
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MemberInstance:
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Asynchronous coroutine to update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V2.MemberContext {}>".format(context)
class MemberPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MemberInstance:
"""
Build an instance of MemberInstance
:param payload: Payload response from the API
"""
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.MemberPage>"
class MemberList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MemberList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Members".format(
**self._solution
)
def create(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Create the MemberInstance
:param identity:
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Asynchronously create the MemberInstance
:param identity:
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:param date_created:
:param date_updated:
:param attributes:
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MemberInstance]:
"""
Streams MemberInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MemberInstance]:
"""
Asynchronously streams MemberInstance 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 List[str] identity:
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Asynchronously lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity:
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity:
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MemberPage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Asynchronously retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity:
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MemberPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MemberPage:
"""
Retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MemberPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MemberPage:
"""
Asynchronously retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MemberPage(self._version, response, self._solution)
def get(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid:
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid:
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.MemberList>"
@@ -0,0 +1,850 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 MessageInstance(InstanceResource):
class OrderType(object):
ASC = "asc"
DESC = "desc"
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid:
:ivar account_sid:
:ivar attributes:
:ivar service_sid:
:ivar to:
:ivar channel_sid:
:ivar date_created:
:ivar date_updated:
:ivar last_updated_by:
:ivar was_edited:
:ivar _from:
:ivar body:
:ivar index:
:ivar type:
:ivar media:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.attributes: Optional[str] = payload.get("attributes")
self.service_sid: Optional[str] = payload.get("service_sid")
self.to: Optional[str] = payload.get("to")
self.channel_sid: Optional[str] = payload.get("channel_sid")
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.last_updated_by: Optional[str] = payload.get("last_updated_by")
self.was_edited: Optional[bool] = payload.get("was_edited")
self._from: Optional[str] = payload.get("from")
self.body: Optional[str] = payload.get("body")
self.index: Optional[int] = deserialize.integer(payload.get("index"))
self.type: Optional[str] = payload.get("type")
self.media: Optional[Dict[str, object]] = payload.get("media")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MessageContext] = None
@property
def _proxy(self) -> "MessageContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MessageContext for this MessageInstance
"""
if self._context is None:
self._context = MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "MessageInstance":
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MessageInstance":
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param from_:
:returns: The updated MessageInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
body=body,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
last_updated_by=last_updated_by,
from_=from_,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Asynchronous coroutine to update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param from_:
:returns: The updated MessageInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
body=body,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
last_updated_by=last_updated_by,
from_=from_,
)
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.IpMessaging.V2.MessageInstance {}>".format(context)
class MessageContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MessageContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Messages/{sid}".format(
**self._solution
)
)
def delete(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> MessageInstance:
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MessageInstance:
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param from_:
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"From": from_,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronous coroutine to update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param from_:
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"From": from_,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V2.MessageContext {}>".format(context)
class MessagePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MessageInstance:
"""
Build an instance of MessageInstance
:param payload: Payload response from the API
"""
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.MessagePage>"
class MessageList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MessageList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Messages".format(
**self._solution
)
def create(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
body: Union[str, object] = values.unset,
media_sid: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Create the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param from_:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param body:
:param media_sid:
:returns: The created MessageInstance
"""
data = values.of(
{
"From": from_,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"Body": body,
"MediaSid": media_sid,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
body: Union[str, object] = values.unset,
media_sid: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronously create the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param from_:
:param attributes:
:param date_created:
:param date_updated:
:param last_updated_by:
:param body:
:param media_sid:
:returns: The created MessageInstance
"""
data = values.of(
{
"From": from_,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"Body": body,
"MediaSid": media_sid,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MessageInstance]:
"""
Streams MessageInstance 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;MessageInstance.OrderType&quot; order:
: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, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MessageInstance]:
"""
Asynchronously streams MessageInstance 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;MessageInstance.OrderType&quot; order:
: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, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order:
: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,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Asynchronously lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order:
: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,
limit=limit,
page_size=page_size,
)
]
def page(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order:
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MessagePage(self._version, response, self._solution)
async def page_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Asynchronously retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order:
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MessagePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MessagePage:
"""
Retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MessagePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MessagePage:
"""
Asynchronously retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MessagePage(self._version, response, self._solution)
def get(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid:
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid:
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.MessageList>"
@@ -0,0 +1,765 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 WebhookInstance(InstanceResource):
class Method(object):
GET = "GET"
POST = "POST"
class Type(object):
WEBHOOK = "webhook"
TRIGGER = "trigger"
STUDIO = "studio"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar channel_sid:
:ivar type:
:ivar url:
:ivar configuration:
:ivar date_created:
:ivar date_updated:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.type: Optional[str] = payload.get("type")
self.url: Optional[str] = payload.get("url")
self.configuration: Optional[Dict[str, object]] = payload.get("configuration")
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._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[WebhookContext] = None
@property
def _proxy(self) -> "WebhookContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: WebhookContext for this WebhookInstance
"""
if self._context is None:
self._context = WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "WebhookInstance":
"""
Fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "WebhookInstance":
"""
Asynchronous coroutine to fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
return await self._proxy.fetch_async()
def update(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> "WebhookInstance":
"""
Update the WebhookInstance
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The updated WebhookInstance
"""
return self._proxy.update(
configuration_url=configuration_url,
configuration_method=configuration_method,
configuration_filters=configuration_filters,
configuration_triggers=configuration_triggers,
configuration_flow_sid=configuration_flow_sid,
configuration_retry_count=configuration_retry_count,
)
async def update_async(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> "WebhookInstance":
"""
Asynchronous coroutine to update the WebhookInstance
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The updated WebhookInstance
"""
return await self._proxy.update_async(
configuration_url=configuration_url,
configuration_method=configuration_method,
configuration_filters=configuration_filters,
configuration_triggers=configuration_triggers,
configuration_flow_sid=configuration_flow_sid,
configuration_retry_count=configuration_retry_count,
)
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.IpMessaging.V2.WebhookInstance {}>".format(context)
class WebhookContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the WebhookContext
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Webhooks/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the WebhookInstance
: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 WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> WebhookInstance:
"""
Fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> WebhookInstance:
"""
Asynchronous coroutine to fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Update the WebhookInstance
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The updated WebhookInstance
"""
data = values.of(
{
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Asynchronous coroutine to update the WebhookInstance
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The updated WebhookInstance
"""
data = values.of(
{
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["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.IpMessaging.V2.WebhookContext {}>".format(context)
class WebhookPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> WebhookInstance:
"""
Build an instance of WebhookInstance
:param payload: Payload response from the API
"""
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.WebhookPage>"
class WebhookList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the WebhookList
:param version: Version that contains the resource
:param service_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Webhooks".format(
**self._solution
)
def create(
self,
type: "WebhookInstance.Type",
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Create the WebhookInstance
:param type:
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The created WebhookInstance
"""
data = values.of(
{
"Type": type,
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
type: "WebhookInstance.Type",
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Asynchronously create the WebhookInstance
:param type:
:param configuration_url:
:param configuration_method:
:param configuration_filters:
:param configuration_triggers:
:param configuration_flow_sid:
:param configuration_retry_count:
:returns: The created WebhookInstance
"""
data = values.of(
{
"Type": type,
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[WebhookInstance]:
"""
Streams WebhookInstance 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[WebhookInstance]:
"""
Asynchronously streams WebhookInstance 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[WebhookInstance]:
"""
Lists WebhookInstance 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[WebhookInstance]:
"""
Asynchronously lists WebhookInstance 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,
) -> WebhookPage:
"""
Retrieve a single page of WebhookInstance 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 WebhookInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return WebhookPage(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,
) -> WebhookPage:
"""
Asynchronously retrieve a single page of WebhookInstance 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 WebhookInstance
"""
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 WebhookPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> WebhookPage:
"""
Retrieve a specific page of WebhookInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of WebhookInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return WebhookPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> WebhookPage:
"""
Asynchronously retrieve a specific page of WebhookInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of WebhookInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return WebhookPage(self._version, response, self._solution)
def get(self, sid: str) -> WebhookContext:
"""
Constructs a WebhookContext
:param sid:
"""
return WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> WebhookContext:
"""
Constructs a WebhookContext
:param sid:
"""
return WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.WebhookList>"
@@ -0,0 +1,610 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 RoleInstance(InstanceResource):
class RoleType(object):
CHANNEL = "channel"
DEPLOYMENT = "deployment"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar friendly_name:
:ivar type:
:ivar permissions:
:ivar date_created:
:ivar date_updated:
:ivar url:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["RoleInstance.RoleType"] = payload.get("type")
self.permissions: Optional[List[str]] = payload.get("permissions")
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._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[RoleContext] = None
@property
def _proxy(self) -> "RoleContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: RoleContext for this RoleInstance
"""
if self._context is None:
self._context = RoleContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "RoleInstance":
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "RoleInstance":
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return await self._proxy.fetch_async()
def update(self, permission: List[str]) -> "RoleInstance":
"""
Update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
return self._proxy.update(
permission=permission,
)
async def update_async(self, permission: List[str]) -> "RoleInstance":
"""
Asynchronous coroutine to update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
return await self._proxy.update_async(
permission=permission,
)
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.IpMessaging.V2.RoleInstance {}>".format(context)
class RoleContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the RoleContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Roles/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the RoleInstance
: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 RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> RoleInstance:
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> RoleInstance:
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(self, permission: List[str]) -> RoleInstance:
"""
Update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(self, permission: List[str]) -> RoleInstance:
"""
Asynchronous coroutine to update the RoleInstance
:param permission:
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["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.IpMessaging.V2.RoleContext {}>".format(context)
class RolePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> RoleInstance:
"""
Build an instance of RoleInstance
:param payload: Payload response from the API
"""
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.RolePage>"
class RoleList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the RoleList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Roles".format(**self._solution)
def create(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Create the RoleInstance
:param friendly_name:
:param type:
:param permission:
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Asynchronously create the RoleInstance
:param friendly_name:
:param type:
:param permission:
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[RoleInstance]:
"""
Streams RoleInstance 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[RoleInstance]:
"""
Asynchronously streams RoleInstance 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[RoleInstance]:
"""
Lists RoleInstance 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[RoleInstance]:
"""
Asynchronously lists RoleInstance 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,
) -> RolePage:
"""
Retrieve a single page of RoleInstance 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 RoleInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return RolePage(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,
) -> RolePage:
"""
Asynchronously retrieve a single page of RoleInstance 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 RoleInstance
"""
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 RolePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> RolePage:
"""
Retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return RolePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> RolePage:
"""
Asynchronously retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return RolePage(self._version, response, self._solution)
def get(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid:
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid:
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.RoleList>"
@@ -0,0 +1,751 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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.ip_messaging.v2.service.user.user_binding import UserBindingList
from twilio.rest.ip_messaging.v2.service.user.user_channel import UserChannelList
class UserInstance(InstanceResource):
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar attributes:
:ivar friendly_name:
:ivar role_sid:
:ivar identity:
:ivar is_online:
:ivar is_notifiable:
:ivar date_created:
:ivar date_updated:
:ivar joined_channels_count:
:ivar links:
:ivar url:
"""
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.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.attributes: Optional[str] = payload.get("attributes")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.role_sid: Optional[str] = payload.get("role_sid")
self.identity: Optional[str] = payload.get("identity")
self.is_online: Optional[bool] = payload.get("is_online")
self.is_notifiable: Optional[bool] = payload.get("is_notifiable")
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.joined_channels_count: Optional[int] = deserialize.integer(
payload.get("joined_channels_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[UserContext] = None
@property
def _proxy(self) -> "UserContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserContext for this UserInstance
"""
if self._context is None:
self._context = UserContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserInstance":
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserInstance":
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Asynchronous coroutine to update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
@property
def user_bindings(self) -> UserBindingList:
"""
Access the user_bindings
"""
return self._proxy.user_bindings
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
return self._proxy.user_channels
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.IpMessaging.V2.UserInstance {}>".format(context)
class UserContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the UserContext
:param version: Version that contains the resource
:param service_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Users/{sid}".format(**self._solution)
self._user_bindings: Optional[UserBindingList] = None
self._user_channels: Optional[UserChannelList] = None
def delete(self) -> bool:
"""
Deletes the UserInstance
: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 UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserInstance:
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> UserInstance:
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronous coroutine to update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def user_bindings(self) -> UserBindingList:
"""
Access the user_bindings
"""
if self._user_bindings is None:
self._user_bindings = UserBindingList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._user_bindings
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
if self._user_channels is None:
self._user_channels = UserChannelList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._user_channels
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.IpMessaging.V2.UserContext {}>".format(context)
class UserPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserInstance:
"""
Build an instance of UserInstance
:param payload: Payload response from the API
"""
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserPage>"
class UserList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the UserList
:param version: Version that contains the resource
:param service_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Users".format(**self._solution)
def create(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Create the UserInstance
:param identity:
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronously create the UserInstance
:param identity:
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid:
:param attributes:
:param friendly_name:
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserInstance]:
"""
Streams UserInstance 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[UserInstance]:
"""
Asynchronously streams UserInstance 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[UserInstance]:
"""
Lists UserInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param 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[UserInstance]:
"""
Asynchronously lists UserInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param 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,
) -> UserPage:
"""
Retrieve a single page of UserInstance 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 UserInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserPage(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,
) -> UserPage:
"""
Asynchronously retrieve a single page of UserInstance 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 UserInstance
"""
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 UserPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserPage:
"""
Retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserPage:
"""
Asynchronously retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserPage(self._version, response, self._solution)
def get(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid:
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid:
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserList>"
@@ -0,0 +1,533 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 UserBindingInstance(InstanceResource):
class BindingType(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid:
:ivar account_sid:
:ivar service_sid:
:ivar date_created:
:ivar date_updated:
:ivar endpoint:
:ivar identity:
:ivar user_sid:
:ivar credential_sid:
:ivar binding_type:
:ivar message_types:
:ivar url:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
user_sid: str,
sid: Optional[str] = None,
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
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.endpoint: Optional[str] = payload.get("endpoint")
self.identity: Optional[str] = payload.get("identity")
self.user_sid: Optional[str] = payload.get("user_sid")
self.credential_sid: Optional[str] = payload.get("credential_sid")
self.binding_type: Optional["UserBindingInstance.BindingType"] = payload.get(
"binding_type"
)
self.message_types: Optional[List[str]] = payload.get("message_types")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"sid": sid or self.sid,
}
self._context: Optional[UserBindingContext] = None
@property
def _proxy(self) -> "UserBindingContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserBindingContext for this UserBindingInstance
"""
if self._context is None:
self._context = UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserBindingInstance":
"""
Fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserBindingInstance":
"""
Asynchronous coroutine to fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
return await self._proxy.fetch_async()
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
return "<Twilio.IpMessaging.V2.UserBindingInstance {}>".format(context)
class UserBindingContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, user_sid: str, sid: str):
"""
Initialize the UserBindingContext
:param version: Version that contains the resource
:param service_sid:
:param user_sid:
:param sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Bindings/{sid}".format(
**self._solution
)
def delete(self) -> bool:
"""
Deletes the UserBindingInstance
: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 UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserBindingInstance:
"""
Fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> UserBindingInstance:
"""
Asynchronous coroutine to fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=self._solution["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.IpMessaging.V2.UserBindingContext {}>".format(context)
class UserBindingPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserBindingInstance:
"""
Build an instance of UserBindingInstance
:param payload: Payload response from the API
"""
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserBindingPage>"
class UserBindingList(ListResource):
def __init__(self, version: Version, service_sid: str, user_sid: str):
"""
Initialize the UserBindingList
:param version: Version that contains the resource
:param service_sid:
:param user_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Bindings".format(
**self._solution
)
def stream(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserBindingInstance]:
"""
Streams UserBindingInstance 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 List[&quot;UserBindingInstance.BindingType&quot;] binding_type:
: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(binding_type=binding_type, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[UserBindingInstance]:
"""
Asynchronously streams UserBindingInstance 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 List[&quot;UserBindingInstance.BindingType&quot;] binding_type:
: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(
binding_type=binding_type, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[UserBindingInstance]:
"""
Lists UserBindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;UserBindingInstance.BindingType&quot;] binding_type:
: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(
binding_type=binding_type,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[UserBindingInstance]:
"""
Asynchronously lists UserBindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;UserBindingInstance.BindingType&quot;] binding_type:
: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(
binding_type=binding_type,
limit=limit,
page_size=page_size,
)
]
def page(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> UserBindingPage:
"""
Retrieve a single page of UserBindingInstance records from the API.
Request is executed immediately
:param binding_type:
: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 UserBindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserBindingPage(self._version, response, self._solution)
async def page_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> UserBindingPage:
"""
Asynchronously retrieve a single page of UserBindingInstance records from the API.
Request is executed immediately
:param binding_type:
: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 UserBindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return UserBindingPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserBindingPage:
"""
Retrieve a specific page of UserBindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserBindingInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserBindingPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserBindingPage:
"""
Asynchronously retrieve a specific page of UserBindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserBindingInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserBindingPage(self._version, response, self._solution)
def get(self, sid: str) -> UserBindingContext:
"""
Constructs a UserBindingContext
:param sid:
"""
return UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=sid,
)
def __call__(self, sid: str) -> UserBindingContext:
"""
Constructs a UserBindingContext
:param sid:
"""
return UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserBindingList>"
@@ -0,0 +1,639 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Ip_messaging
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 UserChannelInstance(InstanceResource):
class ChannelStatus(object):
JOINED = "joined"
INVITED = "invited"
NOT_PARTICIPATING = "not_participating"
class NotificationLevel(object):
DEFAULT = "default"
MUTED = "muted"
"""
:ivar account_sid:
:ivar service_sid:
:ivar channel_sid:
:ivar user_sid:
:ivar member_sid:
:ivar status:
:ivar last_consumed_message_index:
:ivar unread_messages_count:
:ivar links:
:ivar url:
:ivar notification_level:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
user_sid: str,
channel_sid: 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.channel_sid: Optional[str] = payload.get("channel_sid")
self.user_sid: Optional[str] = payload.get("user_sid")
self.member_sid: Optional[str] = payload.get("member_sid")
self.status: Optional["UserChannelInstance.ChannelStatus"] = payload.get(
"status"
)
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.unread_messages_count: Optional[int] = deserialize.integer(
payload.get("unread_messages_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self.url: Optional[str] = payload.get("url")
self.notification_level: Optional[
"UserChannelInstance.NotificationLevel"
] = payload.get("notification_level")
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"channel_sid": channel_sid or self.channel_sid,
}
self._context: Optional[UserChannelContext] = None
@property
def _proxy(self) -> "UserChannelContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserChannelContext for this UserChannelInstance
"""
if self._context is None:
self._context = UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserChannelInstance":
"""
Fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserChannelInstance":
"""
Asynchronous coroutine to fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
return await self._proxy.fetch_async()
def update(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> "UserChannelInstance":
"""
Update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:returns: The updated UserChannelInstance
"""
return self._proxy.update(
notification_level=notification_level,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
)
async def update_async(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> "UserChannelInstance":
"""
Asynchronous coroutine to update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:returns: The updated UserChannelInstance
"""
return await self._proxy.update_async(
notification_level=notification_level,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
)
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.IpMessaging.V2.UserChannelInstance {}>".format(context)
class UserChannelContext(InstanceContext):
def __init__(
self, version: Version, service_sid: str, user_sid: str, channel_sid: str
):
"""
Initialize the UserChannelContext
:param version: Version that contains the resource
:param service_sid:
:param user_sid:
:param channel_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"channel_sid": channel_sid,
}
self._uri = (
"/Services/{service_sid}/Users/{user_sid}/Channels/{channel_sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the UserChannelInstance
: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 UserChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserChannelInstance:
"""
Fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
async def fetch_async(self) -> UserChannelInstance:
"""
Asynchronous coroutine to fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
def update(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> UserChannelInstance:
"""
Update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:returns: The updated UserChannelInstance
"""
data = values.of(
{
"NotificationLevel": notification_level,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
async def update_async(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> UserChannelInstance:
"""
Asynchronous coroutine to update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index:
:param last_consumption_timestamp:
:returns: The updated UserChannelInstance
"""
data = values.of(
{
"NotificationLevel": notification_level,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_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.IpMessaging.V2.UserChannelContext {}>".format(context)
class UserChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserChannelInstance:
"""
Build an instance of UserChannelInstance
:param payload: Payload response from the API
"""
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserChannelPage>"
class UserChannelList(ListResource):
def __init__(self, version: Version, service_sid: str, user_sid: str):
"""
Initialize the UserChannelList
:param version: Version that contains the resource
:param service_sid:
:param user_sid:
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Channels".format(
**self._solution
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserChannelInstance]:
"""
Streams UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously streams UserChannelInstance 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[UserChannelInstance]:
"""
Lists UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously lists UserChannelInstance 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,
) -> UserChannelPage:
"""
Retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserChannelPage(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,
) -> UserChannelPage:
"""
Asynchronously retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
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 UserChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserChannelPage:
"""
Retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserChannelPage:
"""
Asynchronously retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
def get(self, channel_sid: str) -> UserChannelContext:
"""
Constructs a UserChannelContext
:param channel_sid:
"""
return UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=channel_sid,
)
def __call__(self, channel_sid: str) -> UserChannelContext:
"""
Constructs a UserChannelContext
:param channel_sid:
"""
return UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=channel_sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.IpMessaging.V2.UserChannelList>"