twilio_rust_openapi/apis/
api20100401_event_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 [`list_call_event`]
18#[derive(Clone, Debug)]
19pub struct ListCallEventParams {
20    /// The unique SID identifier of the Account.
21    pub account_sid: String,
22    /// The unique SID identifier of the Call.
23    pub call_sid: String,
24    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
25    pub page_size: Option<i32>,
26    /// The page index. This value is simply for client state.
27    pub page: Option<i32>,
28    /// The page token. This is provided by the API.
29    pub page_token: Option<String>
30}
31
32
33/// struct for typed errors of method [`list_call_event`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ListCallEventError {
37    UnknownValue(serde_json::Value),
38}
39
40
41/// Retrieve a list of all events for a call.
42pub async fn list_call_event(configuration: &configuration::Configuration, params: ListCallEventParams) -> Result<models::ListCallEventResponse, Error<ListCallEventError>> {
43    let local_var_configuration = configuration;
44
45    // unbox the parameters
46    let account_sid = params.account_sid;
47    let call_sid = params.call_sid;
48    let page_size = params.page_size;
49    let page = params.page;
50    let page_token = params.page_token;
51
52
53    let local_var_client = &local_var_configuration.client;
54
55    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CallSid=crate::apis::urlencode(call_sid));
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58    if let Some(ref local_var_str) = page_size {
59        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
60    }
61    if let Some(ref local_var_str) = page {
62        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
63    }
64    if let Some(ref local_var_str) = page_token {
65        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
66    }
67    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
68        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69    }
70    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
71        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
72    };
73
74    let local_var_req = local_var_req_builder.build()?;
75    let local_var_resp = local_var_client.execute(local_var_req).await?;
76
77    let local_var_status = local_var_resp.status();
78    let local_var_content = local_var_resp.text().await?;
79
80    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81        serde_json::from_str(&local_var_content).map_err(Error::from)
82    } else {
83        let local_var_entity: Option<ListCallEventError> = serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85        Err(Error::ResponseError(local_var_error))
86    }
87}
88