twilio_rust_openapi/apis/
api20100401_address_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_address`]
18#[derive(Clone, Debug)]
19pub struct CreateAddressParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will be responsible for the new Address resource.
21    pub account_sid: String,
22    /// The name to associate with the new address.
23    pub customer_name: String,
24    /// The number and street address of the new address.
25    pub street: String,
26    /// The city of the new address.
27    pub city: String,
28    /// The state or region of the new address.
29    pub region: String,
30    /// The postal code of the new address.
31    pub postal_code: String,
32    /// The ISO country code of the new address.
33    pub iso_country: String,
34    /// A descriptive string that you create to describe the new address. It can be up to 64 characters long.
35    pub friendly_name: Option<String>,
36    /// Whether to enable emergency calling on the new address. Can be: `true` or `false`.
37    pub emergency_enabled: Option<bool>,
38    /// Whether we should automatically correct the address. Can be: `true` or `false` and the default is `true`. If empty or `true`, we will correct the address you provide if necessary. If `false`, we won't alter the address you provide.
39    pub auto_correct_address: Option<bool>,
40    /// The additional number and street address of the address.
41    pub street_secondary: Option<String>
42}
43
44/// struct for passing parameters to the method [`delete_address`]
45#[derive(Clone, Debug)]
46pub struct DeleteAddressParams {
47    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is responsible for the Address resource to delete.
48    pub account_sid: String,
49    /// The Twilio-provided string that uniquely identifies the Address resource to delete.
50    pub sid: String
51}
52
53/// struct for passing parameters to the method [`fetch_address`]
54#[derive(Clone, Debug)]
55pub struct FetchAddressParams {
56    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is responsible for the Address resource to fetch.
57    pub account_sid: String,
58    /// The Twilio-provided string that uniquely identifies the Address resource to fetch.
59    pub sid: String
60}
61
62/// struct for passing parameters to the method [`list_address`]
63#[derive(Clone, Debug)]
64pub struct ListAddressParams {
65    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is responsible for the Address resource to read.
66    pub account_sid: String,
67    /// The `customer_name` of the Address resources to read.
68    pub customer_name: Option<String>,
69    /// The string that identifies the Address resources to read.
70    pub friendly_name: Option<String>,
71    /// The ISO country code of the Address resources to read.
72    pub iso_country: Option<String>,
73    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
74    pub page_size: Option<i32>,
75    /// The page index. This value is simply for client state.
76    pub page: Option<i32>,
77    /// The page token. This is provided by the API.
78    pub page_token: Option<String>
79}
80
81/// struct for passing parameters to the method [`update_address`]
82#[derive(Clone, Debug)]
83pub struct UpdateAddressParams {
84    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is responsible for the Address resource to update.
85    pub account_sid: String,
86    /// The Twilio-provided string that uniquely identifies the Address resource to update.
87    pub sid: String,
88    /// A descriptive string that you create to describe the address. It can be up to 64 characters long.
89    pub friendly_name: Option<String>,
90    /// The name to associate with the address.
91    pub customer_name: Option<String>,
92    /// The number and street address of the address.
93    pub street: Option<String>,
94    /// The city of the address.
95    pub city: Option<String>,
96    /// The state or region of the address.
97    pub region: Option<String>,
98    /// The postal code of the address.
99    pub postal_code: Option<String>,
100    /// Whether to enable emergency calling on the address. Can be: `true` or `false`.
101    pub emergency_enabled: Option<bool>,
102    /// Whether we should automatically correct the address. Can be: `true` or `false` and the default is `true`. If empty or `true`, we will correct the address you provide if necessary. If `false`, we won't alter the address you provide.
103    pub auto_correct_address: Option<bool>,
104    /// The additional number and street address of the address.
105    pub street_secondary: Option<String>
106}
107
108
109/// struct for typed errors of method [`create_address`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum CreateAddressError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`delete_address`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum DeleteAddressError {
120    UnknownValue(serde_json::Value),
121}
122
123/// struct for typed errors of method [`fetch_address`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum FetchAddressError {
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`list_address`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum ListAddressError {
134    UnknownValue(serde_json::Value),
135}
136
137/// struct for typed errors of method [`update_address`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum UpdateAddressError {
141    UnknownValue(serde_json::Value),
142}
143
144
145/// 
146pub async fn create_address(configuration: &configuration::Configuration, params: CreateAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodAddress, Error<CreateAddressError>> {
147    let local_var_configuration = configuration;
148
149    // unbox the parameters
150    let account_sid = params.account_sid;
151    let customer_name = params.customer_name;
152    let street = params.street;
153    let city = params.city;
154    let region = params.region;
155    let postal_code = params.postal_code;
156    let iso_country = params.iso_country;
157    let friendly_name = params.friendly_name;
158    let emergency_enabled = params.emergency_enabled;
159    let auto_correct_address = params.auto_correct_address;
160    let street_secondary = params.street_secondary;
161
162
163    let local_var_client = &local_var_configuration.client;
164
165    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Addresses.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
166    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
167
168    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
169        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
170    }
171    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
172        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
173    };
174    let mut local_var_form_params = std::collections::HashMap::new();
175    local_var_form_params.insert("CustomerName", customer_name.to_string());
176    local_var_form_params.insert("Street", street.to_string());
177    local_var_form_params.insert("City", city.to_string());
178    local_var_form_params.insert("Region", region.to_string());
179    local_var_form_params.insert("PostalCode", postal_code.to_string());
180    local_var_form_params.insert("IsoCountry", iso_country.to_string());
181    if let Some(local_var_param_value) = friendly_name {
182        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
183    }
184    if let Some(local_var_param_value) = emergency_enabled {
185        local_var_form_params.insert("EmergencyEnabled", local_var_param_value.to_string());
186    }
187    if let Some(local_var_param_value) = auto_correct_address {
188        local_var_form_params.insert("AutoCorrectAddress", local_var_param_value.to_string());
189    }
190    if let Some(local_var_param_value) = street_secondary {
191        local_var_form_params.insert("StreetSecondary", local_var_param_value.to_string());
192    }
193    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
194
195    let local_var_req = local_var_req_builder.build()?;
196    let local_var_resp = local_var_client.execute(local_var_req).await?;
197
198    let local_var_status = local_var_resp.status();
199    let local_var_content = local_var_resp.text().await?;
200
201    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
202        serde_json::from_str(&local_var_content).map_err(Error::from)
203    } else {
204        let local_var_entity: Option<CreateAddressError> = serde_json::from_str(&local_var_content).ok();
205        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
206        Err(Error::ResponseError(local_var_error))
207    }
208}
209
210/// 
211pub async fn delete_address(configuration: &configuration::Configuration, params: DeleteAddressParams) -> Result<(), Error<DeleteAddressError>> {
212    let local_var_configuration = configuration;
213
214    // unbox the parameters
215    let account_sid = params.account_sid;
216    let sid = params.sid;
217
218
219    let local_var_client = &local_var_configuration.client;
220
221    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
222    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
223
224    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
225        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
228        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
229    };
230
231    let local_var_req = local_var_req_builder.build()?;
232    let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234    let local_var_status = local_var_resp.status();
235    let local_var_content = local_var_resp.text().await?;
236
237    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238        Ok(())
239    } else {
240        let local_var_entity: Option<DeleteAddressError> = serde_json::from_str(&local_var_content).ok();
241        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
242        Err(Error::ResponseError(local_var_error))
243    }
244}
245
246/// 
247pub async fn fetch_address(configuration: &configuration::Configuration, params: FetchAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodAddress, Error<FetchAddressError>> {
248    let local_var_configuration = configuration;
249
250    // unbox the parameters
251    let account_sid = params.account_sid;
252    let sid = params.sid;
253
254
255    let local_var_client = &local_var_configuration.client;
256
257    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
258    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
259
260    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
261        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
262    }
263    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
264        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
265    };
266
267    let local_var_req = local_var_req_builder.build()?;
268    let local_var_resp = local_var_client.execute(local_var_req).await?;
269
270    let local_var_status = local_var_resp.status();
271    let local_var_content = local_var_resp.text().await?;
272
273    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
274        serde_json::from_str(&local_var_content).map_err(Error::from)
275    } else {
276        let local_var_entity: Option<FetchAddressError> = serde_json::from_str(&local_var_content).ok();
277        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
278        Err(Error::ResponseError(local_var_error))
279    }
280}
281
282/// 
283pub async fn list_address(configuration: &configuration::Configuration, params: ListAddressParams) -> Result<models::ListAddressResponse, Error<ListAddressError>> {
284    let local_var_configuration = configuration;
285
286    // unbox the parameters
287    let account_sid = params.account_sid;
288    let customer_name = params.customer_name;
289    let friendly_name = params.friendly_name;
290    let iso_country = params.iso_country;
291    let page_size = params.page_size;
292    let page = params.page;
293    let page_token = params.page_token;
294
295
296    let local_var_client = &local_var_configuration.client;
297
298    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Addresses.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
299    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
300
301    if let Some(ref local_var_str) = customer_name {
302        local_var_req_builder = local_var_req_builder.query(&[("CustomerName", &local_var_str.to_string())]);
303    }
304    if let Some(ref local_var_str) = friendly_name {
305        local_var_req_builder = local_var_req_builder.query(&[("FriendlyName", &local_var_str.to_string())]);
306    }
307    if let Some(ref local_var_str) = iso_country {
308        local_var_req_builder = local_var_req_builder.query(&[("IsoCountry", &local_var_str.to_string())]);
309    }
310    if let Some(ref local_var_str) = page_size {
311        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
312    }
313    if let Some(ref local_var_str) = page {
314        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
315    }
316    if let Some(ref local_var_str) = page_token {
317        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
318    }
319    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
320        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
321    }
322    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
323        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
324    };
325
326    let local_var_req = local_var_req_builder.build()?;
327    let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329    let local_var_status = local_var_resp.status();
330    let local_var_content = local_var_resp.text().await?;
331
332    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
333        serde_json::from_str(&local_var_content).map_err(Error::from)
334    } else {
335        let local_var_entity: Option<ListAddressError> = serde_json::from_str(&local_var_content).ok();
336        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
337        Err(Error::ResponseError(local_var_error))
338    }
339}
340
341/// 
342pub async fn update_address(configuration: &configuration::Configuration, params: UpdateAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodAddress, Error<UpdateAddressError>> {
343    let local_var_configuration = configuration;
344
345    // unbox the parameters
346    let account_sid = params.account_sid;
347    let sid = params.sid;
348    let friendly_name = params.friendly_name;
349    let customer_name = params.customer_name;
350    let street = params.street;
351    let city = params.city;
352    let region = params.region;
353    let postal_code = params.postal_code;
354    let emergency_enabled = params.emergency_enabled;
355    let auto_correct_address = params.auto_correct_address;
356    let street_secondary = params.street_secondary;
357
358
359    let local_var_client = &local_var_configuration.client;
360
361    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
362    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
363
364    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
365        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
366    }
367    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
368        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
369    };
370    let mut local_var_form_params = std::collections::HashMap::new();
371    if let Some(local_var_param_value) = friendly_name {
372        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
373    }
374    if let Some(local_var_param_value) = customer_name {
375        local_var_form_params.insert("CustomerName", local_var_param_value.to_string());
376    }
377    if let Some(local_var_param_value) = street {
378        local_var_form_params.insert("Street", local_var_param_value.to_string());
379    }
380    if let Some(local_var_param_value) = city {
381        local_var_form_params.insert("City", local_var_param_value.to_string());
382    }
383    if let Some(local_var_param_value) = region {
384        local_var_form_params.insert("Region", local_var_param_value.to_string());
385    }
386    if let Some(local_var_param_value) = postal_code {
387        local_var_form_params.insert("PostalCode", local_var_param_value.to_string());
388    }
389    if let Some(local_var_param_value) = emergency_enabled {
390        local_var_form_params.insert("EmergencyEnabled", local_var_param_value.to_string());
391    }
392    if let Some(local_var_param_value) = auto_correct_address {
393        local_var_form_params.insert("AutoCorrectAddress", local_var_param_value.to_string());
394    }
395    if let Some(local_var_param_value) = street_secondary {
396        local_var_form_params.insert("StreetSecondary", local_var_param_value.to_string());
397    }
398    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
399
400    let local_var_req = local_var_req_builder.build()?;
401    let local_var_resp = local_var_client.execute(local_var_req).await?;
402
403    let local_var_status = local_var_resp.status();
404    let local_var_content = local_var_resp.text().await?;
405
406    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
407        serde_json::from_str(&local_var_content).map_err(Error::from)
408    } else {
409        let local_var_entity: Option<UpdateAddressError> = serde_json::from_str(&local_var_content).ok();
410        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
411        Err(Error::ResponseError(local_var_error))
412    }
413}
414