twilio_rust_openapi/apis/
api20100401_domain_api.rs

1/*
2 * Twilio - Api
3 *
4 * This is the public Twilio REST API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: support@twilio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`create_sip_domain`]
18#[derive(Clone, Debug)]
19pub struct CreateSipDomainParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
21    pub account_sid: String,
22    /// The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and \\\"-\\\" and must end with `sip.twilio.com`.
23    pub domain_name: String,
24    /// A descriptive string that you created to describe the resource. It can be up to 64 characters long.
25    pub friendly_name: Option<String>,
26    /// The URL we should when the domain receives a call.
27    pub voice_url: Option<String>,
28    /// The HTTP method we should use to call `voice_url`. Can be: `GET` or `POST`.
29    pub voice_method: Option<String>,
30    /// The URL that we should call when an error occurs while retrieving or executing the TwiML from `voice_url`.
31    pub voice_fallback_url: Option<String>,
32    /// The HTTP method we should use to call `voice_fallback_url`. Can be: `GET` or `POST`.
33    pub voice_fallback_method: Option<String>,
34    /// The URL that we should call to pass status parameters (such as call ended) to your application.
35    pub voice_status_callback_url: Option<String>,
36    /// The HTTP method we should use to call `voice_status_callback_url`. Can be: `GET` or `POST`.
37    pub voice_status_callback_method: Option<String>,
38    /// Whether to allow SIP Endpoints to register with the domain to receive calls. Can be `true` or `false`. `true` allows SIP Endpoints to register with the domain to receive calls, `false` does not.
39    pub sip_registration: Option<bool>,
40    /// Whether emergency calling is enabled for the domain. If enabled, allows emergency calls on the domain from phone numbers with validated addresses.
41    pub emergency_calling_enabled: Option<bool>,
42    /// Whether secure SIP is enabled for the domain. If enabled, TLS will be enforced and SRTP will be negotiated on all incoming calls to this sip domain.
43    pub secure: Option<bool>,
44    /// The SID of the BYOC Trunk(Bring Your Own Carrier) resource that the Sip Domain will be associated with.
45    pub byoc_trunk_sid: Option<String>,
46    /// Whether an emergency caller sid is configured for the domain. If present, this phone number will be used as the callback for the emergency call.
47    pub emergency_caller_sid: Option<String>
48}
49
50/// struct for passing parameters to the method [`delete_sip_domain`]
51#[derive(Clone, Debug)]
52pub struct DeleteSipDomainParams {
53    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the SipDomain resources to delete.
54    pub account_sid: String,
55    /// The Twilio-provided string that uniquely identifies the SipDomain resource to delete.
56    pub sid: String
57}
58
59/// struct for passing parameters to the method [`fetch_sip_domain`]
60#[derive(Clone, Debug)]
61pub struct FetchSipDomainParams {
62    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the SipDomain resource to fetch.
63    pub account_sid: String,
64    /// The Twilio-provided string that uniquely identifies the SipDomain resource to fetch.
65    pub sid: String
66}
67
68/// struct for passing parameters to the method [`list_sip_domain`]
69#[derive(Clone, Debug)]
70pub struct ListSipDomainParams {
71    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the SipDomain resources to read.
72    pub account_sid: String,
73    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
74    pub page_size: Option<i32>,
75    /// The page index. This value is simply for client state.
76    pub page: Option<i32>,
77    /// The page token. This is provided by the API.
78    pub page_token: Option<String>
79}
80
81/// struct for passing parameters to the method [`update_sip_domain`]
82#[derive(Clone, Debug)]
83pub struct UpdateSipDomainParams {
84    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the SipDomain resource to update.
85    pub account_sid: String,
86    /// The Twilio-provided string that uniquely identifies the SipDomain resource to update.
87    pub sid: String,
88    /// A descriptive string that you created to describe the resource. It can be up to 64 characters long.
89    pub friendly_name: Option<String>,
90    /// The HTTP method we should use to call `voice_fallback_url`. Can be: `GET` or `POST`.
91    pub voice_fallback_method: Option<String>,
92    /// The URL that we should call when an error occurs while retrieving or executing the TwiML requested by `voice_url`.
93    pub voice_fallback_url: Option<String>,
94    /// The HTTP method we should use to call `voice_url`
95    pub voice_method: Option<String>,
96    /// The HTTP method we should use to call `voice_status_callback_url`. Can be: `GET` or `POST`.
97    pub voice_status_callback_method: Option<String>,
98    /// The URL that we should call to pass status parameters (such as call ended) to your application.
99    pub voice_status_callback_url: Option<String>,
100    /// The URL we should call when the domain receives a call.
101    pub voice_url: Option<String>,
102    /// Whether to allow SIP Endpoints to register with the domain to receive calls. Can be `true` or `false`. `true` allows SIP Endpoints to register with the domain to receive calls, `false` does not.
103    pub sip_registration: Option<bool>,
104    /// The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and \\\"-\\\" and must end with `sip.twilio.com`.
105    pub domain_name: Option<String>,
106    /// Whether emergency calling is enabled for the domain. If enabled, allows emergency calls on the domain from phone numbers with validated addresses.
107    pub emergency_calling_enabled: Option<bool>,
108    /// Whether secure SIP is enabled for the domain. If enabled, TLS will be enforced and SRTP will be negotiated on all incoming calls to this sip domain.
109    pub secure: Option<bool>,
110    /// The SID of the BYOC Trunk(Bring Your Own Carrier) resource that the Sip Domain will be associated with.
111    pub byoc_trunk_sid: Option<String>,
112    /// Whether an emergency caller sid is configured for the domain. If present, this phone number will be used as the callback for the emergency call.
113    pub emergency_caller_sid: Option<String>
114}
115
116
117/// struct for typed errors of method [`create_sip_domain`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum CreateSipDomainError {
121    UnknownValue(serde_json::Value),
122}
123
124/// struct for typed errors of method [`delete_sip_domain`]
125#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum DeleteSipDomainError {
128    UnknownValue(serde_json::Value),
129}
130
131/// struct for typed errors of method [`fetch_sip_domain`]
132#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum FetchSipDomainError {
135    UnknownValue(serde_json::Value),
136}
137
138/// struct for typed errors of method [`list_sip_domain`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum ListSipDomainError {
142    UnknownValue(serde_json::Value),
143}
144
145/// struct for typed errors of method [`update_sip_domain`]
146#[derive(Debug, Clone, Serialize, Deserialize)]
147#[serde(untagged)]
148pub enum UpdateSipDomainError {
149    UnknownValue(serde_json::Value),
150}
151
152
153/// Create a new Domain
154pub async fn create_sip_domain(configuration: &configuration::Configuration, params: CreateSipDomainParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipDomain, Error<CreateSipDomainError>> {
155    let local_var_configuration = configuration;
156
157    // unbox the parameters
158    let account_sid = params.account_sid;
159    let domain_name = params.domain_name;
160    let friendly_name = params.friendly_name;
161    let voice_url = params.voice_url;
162    let voice_method = params.voice_method;
163    let voice_fallback_url = params.voice_fallback_url;
164    let voice_fallback_method = params.voice_fallback_method;
165    let voice_status_callback_url = params.voice_status_callback_url;
166    let voice_status_callback_method = params.voice_status_callback_method;
167    let sip_registration = params.sip_registration;
168    let emergency_calling_enabled = params.emergency_calling_enabled;
169    let secure = params.secure;
170    let byoc_trunk_sid = params.byoc_trunk_sid;
171    let emergency_caller_sid = params.emergency_caller_sid;
172
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
177    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
178
179    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181    }
182    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
183        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
184    };
185    let mut local_var_form_params = std::collections::HashMap::new();
186    local_var_form_params.insert("DomainName", domain_name.to_string());
187    if let Some(local_var_param_value) = friendly_name {
188        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
189    }
190    if let Some(local_var_param_value) = voice_url {
191        local_var_form_params.insert("VoiceUrl", local_var_param_value.to_string());
192    }
193    if let Some(local_var_param_value) = voice_method {
194        local_var_form_params.insert("VoiceMethod", local_var_param_value.to_string());
195    }
196    if let Some(local_var_param_value) = voice_fallback_url {
197        local_var_form_params.insert("VoiceFallbackUrl", local_var_param_value.to_string());
198    }
199    if let Some(local_var_param_value) = voice_fallback_method {
200        local_var_form_params.insert("VoiceFallbackMethod", local_var_param_value.to_string());
201    }
202    if let Some(local_var_param_value) = voice_status_callback_url {
203        local_var_form_params.insert("VoiceStatusCallbackUrl", local_var_param_value.to_string());
204    }
205    if let Some(local_var_param_value) = voice_status_callback_method {
206        local_var_form_params.insert("VoiceStatusCallbackMethod", local_var_param_value.to_string());
207    }
208    if let Some(local_var_param_value) = sip_registration {
209        local_var_form_params.insert("SipRegistration", local_var_param_value.to_string());
210    }
211    if let Some(local_var_param_value) = emergency_calling_enabled {
212        local_var_form_params.insert("EmergencyCallingEnabled", local_var_param_value.to_string());
213    }
214    if let Some(local_var_param_value) = secure {
215        local_var_form_params.insert("Secure", local_var_param_value.to_string());
216    }
217    if let Some(local_var_param_value) = byoc_trunk_sid {
218        local_var_form_params.insert("ByocTrunkSid", local_var_param_value.to_string());
219    }
220    if let Some(local_var_param_value) = emergency_caller_sid {
221        local_var_form_params.insert("EmergencyCallerSid", local_var_param_value.to_string());
222    }
223    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
224
225    let local_var_req = local_var_req_builder.build()?;
226    let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228    let local_var_status = local_var_resp.status();
229    let local_var_content = local_var_resp.text().await?;
230
231    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
232        serde_json::from_str(&local_var_content).map_err(Error::from)
233    } else {
234        let local_var_entity: Option<CreateSipDomainError> = serde_json::from_str(&local_var_content).ok();
235        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
236        Err(Error::ResponseError(local_var_error))
237    }
238}
239
240/// Delete an instance of a Domain
241pub async fn delete_sip_domain(configuration: &configuration::Configuration, params: DeleteSipDomainParams) -> Result<(), Error<DeleteSipDomainError>> {
242    let local_var_configuration = configuration;
243
244    // unbox the parameters
245    let account_sid = params.account_sid;
246    let sid = params.sid;
247
248
249    let local_var_client = &local_var_configuration.client;
250
251    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
252    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
253
254    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
255        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
256    }
257    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
258        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
259    };
260
261    let local_var_req = local_var_req_builder.build()?;
262    let local_var_resp = local_var_client.execute(local_var_req).await?;
263
264    let local_var_status = local_var_resp.status();
265    let local_var_content = local_var_resp.text().await?;
266
267    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
268        Ok(())
269    } else {
270        let local_var_entity: Option<DeleteSipDomainError> = serde_json::from_str(&local_var_content).ok();
271        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
272        Err(Error::ResponseError(local_var_error))
273    }
274}
275
276/// Fetch an instance of a Domain
277pub async fn fetch_sip_domain(configuration: &configuration::Configuration, params: FetchSipDomainParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipDomain, Error<FetchSipDomainError>> {
278    let local_var_configuration = configuration;
279
280    // unbox the parameters
281    let account_sid = params.account_sid;
282    let sid = params.sid;
283
284
285    let local_var_client = &local_var_configuration.client;
286
287    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
288    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
289
290    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
291        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292    }
293    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
294        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
295    };
296
297    let local_var_req = local_var_req_builder.build()?;
298    let local_var_resp = local_var_client.execute(local_var_req).await?;
299
300    let local_var_status = local_var_resp.status();
301    let local_var_content = local_var_resp.text().await?;
302
303    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
304        serde_json::from_str(&local_var_content).map_err(Error::from)
305    } else {
306        let local_var_entity: Option<FetchSipDomainError> = serde_json::from_str(&local_var_content).ok();
307        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
308        Err(Error::ResponseError(local_var_error))
309    }
310}
311
312/// Retrieve a list of domains belonging to the account used to make the request
313pub async fn list_sip_domain(configuration: &configuration::Configuration, params: ListSipDomainParams) -> Result<models::ListSipDomainResponse, Error<ListSipDomainError>> {
314    let local_var_configuration = configuration;
315
316    // unbox the parameters
317    let account_sid = params.account_sid;
318    let page_size = params.page_size;
319    let page = params.page;
320    let page_token = params.page_token;
321
322
323    let local_var_client = &local_var_configuration.client;
324
325    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
326    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
327
328    if let Some(ref local_var_str) = page_size {
329        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
330    }
331    if let Some(ref local_var_str) = page {
332        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
333    }
334    if let Some(ref local_var_str) = page_token {
335        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
336    }
337    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
339    }
340    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
341        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
342    };
343
344    let local_var_req = local_var_req_builder.build()?;
345    let local_var_resp = local_var_client.execute(local_var_req).await?;
346
347    let local_var_status = local_var_resp.status();
348    let local_var_content = local_var_resp.text().await?;
349
350    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
351        serde_json::from_str(&local_var_content).map_err(Error::from)
352    } else {
353        let local_var_entity: Option<ListSipDomainError> = serde_json::from_str(&local_var_content).ok();
354        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
355        Err(Error::ResponseError(local_var_error))
356    }
357}
358
359/// Update the attributes of a domain
360pub async fn update_sip_domain(configuration: &configuration::Configuration, params: UpdateSipDomainParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipDomain, Error<UpdateSipDomainError>> {
361    let local_var_configuration = configuration;
362
363    // unbox the parameters
364    let account_sid = params.account_sid;
365    let sid = params.sid;
366    let friendly_name = params.friendly_name;
367    let voice_fallback_method = params.voice_fallback_method;
368    let voice_fallback_url = params.voice_fallback_url;
369    let voice_method = params.voice_method;
370    let voice_status_callback_method = params.voice_status_callback_method;
371    let voice_status_callback_url = params.voice_status_callback_url;
372    let voice_url = params.voice_url;
373    let sip_registration = params.sip_registration;
374    let domain_name = params.domain_name;
375    let emergency_calling_enabled = params.emergency_calling_enabled;
376    let secure = params.secure;
377    let byoc_trunk_sid = params.byoc_trunk_sid;
378    let emergency_caller_sid = params.emergency_caller_sid;
379
380
381    let local_var_client = &local_var_configuration.client;
382
383    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
384    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
385
386    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
387        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
388    }
389    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
390        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
391    };
392    let mut local_var_form_params = std::collections::HashMap::new();
393    if let Some(local_var_param_value) = friendly_name {
394        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
395    }
396    if let Some(local_var_param_value) = voice_fallback_method {
397        local_var_form_params.insert("VoiceFallbackMethod", local_var_param_value.to_string());
398    }
399    if let Some(local_var_param_value) = voice_fallback_url {
400        local_var_form_params.insert("VoiceFallbackUrl", local_var_param_value.to_string());
401    }
402    if let Some(local_var_param_value) = voice_method {
403        local_var_form_params.insert("VoiceMethod", local_var_param_value.to_string());
404    }
405    if let Some(local_var_param_value) = voice_status_callback_method {
406        local_var_form_params.insert("VoiceStatusCallbackMethod", local_var_param_value.to_string());
407    }
408    if let Some(local_var_param_value) = voice_status_callback_url {
409        local_var_form_params.insert("VoiceStatusCallbackUrl", local_var_param_value.to_string());
410    }
411    if let Some(local_var_param_value) = voice_url {
412        local_var_form_params.insert("VoiceUrl", local_var_param_value.to_string());
413    }
414    if let Some(local_var_param_value) = sip_registration {
415        local_var_form_params.insert("SipRegistration", local_var_param_value.to_string());
416    }
417    if let Some(local_var_param_value) = domain_name {
418        local_var_form_params.insert("DomainName", local_var_param_value.to_string());
419    }
420    if let Some(local_var_param_value) = emergency_calling_enabled {
421        local_var_form_params.insert("EmergencyCallingEnabled", local_var_param_value.to_string());
422    }
423    if let Some(local_var_param_value) = secure {
424        local_var_form_params.insert("Secure", local_var_param_value.to_string());
425    }
426    if let Some(local_var_param_value) = byoc_trunk_sid {
427        local_var_form_params.insert("ByocTrunkSid", local_var_param_value.to_string());
428    }
429    if let Some(local_var_param_value) = emergency_caller_sid {
430        local_var_form_params.insert("EmergencyCallerSid", local_var_param_value.to_string());
431    }
432    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
433
434    let local_var_req = local_var_req_builder.build()?;
435    let local_var_resp = local_var_client.execute(local_var_req).await?;
436
437    let local_var_status = local_var_resp.status();
438    let local_var_content = local_var_resp.text().await?;
439
440    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
441        serde_json::from_str(&local_var_content).map_err(Error::from)
442    } else {
443        let local_var_entity: Option<UpdateSipDomainError> = serde_json::from_str(&local_var_content).ok();
444        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
445        Err(Error::ResponseError(local_var_error))
446    }
447}
448