twilio_rust_openapi/apis/
api20100401_credential_list_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`]
18#[derive(Clone, Debug)]
19pub struct CreateSipCredentialListParams {
20    /// The unique id of the Account that is responsible for this resource.
21    pub account_sid: String,
22    /// A human readable descriptive text that describes the CredentialList, up to 64 characters long.
23    pub friendly_name: String
24}
25
26/// struct for passing parameters to the method [`delete_sip_credential_list`]
27#[derive(Clone, Debug)]
28pub struct DeleteSipCredentialListParams {
29    /// The unique id of the Account that is responsible for this resource.
30    pub account_sid: String,
31    /// The credential list Sid that uniquely identifies this resource
32    pub sid: String
33}
34
35/// struct for passing parameters to the method [`fetch_sip_credential_list`]
36#[derive(Clone, Debug)]
37pub struct FetchSipCredentialListParams {
38    /// The unique id of the Account that is responsible for this resource.
39    pub account_sid: String,
40    /// The credential list Sid that uniquely identifies this resource
41    pub sid: String
42}
43
44/// struct for passing parameters to the method [`list_sip_credential_list`]
45#[derive(Clone, Debug)]
46pub struct ListSipCredentialListParams {
47    /// The unique id of the Account that is responsible for this resource.
48    pub account_sid: String,
49    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
50    pub page_size: Option<i32>,
51    /// The page index. This value is simply for client state.
52    pub page: Option<i32>,
53    /// The page token. This is provided by the API.
54    pub page_token: Option<String>
55}
56
57/// struct for passing parameters to the method [`update_sip_credential_list`]
58#[derive(Clone, Debug)]
59pub struct UpdateSipCredentialListParams {
60    /// The unique id of the Account that is responsible for this resource.
61    pub account_sid: String,
62    /// The credential list Sid that uniquely identifies this resource
63    pub sid: String,
64    /// A human readable descriptive text for a CredentialList, up to 64 characters long.
65    pub friendly_name: String
66}
67
68
69/// struct for typed errors of method [`create_sip_credential_list`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum CreateSipCredentialListError {
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`delete_sip_credential_list`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum DeleteSipCredentialListError {
80    UnknownValue(serde_json::Value),
81}
82
83/// struct for typed errors of method [`fetch_sip_credential_list`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum FetchSipCredentialListError {
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`list_sip_credential_list`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum ListSipCredentialListError {
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`update_sip_credential_list`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum UpdateSipCredentialListError {
101    UnknownValue(serde_json::Value),
102}
103
104
105/// Create a Credential List
106pub async fn create_sip_credential_list(configuration: &configuration::Configuration, params: CreateSipCredentialListParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialList, Error<CreateSipCredentialListError>> {
107    let local_var_configuration = configuration;
108
109    // unbox the parameters
110    let account_sid = params.account_sid;
111    let friendly_name = params.friendly_name;
112
113
114    let local_var_client = &local_var_configuration.client;
115
116    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
117    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
118
119    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
120        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
121    }
122    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
123        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
124    };
125    let mut local_var_form_params = std::collections::HashMap::new();
126    local_var_form_params.insert("FriendlyName", friendly_name.to_string());
127    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
128
129    let local_var_req = local_var_req_builder.build()?;
130    let local_var_resp = local_var_client.execute(local_var_req).await?;
131
132    let local_var_status = local_var_resp.status();
133    let local_var_content = local_var_resp.text().await?;
134
135    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
136        serde_json::from_str(&local_var_content).map_err(Error::from)
137    } else {
138        let local_var_entity: Option<CreateSipCredentialListError> = serde_json::from_str(&local_var_content).ok();
139        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
140        Err(Error::ResponseError(local_var_error))
141    }
142}
143
144/// Delete a Credential List
145pub async fn delete_sip_credential_list(configuration: &configuration::Configuration, params: DeleteSipCredentialListParams) -> Result<(), Error<DeleteSipCredentialListError>> {
146    let local_var_configuration = configuration;
147
148    // unbox the parameters
149    let account_sid = params.account_sid;
150    let sid = params.sid;
151
152
153    let local_var_client = &local_var_configuration.client;
154
155    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
156    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
157
158    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
160    }
161    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
162        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
163    };
164
165    let local_var_req = local_var_req_builder.build()?;
166    let local_var_resp = local_var_client.execute(local_var_req).await?;
167
168    let local_var_status = local_var_resp.status();
169    let local_var_content = local_var_resp.text().await?;
170
171    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
172        Ok(())
173    } else {
174        let local_var_entity: Option<DeleteSipCredentialListError> = serde_json::from_str(&local_var_content).ok();
175        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
176        Err(Error::ResponseError(local_var_error))
177    }
178}
179
180/// Get a Credential List
181pub async fn fetch_sip_credential_list(configuration: &configuration::Configuration, params: FetchSipCredentialListParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialList, Error<FetchSipCredentialListError>> {
182    let local_var_configuration = configuration;
183
184    // unbox the parameters
185    let account_sid = params.account_sid;
186    let sid = params.sid;
187
188
189    let local_var_client = &local_var_configuration.client;
190
191    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
192    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
195        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
196    }
197    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
198        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
199    };
200
201    let local_var_req = local_var_req_builder.build()?;
202    let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204    let local_var_status = local_var_resp.status();
205    let local_var_content = local_var_resp.text().await?;
206
207    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
208        serde_json::from_str(&local_var_content).map_err(Error::from)
209    } else {
210        let local_var_entity: Option<FetchSipCredentialListError> = serde_json::from_str(&local_var_content).ok();
211        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
212        Err(Error::ResponseError(local_var_error))
213    }
214}
215
216/// Get All Credential Lists
217pub async fn list_sip_credential_list(configuration: &configuration::Configuration, params: ListSipCredentialListParams) -> Result<models::ListSipCredentialListResponse, Error<ListSipCredentialListError>> {
218    let local_var_configuration = configuration;
219
220    // unbox the parameters
221    let account_sid = params.account_sid;
222    let page_size = params.page_size;
223    let page = params.page;
224    let page_token = params.page_token;
225
226
227    let local_var_client = &local_var_configuration.client;
228
229    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
230    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
231
232    if let Some(ref local_var_str) = page_size {
233        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
234    }
235    if let Some(ref local_var_str) = page {
236        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
237    }
238    if let Some(ref local_var_str) = page_token {
239        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
240    }
241    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
242        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
243    }
244    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
245        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
246    };
247
248    let local_var_req = local_var_req_builder.build()?;
249    let local_var_resp = local_var_client.execute(local_var_req).await?;
250
251    let local_var_status = local_var_resp.status();
252    let local_var_content = local_var_resp.text().await?;
253
254    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255        serde_json::from_str(&local_var_content).map_err(Error::from)
256    } else {
257        let local_var_entity: Option<ListSipCredentialListError> = serde_json::from_str(&local_var_content).ok();
258        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
259        Err(Error::ResponseError(local_var_error))
260    }
261}
262
263/// Update a Credential List
264pub async fn update_sip_credential_list(configuration: &configuration::Configuration, params: UpdateSipCredentialListParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialList, Error<UpdateSipCredentialListError>> {
265    let local_var_configuration = configuration;
266
267    // unbox the parameters
268    let account_sid = params.account_sid;
269    let sid = params.sid;
270    let friendly_name = params.friendly_name;
271
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
282        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
283    };
284    let mut local_var_form_params = std::collections::HashMap::new();
285    local_var_form_params.insert("FriendlyName", friendly_name.to_string());
286    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
287
288    let local_var_req = local_var_req_builder.build()?;
289    let local_var_resp = local_var_client.execute(local_var_req).await?;
290
291    let local_var_status = local_var_resp.status();
292    let local_var_content = local_var_resp.text().await?;
293
294    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
295        serde_json::from_str(&local_var_content).map_err(Error::from)
296    } else {
297        let local_var_entity: Option<UpdateSipCredentialListError> = serde_json::from_str(&local_var_content).ok();
298        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
299        Err(Error::ResponseError(local_var_error))
300    }
301}
302