twilio_rust_openapi/apis/
api20100401_validation_request_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_validation_request`]
18#[derive(Clone, Debug)]
19pub struct CreateValidationRequestParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for the new caller ID resource.
21    pub account_sid: String,
22    /// The phone number to verify in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, which consists of a + followed by the country code and subscriber number.
23    pub phone_number: String,
24    /// A descriptive string that you create to describe the new caller ID resource. It can be up to 64 characters long. The default value is a formatted version of the phone number.
25    pub friendly_name: Option<String>,
26    /// The number of seconds to delay before initiating the verification call. Can be an integer between `0` and `60`, inclusive. The default is `0`.
27    pub call_delay: Option<i32>,
28    /// The digits to dial after connecting the verification call.
29    pub extension: Option<String>,
30    /// The URL we should call using the `status_callback_method` to send status information about the verification process to your application.
31    pub status_callback: Option<String>,
32    /// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST`, and the default is `POST`.
33    pub status_callback_method: Option<String>
34}
35
36
37/// struct for typed errors of method [`create_validation_request`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum CreateValidationRequestError {
41    UnknownValue(serde_json::Value),
42}
43
44
45/// 
46pub async fn create_validation_request(configuration: &configuration::Configuration, params: CreateValidationRequestParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodValidationRequest, Error<CreateValidationRequestError>> {
47    let local_var_configuration = configuration;
48
49    // unbox the parameters
50    let account_sid = params.account_sid;
51    let phone_number = params.phone_number;
52    let friendly_name = params.friendly_name;
53    let call_delay = params.call_delay;
54    let extension = params.extension;
55    let status_callback = params.status_callback;
56    let status_callback_method = params.status_callback_method;
57
58
59    let local_var_client = &local_var_configuration.client;
60
61    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
62    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
63
64    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
65        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
66    }
67    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
68        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
69    };
70    let mut local_var_form_params = std::collections::HashMap::new();
71    local_var_form_params.insert("PhoneNumber", phone_number.to_string());
72    if let Some(local_var_param_value) = friendly_name {
73        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
74    }
75    if let Some(local_var_param_value) = call_delay {
76        local_var_form_params.insert("CallDelay", local_var_param_value.to_string());
77    }
78    if let Some(local_var_param_value) = extension {
79        local_var_form_params.insert("Extension", local_var_param_value.to_string());
80    }
81    if let Some(local_var_param_value) = status_callback {
82        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
83    }
84    if let Some(local_var_param_value) = status_callback_method {
85        local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
86    }
87    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
88
89    let local_var_req = local_var_req_builder.build()?;
90    let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92    let local_var_status = local_var_resp.status();
93    let local_var_content = local_var_resp.text().await?;
94
95    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96        serde_json::from_str(&local_var_content).map_err(Error::from)
97    } else {
98        let local_var_entity: Option<CreateValidationRequestError> = serde_json::from_str(&local_var_content).ok();
99        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103