twilio_rust_openapi/apis/
api20100401_member_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 [`fetch_member`]
18#[derive(Clone, Debug)]
19pub struct FetchMemberParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Member resource(s) to fetch.
21    pub account_sid: String,
22    /// The SID of the Queue in which to find the members to fetch.
23    pub queue_sid: String,
24    /// The [Call](https://www.twilio.com/docs/voice/api/call-resource) SID of the resource(s) to fetch.
25    pub call_sid: String
26}
27
28/// struct for passing parameters to the method [`list_member`]
29#[derive(Clone, Debug)]
30pub struct ListMemberParams {
31    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Member resource(s) to read.
32    pub account_sid: String,
33    /// The SID of the Queue in which to find the members
34    pub queue_sid: String,
35    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
36    pub page_size: Option<i32>,
37    /// The page index. This value is simply for client state.
38    pub page: Option<i32>,
39    /// The page token. This is provided by the API.
40    pub page_token: Option<String>
41}
42
43/// struct for passing parameters to the method [`update_member`]
44#[derive(Clone, Debug)]
45pub struct UpdateMemberParams {
46    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Member resource(s) to update.
47    pub account_sid: String,
48    /// The SID of the Queue in which to find the members to update.
49    pub queue_sid: String,
50    /// The [Call](https://www.twilio.com/docs/voice/api/call-resource) SID of the resource(s) to update.
51    pub call_sid: String,
52    /// The absolute URL of the Queue resource.
53    pub url: String,
54    /// How to pass the update request data. Can be `GET` or `POST` and the default is `POST`. `POST` sends the data as encoded form data and `GET` sends the data as query parameters.
55    pub method: Option<String>
56}
57
58
59/// struct for typed errors of method [`fetch_member`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum FetchMemberError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`list_member`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListMemberError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`update_member`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum UpdateMemberError {
77    UnknownValue(serde_json::Value),
78}
79
80
81/// Fetch a specific member from the queue
82pub async fn fetch_member(configuration: &configuration::Configuration, params: FetchMemberParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodQueuePeriodMember, Error<FetchMemberError>> {
83    let local_var_configuration = configuration;
84
85    // unbox the parameters
86    let account_sid = params.account_sid;
87    let queue_sid = params.queue_sid;
88    let call_sid = params.call_sid;
89
90
91    let local_var_client = &local_var_configuration.client;
92
93    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), QueueSid=crate::apis::urlencode(queue_sid), CallSid=crate::apis::urlencode(call_sid));
94    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
95
96    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
97        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
98    }
99    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
100        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
101    };
102
103    let local_var_req = local_var_req_builder.build()?;
104    let local_var_resp = local_var_client.execute(local_var_req).await?;
105
106    let local_var_status = local_var_resp.status();
107    let local_var_content = local_var_resp.text().await?;
108
109    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110        serde_json::from_str(&local_var_content).map_err(Error::from)
111    } else {
112        let local_var_entity: Option<FetchMemberError> = serde_json::from_str(&local_var_content).ok();
113        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
114        Err(Error::ResponseError(local_var_error))
115    }
116}
117
118/// Retrieve the members of the queue
119pub async fn list_member(configuration: &configuration::Configuration, params: ListMemberParams) -> Result<models::ListMemberResponse, Error<ListMemberError>> {
120    let local_var_configuration = configuration;
121
122    // unbox the parameters
123    let account_sid = params.account_sid;
124    let queue_sid = params.queue_sid;
125    let page_size = params.page_size;
126    let page = params.page;
127    let page_token = params.page_token;
128
129
130    let local_var_client = &local_var_configuration.client;
131
132    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), QueueSid=crate::apis::urlencode(queue_sid));
133    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
134
135    if let Some(ref local_var_str) = page_size {
136        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
137    }
138    if let Some(ref local_var_str) = page {
139        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
140    }
141    if let Some(ref local_var_str) = page_token {
142        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
143    }
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
148        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
149    };
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        serde_json::from_str(&local_var_content).map_err(Error::from)
159    } else {
160        let local_var_entity: Option<ListMemberError> = serde_json::from_str(&local_var_content).ok();
161        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
162        Err(Error::ResponseError(local_var_error))
163    }
164}
165
166/// Dequeue a member from a queue and have the member's call begin executing the TwiML document at that URL
167pub async fn update_member(configuration: &configuration::Configuration, params: UpdateMemberParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodQueuePeriodMember, Error<UpdateMemberError>> {
168    let local_var_configuration = configuration;
169
170    // unbox the parameters
171    let account_sid = params.account_sid;
172    let queue_sid = params.queue_sid;
173    let call_sid = params.call_sid;
174    let url = params.url;
175    let method = params.method;
176
177
178    let local_var_client = &local_var_configuration.client;
179
180    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), QueueSid=crate::apis::urlencode(queue_sid), CallSid=crate::apis::urlencode(call_sid));
181    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
184        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
185    }
186    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
187        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
188    };
189    let mut local_var_form_params = std::collections::HashMap::new();
190    local_var_form_params.insert("Url", url.to_string());
191    if let Some(local_var_param_value) = method {
192        local_var_form_params.insert("Method", local_var_param_value.to_string());
193    }
194    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
195
196    let local_var_req = local_var_req_builder.build()?;
197    let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199    let local_var_status = local_var_resp.status();
200    let local_var_content = local_var_resp.text().await?;
201
202    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
203        serde_json::from_str(&local_var_content).map_err(Error::from)
204    } else {
205        let local_var_entity: Option<UpdateMemberError> = serde_json::from_str(&local_var_content).ok();
206        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
207        Err(Error::ResponseError(local_var_error))
208    }
209}
210