twilio_rust_openapi/apis/
api20100401_credential_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`]
18#[derive(Clone, Debug)]
19pub struct CreateSipCredentialParams {
20    /// The unique id of the Account that is responsible for this resource.
21    pub account_sid: String,
22    /// The unique id that identifies the credential list to include the created credential.
23    pub credential_list_sid: String,
24    /// The username that will be passed when authenticating SIP requests. The username should be sent in response to Twilio's challenge of the initial INVITE. It can be up to 32 characters long.
25    pub username: String,
26    /// The password that the username will use when authenticating SIP requests. The password must be a minimum of 12 characters, contain at least 1 digit, and have mixed case. (eg `IWasAtSignal2018`)
27    pub password: String
28}
29
30/// struct for passing parameters to the method [`delete_sip_credential`]
31#[derive(Clone, Debug)]
32pub struct DeleteSipCredentialParams {
33    /// The unique id of the Account that is responsible for this resource.
34    pub account_sid: String,
35    /// The unique id that identifies the credential list that contains the desired credentials.
36    pub credential_list_sid: String,
37    /// The unique id that identifies the resource to delete.
38    pub sid: String
39}
40
41/// struct for passing parameters to the method [`fetch_sip_credential`]
42#[derive(Clone, Debug)]
43pub struct FetchSipCredentialParams {
44    /// The unique id of the Account that is responsible for this resource.
45    pub account_sid: String,
46    /// The unique id that identifies the credential list that contains the desired credential.
47    pub credential_list_sid: String,
48    /// The unique id that identifies the resource to fetch.
49    pub sid: String
50}
51
52/// struct for passing parameters to the method [`list_sip_credential`]
53#[derive(Clone, Debug)]
54pub struct ListSipCredentialParams {
55    /// The unique id of the Account that is responsible for this resource.
56    pub account_sid: String,
57    /// The unique id that identifies the credential list that contains the desired credentials.
58    pub credential_list_sid: String,
59    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
60    pub page_size: Option<i32>,
61    /// The page index. This value is simply for client state.
62    pub page: Option<i32>,
63    /// The page token. This is provided by the API.
64    pub page_token: Option<String>
65}
66
67/// struct for passing parameters to the method [`update_sip_credential`]
68#[derive(Clone, Debug)]
69pub struct UpdateSipCredentialParams {
70    /// The unique id of the Account that is responsible for this resource.
71    pub account_sid: String,
72    /// The unique id that identifies the credential list that includes this credential.
73    pub credential_list_sid: String,
74    /// The unique id that identifies the resource to update.
75    pub sid: String,
76    /// The password that the username will use when authenticating SIP requests. The password must be a minimum of 12 characters, contain at least 1 digit, and have mixed case. (eg `IWasAtSignal2018`)
77    pub password: Option<String>
78}
79
80
81/// struct for typed errors of method [`create_sip_credential`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum CreateSipCredentialError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`delete_sip_credential`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum DeleteSipCredentialError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`fetch_sip_credential`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum FetchSipCredentialError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`list_sip_credential`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum ListSipCredentialError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`update_sip_credential`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum UpdateSipCredentialError {
113    UnknownValue(serde_json::Value),
114}
115
116
117/// Create a new credential resource.
118pub async fn create_sip_credential(configuration: &configuration::Configuration, params: CreateSipCredentialParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialListPeriodSipCredential, Error<CreateSipCredentialError>> {
119    let local_var_configuration = configuration;
120
121    // unbox the parameters
122    let account_sid = params.account_sid;
123    let credential_list_sid = params.credential_list_sid;
124    let username = params.username;
125    let password = params.password;
126
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CredentialListSid=crate::apis::urlencode(credential_list_sid));
131    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
134        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135    }
136    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
137        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
138    };
139    let mut local_var_form_params = std::collections::HashMap::new();
140    local_var_form_params.insert("Username", username.to_string());
141    local_var_form_params.insert("Password", password.to_string());
142    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
143
144    let local_var_req = local_var_req_builder.build()?;
145    let local_var_resp = local_var_client.execute(local_var_req).await?;
146
147    let local_var_status = local_var_resp.status();
148    let local_var_content = local_var_resp.text().await?;
149
150    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
151        serde_json::from_str(&local_var_content).map_err(Error::from)
152    } else {
153        let local_var_entity: Option<CreateSipCredentialError> = serde_json::from_str(&local_var_content).ok();
154        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
155        Err(Error::ResponseError(local_var_error))
156    }
157}
158
159/// Delete a credential resource.
160pub async fn delete_sip_credential(configuration: &configuration::Configuration, params: DeleteSipCredentialParams) -> Result<(), Error<DeleteSipCredentialError>> {
161    let local_var_configuration = configuration;
162
163    // unbox the parameters
164    let account_sid = params.account_sid;
165    let credential_list_sid = params.credential_list_sid;
166    let sid = params.sid;
167
168
169    let local_var_client = &local_var_configuration.client;
170
171    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CredentialListSid=crate::apis::urlencode(credential_list_sid), Sid=crate::apis::urlencode(sid));
172    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
173
174    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
175        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176    }
177    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
178        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
179    };
180
181    let local_var_req = local_var_req_builder.build()?;
182    let local_var_resp = local_var_client.execute(local_var_req).await?;
183
184    let local_var_status = local_var_resp.status();
185    let local_var_content = local_var_resp.text().await?;
186
187    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
188        Ok(())
189    } else {
190        let local_var_entity: Option<DeleteSipCredentialError> = serde_json::from_str(&local_var_content).ok();
191        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
192        Err(Error::ResponseError(local_var_error))
193    }
194}
195
196/// Fetch a single credential.
197pub async fn fetch_sip_credential(configuration: &configuration::Configuration, params: FetchSipCredentialParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialListPeriodSipCredential, Error<FetchSipCredentialError>> {
198    let local_var_configuration = configuration;
199
200    // unbox the parameters
201    let account_sid = params.account_sid;
202    let credential_list_sid = params.credential_list_sid;
203    let sid = params.sid;
204
205
206    let local_var_client = &local_var_configuration.client;
207
208    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CredentialListSid=crate::apis::urlencode(credential_list_sid), Sid=crate::apis::urlencode(sid));
209    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
210
211    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
212        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
213    }
214    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
215        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
216    };
217
218    let local_var_req = local_var_req_builder.build()?;
219    let local_var_resp = local_var_client.execute(local_var_req).await?;
220
221    let local_var_status = local_var_resp.status();
222    let local_var_content = local_var_resp.text().await?;
223
224    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
225        serde_json::from_str(&local_var_content).map_err(Error::from)
226    } else {
227        let local_var_entity: Option<FetchSipCredentialError> = serde_json::from_str(&local_var_content).ok();
228        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
229        Err(Error::ResponseError(local_var_error))
230    }
231}
232
233/// Retrieve a list of credentials.
234pub async fn list_sip_credential(configuration: &configuration::Configuration, params: ListSipCredentialParams) -> Result<models::ListSipCredentialResponse, Error<ListSipCredentialError>> {
235    let local_var_configuration = configuration;
236
237    // unbox the parameters
238    let account_sid = params.account_sid;
239    let credential_list_sid = params.credential_list_sid;
240    let page_size = params.page_size;
241    let page = params.page;
242    let page_token = params.page_token;
243
244
245    let local_var_client = &local_var_configuration.client;
246
247    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CredentialListSid=crate::apis::urlencode(credential_list_sid));
248    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
249
250    if let Some(ref local_var_str) = page_size {
251        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
252    }
253    if let Some(ref local_var_str) = page {
254        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
255    }
256    if let Some(ref local_var_str) = page_token {
257        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
258    }
259    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
260        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
261    }
262    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
263        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
264    };
265
266    let local_var_req = local_var_req_builder.build()?;
267    let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269    let local_var_status = local_var_resp.status();
270    let local_var_content = local_var_resp.text().await?;
271
272    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
273        serde_json::from_str(&local_var_content).map_err(Error::from)
274    } else {
275        let local_var_entity: Option<ListSipCredentialError> = serde_json::from_str(&local_var_content).ok();
276        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
277        Err(Error::ResponseError(local_var_error))
278    }
279}
280
281/// Update a credential resource.
282pub async fn update_sip_credential(configuration: &configuration::Configuration, params: UpdateSipCredentialParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipCredentialListPeriodSipCredential, Error<UpdateSipCredentialError>> {
283    let local_var_configuration = configuration;
284
285    // unbox the parameters
286    let account_sid = params.account_sid;
287    let credential_list_sid = params.credential_list_sid;
288    let sid = params.sid;
289    let password = params.password;
290
291
292    let local_var_client = &local_var_configuration.client;
293
294    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CredentialListSid=crate::apis::urlencode(credential_list_sid), Sid=crate::apis::urlencode(sid));
295    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
296
297    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
298        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299    }
300    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
301        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
302    };
303    let mut local_var_form_params = std::collections::HashMap::new();
304    if let Some(local_var_param_value) = password {
305        local_var_form_params.insert("Password", local_var_param_value.to_string());
306    }
307    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
308
309    let local_var_req = local_var_req_builder.build()?;
310    let local_var_resp = local_var_client.execute(local_var_req).await?;
311
312    let local_var_status = local_var_resp.status();
313    let local_var_content = local_var_resp.text().await?;
314
315    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
316        serde_json::from_str(&local_var_content).map_err(Error::from)
317    } else {
318        let local_var_entity: Option<UpdateSipCredentialError> = serde_json::from_str(&local_var_content).ok();
319        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
320        Err(Error::ResponseError(local_var_error))
321    }
322}
323