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