|
| 1 | +r""" |
| 2 | + This code was generated by |
| 3 | + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ |
| 4 | + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ |
| 5 | + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ |
| 6 | +
|
| 7 | + Twilio - Accounts |
| 8 | + This is the public Twilio REST API. |
| 9 | +
|
| 10 | + NOTE: This class is auto generated by OpenAPI Generator. |
| 11 | + https://openapi-generator.tech |
| 12 | + Do not edit the class manually. |
| 13 | +""" |
| 14 | + |
| 15 | +from typing import Any, Dict, List, Optional |
| 16 | +from twilio.base import serialize, values |
| 17 | + |
| 18 | +from twilio.base.instance_resource import InstanceResource |
| 19 | +from twilio.base.list_resource import ListResource |
| 20 | +from twilio.base.version import Version |
| 21 | + |
| 22 | + |
| 23 | +class BulkConsentsInstance(InstanceResource): |
| 24 | + """ |
| 25 | + :ivar items: A list of objects where each object represents the result of processing a `correlation_id`. Each object contains the following fields: `correlation_id`, a unique 32-character UUID that maps the response to the original request; `error_code`, an integer where 0 indicates success and any non-zero value represents an error; and `error_messages`, an array of strings describing specific validation errors encountered. If the request is successful, the error_messages array will be empty. |
| 26 | + """ |
| 27 | + |
| 28 | + def __init__(self, version: Version, payload: Dict[str, Any]): |
| 29 | + super().__init__(version) |
| 30 | + |
| 31 | + self.items: Optional[Dict[str, object]] = payload.get("items") |
| 32 | + |
| 33 | + def __repr__(self) -> str: |
| 34 | + """ |
| 35 | + Provide a friendly representation |
| 36 | +
|
| 37 | + :returns: Machine friendly representation |
| 38 | + """ |
| 39 | + |
| 40 | + return "<Twilio.Accounts.V1.BulkConsentsInstance>" |
| 41 | + |
| 42 | + |
| 43 | +class BulkConsentsList(ListResource): |
| 44 | + |
| 45 | + def __init__(self, version: Version): |
| 46 | + """ |
| 47 | + Initialize the BulkConsentsList |
| 48 | +
|
| 49 | + :param version: Version that contains the resource |
| 50 | +
|
| 51 | + """ |
| 52 | + super().__init__(version) |
| 53 | + |
| 54 | + self._uri = "/Consents/Bulk" |
| 55 | + |
| 56 | + def create(self, items: List[object]) -> BulkConsentsInstance: |
| 57 | + """ |
| 58 | + Create the BulkConsentsInstance |
| 59 | +
|
| 60 | + :param items: This is a list of objects that describes a contact's opt-in status. Each object contains the following fields: `contact_id`, which must be a string representing phone number in [E.164 format](https://www.twilio.com/docs/glossary/what-e164); `correlation_id`, a unique 32-character UUID used to uniquely map the request item with the response item; `sender_id`, which can be either a valid messaging service SID or a from phone number; `status`, a string representing the consent status. Can be one of [`opt-in`, `opt-out`]; and `source`, a string indicating the medium through which the consent was collected. Can be one of [`website`, `offline`, `opt-in-message`, `opt-out-message`, `others`]. |
| 61 | +
|
| 62 | + :returns: The created BulkConsentsInstance |
| 63 | + """ |
| 64 | + |
| 65 | + data = values.of( |
| 66 | + { |
| 67 | + "Items": serialize.map(items, lambda e: serialize.object(e)), |
| 68 | + } |
| 69 | + ) |
| 70 | + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) |
| 71 | + |
| 72 | + payload = self._version.create( |
| 73 | + method="POST", uri=self._uri, data=data, headers=headers |
| 74 | + ) |
| 75 | + |
| 76 | + return BulkConsentsInstance(self._version, payload) |
| 77 | + |
| 78 | + async def create_async(self, items: List[object]) -> BulkConsentsInstance: |
| 79 | + """ |
| 80 | + Asynchronously create the BulkConsentsInstance |
| 81 | +
|
| 82 | + :param items: This is a list of objects that describes a contact's opt-in status. Each object contains the following fields: `contact_id`, which must be a string representing phone number in [E.164 format](https://www.twilio.com/docs/glossary/what-e164); `correlation_id`, a unique 32-character UUID used to uniquely map the request item with the response item; `sender_id`, which can be either a valid messaging service SID or a from phone number; `status`, a string representing the consent status. Can be one of [`opt-in`, `opt-out`]; and `source`, a string indicating the medium through which the consent was collected. Can be one of [`website`, `offline`, `opt-in-message`, `opt-out-message`, `others`]. |
| 83 | +
|
| 84 | + :returns: The created BulkConsentsInstance |
| 85 | + """ |
| 86 | + |
| 87 | + data = values.of( |
| 88 | + { |
| 89 | + "Items": serialize.map(items, lambda e: serialize.object(e)), |
| 90 | + } |
| 91 | + ) |
| 92 | + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) |
| 93 | + |
| 94 | + payload = await self._version.create_async( |
| 95 | + method="POST", uri=self._uri, data=data, headers=headers |
| 96 | + ) |
| 97 | + |
| 98 | + return BulkConsentsInstance(self._version, payload) |
| 99 | + |
| 100 | + def __repr__(self) -> str: |
| 101 | + """ |
| 102 | + Provide a friendly representation |
| 103 | +
|
| 104 | + :returns: Machine friendly representation |
| 105 | + """ |
| 106 | + return "<Twilio.Accounts.V1.BulkConsentsList>" |
0 commit comments