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