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