twilio_rust_openapi/apis/
api20100401_credential_list_mapping_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_credential_list_mapping`]
18#[derive(Clone, Debug)]
19pub struct CreateSipCredentialListMappingParams {
20    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
21    pub account_sid: String,
22    /// A 34 character string that uniquely identifies the SIP Domain for which the CredentialList resource will be mapped.
23    pub domain_sid: String,
24    /// A 34 character string that uniquely identifies the CredentialList resource to map to the SIP domain.
25    pub credential_list_sid: String
26}
27
28/// struct for passing parameters to the method [`delete_sip_credential_list_mapping`]
29#[derive(Clone, Debug)]
30pub struct DeleteSipCredentialListMappingParams {
31    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
32    pub account_sid: String,
33    /// A 34 character string that uniquely identifies the SIP Domain that includes the resource to delete.
34    pub domain_sid: String,
35    /// A 34 character string that uniquely identifies the resource to delete.
36    pub sid: String
37}
38
39/// struct for passing parameters to the method [`fetch_sip_credential_list_mapping`]
40#[derive(Clone, Debug)]
41pub struct FetchSipCredentialListMappingParams {
42    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
43    pub account_sid: String,
44    /// A 34 character string that uniquely identifies the SIP Domain that includes the resource to fetch.
45    pub domain_sid: String,
46    /// A 34 character string that uniquely identifies the resource to fetch.
47    pub sid: String
48}
49
50/// struct for passing parameters to the method [`list_sip_credential_list_mapping`]
51#[derive(Clone, Debug)]
52pub struct ListSipCredentialListMappingParams {
53    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
54    pub account_sid: String,
55    /// A 34 character string that uniquely identifies the SIP Domain that includes the resource to read.
56    pub domain_sid: String,
57    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
58    pub page_size: Option<i32>,
59    /// The page index. This value is simply for client state.
60    pub page: Option<i32>,
61    /// The page token. This is provided by the API.
62    pub page_token: Option<String>
63}
64
65
66/// struct for typed errors of method [`create_sip_credential_list_mapping`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum CreateSipCredentialListMappingError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`delete_sip_credential_list_mapping`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum DeleteSipCredentialListMappingError {
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`fetch_sip_credential_list_mapping`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum FetchSipCredentialListMappingError {
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`list_sip_credential_list_mapping`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum ListSipCredentialListMappingError {
91    UnknownValue(serde_json::Value),
92}
93
94
95/// Create a CredentialListMapping resource for an account.
96pub async fn create_sip_credential_list_mapping(configuration: &configuration::Configuration, params: CreateSipCredentialListMappingParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipDomainPeriodSipCredentialListMapping, Error<CreateSipCredentialListMappingError>> {
97    let local_var_configuration = configuration;
98
99    // unbox the parameters
100    let account_sid = params.account_sid;
101    let domain_sid = params.domain_sid;
102    let credential_list_sid = params.credential_list_sid;
103
104
105    let local_var_client = &local_var_configuration.client;
106
107    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), DomainSid=crate::apis::urlencode(domain_sid));
108    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
109
110    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
111        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112    }
113    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
114        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
115    };
116    let mut local_var_form_params = std::collections::HashMap::new();
117    local_var_form_params.insert("CredentialListSid", credential_list_sid.to_string());
118    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
119
120    let local_var_req = local_var_req_builder.build()?;
121    let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123    let local_var_status = local_var_resp.status();
124    let local_var_content = local_var_resp.text().await?;
125
126    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127        serde_json::from_str(&local_var_content).map_err(Error::from)
128    } else {
129        let local_var_entity: Option<CreateSipCredentialListMappingError> = serde_json::from_str(&local_var_content).ok();
130        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134
135/// Delete a CredentialListMapping resource from an account.
136pub async fn delete_sip_credential_list_mapping(configuration: &configuration::Configuration, params: DeleteSipCredentialListMappingParams) -> Result<(), Error<DeleteSipCredentialListMappingError>> {
137    let local_var_configuration = configuration;
138
139    // unbox the parameters
140    let account_sid = params.account_sid;
141    let domain_sid = params.domain_sid;
142    let sid = params.sid;
143
144
145    let local_var_client = &local_var_configuration.client;
146
147    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), DomainSid=crate::apis::urlencode(domain_sid), Sid=crate::apis::urlencode(sid));
148    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
149
150    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
151        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
152    }
153    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
154        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
155    };
156
157    let local_var_req = local_var_req_builder.build()?;
158    let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160    let local_var_status = local_var_resp.status();
161    let local_var_content = local_var_resp.text().await?;
162
163    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
164        Ok(())
165    } else {
166        let local_var_entity: Option<DeleteSipCredentialListMappingError> = serde_json::from_str(&local_var_content).ok();
167        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
168        Err(Error::ResponseError(local_var_error))
169    }
170}
171
172/// Fetch a single CredentialListMapping resource from an account.
173pub async fn fetch_sip_credential_list_mapping(configuration: &configuration::Configuration, params: FetchSipCredentialListMappingParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipDomainPeriodSipCredentialListMapping, Error<FetchSipCredentialListMappingError>> {
174    let local_var_configuration = configuration;
175
176    // unbox the parameters
177    let account_sid = params.account_sid;
178    let domain_sid = params.domain_sid;
179    let sid = params.sid;
180
181
182    let local_var_client = &local_var_configuration.client;
183
184    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), DomainSid=crate::apis::urlencode(domain_sid), Sid=crate::apis::urlencode(sid));
185    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
186
187    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189    }
190    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
191        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<FetchSipCredentialListMappingError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209/// Read multiple CredentialListMapping resources from an account.
210pub async fn list_sip_credential_list_mapping(configuration: &configuration::Configuration, params: ListSipCredentialListMappingParams) -> Result<models::ListSipCredentialListMappingResponse, Error<ListSipCredentialListMappingError>> {
211    let local_var_configuration = configuration;
212
213    // unbox the parameters
214    let account_sid = params.account_sid;
215    let domain_sid = params.domain_sid;
216    let page_size = params.page_size;
217    let page = params.page;
218    let page_token = params.page_token;
219
220
221    let local_var_client = &local_var_configuration.client;
222
223    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), DomainSid=crate::apis::urlencode(domain_sid));
224    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
225
226    if let Some(ref local_var_str) = page_size {
227        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
228    }
229    if let Some(ref local_var_str) = page {
230        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
231    }
232    if let Some(ref local_var_str) = page_token {
233        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
234    }
235    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
236        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237    }
238    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
239        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
240    };
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<ListSipCredentialListMappingError> = serde_json::from_str(&local_var_content).ok();
252        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253        Err(Error::ResponseError(local_var_error))
254    }
255}
256