twilio_rust_openapi/apis/
api20100401_incoming_phone_number_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_incoming_phone_number`]
18#[derive(Clone, Debug)]
19pub struct CreateIncomingPhoneNumberParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
21    pub account_sid: String,
22    /// The API version to use for incoming calls made to the new phone number. The default is `2010-04-01`.
23    pub api_version: Option<String>,
24    /// A descriptive string that you created to describe the new phone number. It can be up to 64 characters long. By default, this is a formatted version of the new phone number.
25    pub friendly_name: Option<String>,
26    /// The SID of the application that should handle SMS messages sent to the new phone number. If an `sms_application_sid` is present, we ignore all of the `sms_*_url` urls and use those set on the application.
27    pub sms_application_sid: Option<String>,
28    /// The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
29    pub sms_fallback_method: Option<String>,
30    /// The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`.
31    pub sms_fallback_url: Option<String>,
32    /// The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`.
33    pub sms_method: Option<String>,
34    /// The URL we should call when the new phone number receives an incoming SMS message.
35    pub sms_url: Option<String>,
36    /// The URL we should call using the `status_callback_method` to send status information to your application.
37    pub status_callback: Option<String>,
38    /// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`.
39    pub status_callback_method: Option<String>,
40    /// The SID of the application we should use to handle calls to the new phone number. If a `voice_application_sid` is present, we ignore all of the voice urls and use only those set on the application. Setting a `voice_application_sid` will automatically delete your `trunk_sid` and vice versa.
41    pub voice_application_sid: Option<String>,
42    /// Whether to lookup the caller's name from the CNAM database and post it to your app. Can be: `true` or `false` and defaults to `false`.
43    pub voice_caller_id_lookup: Option<bool>,
44    /// The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
45    pub voice_fallback_method: Option<String>,
46    /// The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`.
47    pub voice_fallback_url: Option<String>,
48    /// The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`.
49    pub voice_method: Option<String>,
50    /// The URL that we should call to answer a call to the new phone number. The `voice_url` will not be called if a `voice_application_sid` or a `trunk_sid` is set.
51    pub voice_url: Option<String>,
52    pub emergency_status: Option<String>,
53    /// The SID of the emergency address configuration to use for emergency calling from the new phone number.
54    pub emergency_address_sid: Option<String>,
55    /// The SID of the Trunk we should use to handle calls to the new phone number. If a `trunk_sid` is present, we ignore all of the voice urls and voice applications and use only those set on the Trunk. Setting a `trunk_sid` will automatically delete your `voice_application_sid` and vice versa.
56    pub trunk_sid: Option<String>,
57    /// The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations.
58    pub identity_sid: Option<String>,
59    /// The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations.
60    pub address_sid: Option<String>,
61    pub voice_receive_mode: Option<String>,
62    /// The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations.
63    pub bundle_sid: Option<String>,
64    /// The phone number to purchase specified in [E.164](https://www.twilio.com/docs/glossary/what-e164) format.  E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234.
65    pub phone_number: Option<String>,
66    /// The desired area code for your new incoming phone number. Can be any three-digit, US or Canada area code. We will provision an available phone number within this area code for you. **You must provide an `area_code` or a `phone_number`.** (US and Canada only).
67    pub area_code: Option<String>
68}
69
70/// struct for passing parameters to the method [`delete_incoming_phone_number`]
71#[derive(Clone, Debug)]
72pub struct DeleteIncomingPhoneNumberParams {
73    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resources to delete.
74    pub account_sid: String,
75    /// The Twilio-provided string that uniquely identifies the IncomingPhoneNumber resource to delete.
76    pub sid: String
77}
78
79/// struct for passing parameters to the method [`fetch_incoming_phone_number`]
80#[derive(Clone, Debug)]
81pub struct FetchIncomingPhoneNumberParams {
82    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to fetch.
83    pub account_sid: String,
84    /// The Twilio-provided string that uniquely identifies the IncomingPhoneNumber resource to fetch.
85    pub sid: String
86}
87
88/// struct for passing parameters to the method [`list_incoming_phone_number`]
89#[derive(Clone, Debug)]
90pub struct ListIncomingPhoneNumberParams {
91    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resources to read.
92    pub account_sid: String,
93    /// Whether to include phone numbers new to the Twilio platform. Can be: `true` or `false` and the default is `true`.
94    pub beta: Option<bool>,
95    /// A string that identifies the IncomingPhoneNumber resources to read.
96    pub friendly_name: Option<String>,
97    /// The phone numbers of the IncomingPhoneNumber resources to read. You can specify partial numbers and use '*' as a wildcard for any digit.
98    pub phone_number: Option<String>,
99    /// Whether to include phone numbers based on their origin. Can be: `twilio` or `hosted`. By default, phone numbers of all origin are included.
100    pub origin: Option<String>,
101    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
102    pub page_size: Option<i32>,
103    /// The page index. This value is simply for client state.
104    pub page: Option<i32>,
105    /// The page token. This is provided by the API.
106    pub page_token: Option<String>
107}
108
109/// struct for passing parameters to the method [`update_incoming_phone_number`]
110#[derive(Clone, Debug)]
111pub struct UpdateIncomingPhoneNumberParams {
112    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to update.  For more information, see [Exchanging Numbers Between Subaccounts](https://www.twilio.com/docs/iam/api/subaccounts#exchanging-numbers).
113    pub account_sid: String,
114    /// The Twilio-provided string that uniquely identifies the IncomingPhoneNumber resource to update.
115    pub sid: String,
116    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to update.  For more information, see [Exchanging Numbers Between Subaccounts](https://www.twilio.com/docs/iam/api/subaccounts#exchanging-numbers).
117    pub account_sid2: Option<String>,
118    /// The API version to use for incoming calls made to the phone number. The default is `2010-04-01`.
119    pub api_version: Option<String>,
120    /// A descriptive string that you created to describe this phone number. It can be up to 64 characters long. By default, this is a formatted version of the phone number.
121    pub friendly_name: Option<String>,
122    /// The SID of the application that should handle SMS messages sent to the number. If an `sms_application_sid` is present, we ignore all of the `sms_*_url` urls and use those set on the application.
123    pub sms_application_sid: Option<String>,
124    /// The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
125    pub sms_fallback_method: Option<String>,
126    /// The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`.
127    pub sms_fallback_url: Option<String>,
128    /// The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`.
129    pub sms_method: Option<String>,
130    /// The URL we should call when the phone number receives an incoming SMS message.
131    pub sms_url: Option<String>,
132    /// The URL we should call using the `status_callback_method` to send status information to your application.
133    pub status_callback: Option<String>,
134    /// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`.
135    pub status_callback_method: Option<String>,
136    /// The SID of the application we should use to handle phone calls to the phone number. If a `voice_application_sid` is present, we ignore all of the voice urls and use only those set on the application. Setting a `voice_application_sid` will automatically delete your `trunk_sid` and vice versa.
137    pub voice_application_sid: Option<String>,
138    /// Whether to lookup the caller's name from the CNAM database and post it to your app. Can be: `true` or `false` and defaults to `false`.
139    pub voice_caller_id_lookup: Option<bool>,
140    /// The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
141    pub voice_fallback_method: Option<String>,
142    /// The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`.
143    pub voice_fallback_url: Option<String>,
144    /// The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`.
145    pub voice_method: Option<String>,
146    /// The URL that we should call to answer a call to the phone number. The `voice_url` will not be called if a `voice_application_sid` or a `trunk_sid` is set.
147    pub voice_url: Option<String>,
148    pub emergency_status: Option<String>,
149    /// The SID of the emergency address configuration to use for emergency calling from this phone number.
150    pub emergency_address_sid: Option<String>,
151    /// The SID of the Trunk we should use to handle phone calls to the phone number. If a `trunk_sid` is present, we ignore all of the voice urls and voice applications and use only those set on the Trunk. Setting a `trunk_sid` will automatically delete your `voice_application_sid` and vice versa.
152    pub trunk_sid: Option<String>,
153    pub voice_receive_mode: Option<String>,
154    /// The SID of the Identity resource that we should associate with the phone number. Some regions require an identity to meet local regulations.
155    pub identity_sid: Option<String>,
156    /// The SID of the Address resource we should associate with the phone number. Some regions require addresses to meet local regulations.
157    pub address_sid: Option<String>,
158    /// The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations.
159    pub bundle_sid: Option<String>
160}
161
162
163/// struct for typed errors of method [`create_incoming_phone_number`]
164#[derive(Debug, Clone, Serialize, Deserialize)]
165#[serde(untagged)]
166pub enum CreateIncomingPhoneNumberError {
167    UnknownValue(serde_json::Value),
168}
169
170/// struct for typed errors of method [`delete_incoming_phone_number`]
171#[derive(Debug, Clone, Serialize, Deserialize)]
172#[serde(untagged)]
173pub enum DeleteIncomingPhoneNumberError {
174    UnknownValue(serde_json::Value),
175}
176
177/// struct for typed errors of method [`fetch_incoming_phone_number`]
178#[derive(Debug, Clone, Serialize, Deserialize)]
179#[serde(untagged)]
180pub enum FetchIncomingPhoneNumberError {
181    UnknownValue(serde_json::Value),
182}
183
184/// struct for typed errors of method [`list_incoming_phone_number`]
185#[derive(Debug, Clone, Serialize, Deserialize)]
186#[serde(untagged)]
187pub enum ListIncomingPhoneNumberError {
188    UnknownValue(serde_json::Value),
189}
190
191/// struct for typed errors of method [`update_incoming_phone_number`]
192#[derive(Debug, Clone, Serialize, Deserialize)]
193#[serde(untagged)]
194pub enum UpdateIncomingPhoneNumberError {
195    UnknownValue(serde_json::Value),
196}
197
198
199/// Purchase a phone-number for the account.
200pub async fn create_incoming_phone_number(configuration: &configuration::Configuration, params: CreateIncomingPhoneNumberParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumber, Error<CreateIncomingPhoneNumberError>> {
201    let local_var_configuration = configuration;
202
203    // unbox the parameters
204    let account_sid = params.account_sid;
205    let api_version = params.api_version;
206    let friendly_name = params.friendly_name;
207    let sms_application_sid = params.sms_application_sid;
208    let sms_fallback_method = params.sms_fallback_method;
209    let sms_fallback_url = params.sms_fallback_url;
210    let sms_method = params.sms_method;
211    let sms_url = params.sms_url;
212    let status_callback = params.status_callback;
213    let status_callback_method = params.status_callback_method;
214    let voice_application_sid = params.voice_application_sid;
215    let voice_caller_id_lookup = params.voice_caller_id_lookup;
216    let voice_fallback_method = params.voice_fallback_method;
217    let voice_fallback_url = params.voice_fallback_url;
218    let voice_method = params.voice_method;
219    let voice_url = params.voice_url;
220    let emergency_status = params.emergency_status;
221    let emergency_address_sid = params.emergency_address_sid;
222    let trunk_sid = params.trunk_sid;
223    let identity_sid = params.identity_sid;
224    let address_sid = params.address_sid;
225    let voice_receive_mode = params.voice_receive_mode;
226    let bundle_sid = params.bundle_sid;
227    let phone_number = params.phone_number;
228    let area_code = params.area_code;
229
230
231    let local_var_client = &local_var_configuration.client;
232
233    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
234    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
235
236    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
237        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
238    }
239    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
240        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
241    };
242    let mut local_var_form_params = std::collections::HashMap::new();
243    if let Some(local_var_param_value) = api_version {
244        local_var_form_params.insert("ApiVersion", local_var_param_value.to_string());
245    }
246    if let Some(local_var_param_value) = friendly_name {
247        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
248    }
249    if let Some(local_var_param_value) = sms_application_sid {
250        local_var_form_params.insert("SmsApplicationSid", local_var_param_value.to_string());
251    }
252    if let Some(local_var_param_value) = sms_fallback_method {
253        local_var_form_params.insert("SmsFallbackMethod", local_var_param_value.to_string());
254    }
255    if let Some(local_var_param_value) = sms_fallback_url {
256        local_var_form_params.insert("SmsFallbackUrl", local_var_param_value.to_string());
257    }
258    if let Some(local_var_param_value) = sms_method {
259        local_var_form_params.insert("SmsMethod", local_var_param_value.to_string());
260    }
261    if let Some(local_var_param_value) = sms_url {
262        local_var_form_params.insert("SmsUrl", local_var_param_value.to_string());
263    }
264    if let Some(local_var_param_value) = status_callback {
265        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
266    }
267    if let Some(local_var_param_value) = status_callback_method {
268        local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
269    }
270    if let Some(local_var_param_value) = voice_application_sid {
271        local_var_form_params.insert("VoiceApplicationSid", local_var_param_value.to_string());
272    }
273    if let Some(local_var_param_value) = voice_caller_id_lookup {
274        local_var_form_params.insert("VoiceCallerIdLookup", local_var_param_value.to_string());
275    }
276    if let Some(local_var_param_value) = voice_fallback_method {
277        local_var_form_params.insert("VoiceFallbackMethod", local_var_param_value.to_string());
278    }
279    if let Some(local_var_param_value) = voice_fallback_url {
280        local_var_form_params.insert("VoiceFallbackUrl", local_var_param_value.to_string());
281    }
282    if let Some(local_var_param_value) = voice_method {
283        local_var_form_params.insert("VoiceMethod", local_var_param_value.to_string());
284    }
285    if let Some(local_var_param_value) = voice_url {
286        local_var_form_params.insert("VoiceUrl", local_var_param_value.to_string());
287    }
288    if let Some(local_var_param_value) = emergency_status {
289        local_var_form_params.insert("EmergencyStatus", local_var_param_value.to_string());
290    }
291    if let Some(local_var_param_value) = emergency_address_sid {
292        local_var_form_params.insert("EmergencyAddressSid", local_var_param_value.to_string());
293    }
294    if let Some(local_var_param_value) = trunk_sid {
295        local_var_form_params.insert("TrunkSid", local_var_param_value.to_string());
296    }
297    if let Some(local_var_param_value) = identity_sid {
298        local_var_form_params.insert("IdentitySid", local_var_param_value.to_string());
299    }
300    if let Some(local_var_param_value) = address_sid {
301        local_var_form_params.insert("AddressSid", local_var_param_value.to_string());
302    }
303    if let Some(local_var_param_value) = voice_receive_mode {
304        local_var_form_params.insert("VoiceReceiveMode", local_var_param_value.to_string());
305    }
306    if let Some(local_var_param_value) = bundle_sid {
307        local_var_form_params.insert("BundleSid", local_var_param_value.to_string());
308    }
309    if let Some(local_var_param_value) = phone_number {
310        local_var_form_params.insert("PhoneNumber", local_var_param_value.to_string());
311    }
312    if let Some(local_var_param_value) = area_code {
313        local_var_form_params.insert("AreaCode", local_var_param_value.to_string());
314    }
315    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
316
317    let local_var_req = local_var_req_builder.build()?;
318    let local_var_resp = local_var_client.execute(local_var_req).await?;
319
320    let local_var_status = local_var_resp.status();
321    let local_var_content = local_var_resp.text().await?;
322
323    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
324        serde_json::from_str(&local_var_content).map_err(Error::from)
325    } else {
326        let local_var_entity: Option<CreateIncomingPhoneNumberError> = serde_json::from_str(&local_var_content).ok();
327        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
328        Err(Error::ResponseError(local_var_error))
329    }
330}
331
332/// Delete a phone-numbers belonging to the account used to make the request.
333pub async fn delete_incoming_phone_number(configuration: &configuration::Configuration, params: DeleteIncomingPhoneNumberParams) -> Result<(), Error<DeleteIncomingPhoneNumberError>> {
334    let local_var_configuration = configuration;
335
336    // unbox the parameters
337    let account_sid = params.account_sid;
338    let sid = params.sid;
339
340
341    let local_var_client = &local_var_configuration.client;
342
343    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
344    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
345
346    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
347        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
348    }
349    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
350        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
351    };
352
353    let local_var_req = local_var_req_builder.build()?;
354    let local_var_resp = local_var_client.execute(local_var_req).await?;
355
356    let local_var_status = local_var_resp.status();
357    let local_var_content = local_var_resp.text().await?;
358
359    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360        Ok(())
361    } else {
362        let local_var_entity: Option<DeleteIncomingPhoneNumberError> = serde_json::from_str(&local_var_content).ok();
363        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
364        Err(Error::ResponseError(local_var_error))
365    }
366}
367
368/// Fetch an incoming-phone-number belonging to the account used to make the request.
369pub async fn fetch_incoming_phone_number(configuration: &configuration::Configuration, params: FetchIncomingPhoneNumberParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumber, Error<FetchIncomingPhoneNumberError>> {
370    let local_var_configuration = configuration;
371
372    // unbox the parameters
373    let account_sid = params.account_sid;
374    let sid = params.sid;
375
376
377    let local_var_client = &local_var_configuration.client;
378
379    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
380    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
381
382    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
383        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
384    }
385    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
386        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
387    };
388
389    let local_var_req = local_var_req_builder.build()?;
390    let local_var_resp = local_var_client.execute(local_var_req).await?;
391
392    let local_var_status = local_var_resp.status();
393    let local_var_content = local_var_resp.text().await?;
394
395    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
396        serde_json::from_str(&local_var_content).map_err(Error::from)
397    } else {
398        let local_var_entity: Option<FetchIncomingPhoneNumberError> = serde_json::from_str(&local_var_content).ok();
399        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
400        Err(Error::ResponseError(local_var_error))
401    }
402}
403
404/// Retrieve a list of incoming-phone-numbers belonging to the account used to make the request.
405pub async fn list_incoming_phone_number(configuration: &configuration::Configuration, params: ListIncomingPhoneNumberParams) -> Result<models::ListIncomingPhoneNumberResponse, Error<ListIncomingPhoneNumberError>> {
406    let local_var_configuration = configuration;
407
408    // unbox the parameters
409    let account_sid = params.account_sid;
410    let beta = params.beta;
411    let friendly_name = params.friendly_name;
412    let phone_number = params.phone_number;
413    let origin = params.origin;
414    let page_size = params.page_size;
415    let page = params.page;
416    let page_token = params.page_token;
417
418
419    let local_var_client = &local_var_configuration.client;
420
421    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
422    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
423
424    if let Some(ref local_var_str) = beta {
425        local_var_req_builder = local_var_req_builder.query(&[("Beta", &local_var_str.to_string())]);
426    }
427    if let Some(ref local_var_str) = friendly_name {
428        local_var_req_builder = local_var_req_builder.query(&[("FriendlyName", &local_var_str.to_string())]);
429    }
430    if let Some(ref local_var_str) = phone_number {
431        local_var_req_builder = local_var_req_builder.query(&[("PhoneNumber", &local_var_str.to_string())]);
432    }
433    if let Some(ref local_var_str) = origin {
434        local_var_req_builder = local_var_req_builder.query(&[("Origin", &local_var_str.to_string())]);
435    }
436    if let Some(ref local_var_str) = page_size {
437        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
438    }
439    if let Some(ref local_var_str) = page {
440        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
441    }
442    if let Some(ref local_var_str) = page_token {
443        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
444    }
445    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
446        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
447    }
448    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
449        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
450    };
451
452    let local_var_req = local_var_req_builder.build()?;
453    let local_var_resp = local_var_client.execute(local_var_req).await?;
454
455    let local_var_status = local_var_resp.status();
456    let local_var_content = local_var_resp.text().await?;
457
458    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
459        serde_json::from_str(&local_var_content).map_err(Error::from)
460    } else {
461        let local_var_entity: Option<ListIncomingPhoneNumberError> = serde_json::from_str(&local_var_content).ok();
462        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
463        Err(Error::ResponseError(local_var_error))
464    }
465}
466
467/// Update an incoming-phone-number instance.
468pub async fn update_incoming_phone_number(configuration: &configuration::Configuration, params: UpdateIncomingPhoneNumberParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumber, Error<UpdateIncomingPhoneNumberError>> {
469    let local_var_configuration = configuration;
470
471    // unbox the parameters
472    let account_sid = params.account_sid;
473    let sid = params.sid;
474    let account_sid2 = params.account_sid2;
475    let api_version = params.api_version;
476    let friendly_name = params.friendly_name;
477    let sms_application_sid = params.sms_application_sid;
478    let sms_fallback_method = params.sms_fallback_method;
479    let sms_fallback_url = params.sms_fallback_url;
480    let sms_method = params.sms_method;
481    let sms_url = params.sms_url;
482    let status_callback = params.status_callback;
483    let status_callback_method = params.status_callback_method;
484    let voice_application_sid = params.voice_application_sid;
485    let voice_caller_id_lookup = params.voice_caller_id_lookup;
486    let voice_fallback_method = params.voice_fallback_method;
487    let voice_fallback_url = params.voice_fallback_url;
488    let voice_method = params.voice_method;
489    let voice_url = params.voice_url;
490    let emergency_status = params.emergency_status;
491    let emergency_address_sid = params.emergency_address_sid;
492    let trunk_sid = params.trunk_sid;
493    let voice_receive_mode = params.voice_receive_mode;
494    let identity_sid = params.identity_sid;
495    let address_sid = params.address_sid;
496    let bundle_sid = params.bundle_sid;
497
498
499    let local_var_client = &local_var_configuration.client;
500
501    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
502    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
503
504    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
505        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
506    }
507    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
508        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
509    };
510    let mut local_var_form_params = std::collections::HashMap::new();
511    if let Some(local_var_param_value) = account_sid2 {
512        local_var_form_params.insert("AccountSid", local_var_param_value.to_string());
513    }
514    if let Some(local_var_param_value) = api_version {
515        local_var_form_params.insert("ApiVersion", local_var_param_value.to_string());
516    }
517    if let Some(local_var_param_value) = friendly_name {
518        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
519    }
520    if let Some(local_var_param_value) = sms_application_sid {
521        local_var_form_params.insert("SmsApplicationSid", local_var_param_value.to_string());
522    }
523    if let Some(local_var_param_value) = sms_fallback_method {
524        local_var_form_params.insert("SmsFallbackMethod", local_var_param_value.to_string());
525    }
526    if let Some(local_var_param_value) = sms_fallback_url {
527        local_var_form_params.insert("SmsFallbackUrl", local_var_param_value.to_string());
528    }
529    if let Some(local_var_param_value) = sms_method {
530        local_var_form_params.insert("SmsMethod", local_var_param_value.to_string());
531    }
532    if let Some(local_var_param_value) = sms_url {
533        local_var_form_params.insert("SmsUrl", local_var_param_value.to_string());
534    }
535    if let Some(local_var_param_value) = status_callback {
536        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
537    }
538    if let Some(local_var_param_value) = status_callback_method {
539        local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
540    }
541    if let Some(local_var_param_value) = voice_application_sid {
542        local_var_form_params.insert("VoiceApplicationSid", local_var_param_value.to_string());
543    }
544    if let Some(local_var_param_value) = voice_caller_id_lookup {
545        local_var_form_params.insert("VoiceCallerIdLookup", local_var_param_value.to_string());
546    }
547    if let Some(local_var_param_value) = voice_fallback_method {
548        local_var_form_params.insert("VoiceFallbackMethod", local_var_param_value.to_string());
549    }
550    if let Some(local_var_param_value) = voice_fallback_url {
551        local_var_form_params.insert("VoiceFallbackUrl", local_var_param_value.to_string());
552    }
553    if let Some(local_var_param_value) = voice_method {
554        local_var_form_params.insert("VoiceMethod", local_var_param_value.to_string());
555    }
556    if let Some(local_var_param_value) = voice_url {
557        local_var_form_params.insert("VoiceUrl", local_var_param_value.to_string());
558    }
559    if let Some(local_var_param_value) = emergency_status {
560        local_var_form_params.insert("EmergencyStatus", local_var_param_value.to_string());
561    }
562    if let Some(local_var_param_value) = emergency_address_sid {
563        local_var_form_params.insert("EmergencyAddressSid", local_var_param_value.to_string());
564    }
565    if let Some(local_var_param_value) = trunk_sid {
566        local_var_form_params.insert("TrunkSid", local_var_param_value.to_string());
567    }
568    if let Some(local_var_param_value) = voice_receive_mode {
569        local_var_form_params.insert("VoiceReceiveMode", local_var_param_value.to_string());
570    }
571    if let Some(local_var_param_value) = identity_sid {
572        local_var_form_params.insert("IdentitySid", local_var_param_value.to_string());
573    }
574    if let Some(local_var_param_value) = address_sid {
575        local_var_form_params.insert("AddressSid", local_var_param_value.to_string());
576    }
577    if let Some(local_var_param_value) = bundle_sid {
578        local_var_form_params.insert("BundleSid", local_var_param_value.to_string());
579    }
580    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
581
582    let local_var_req = local_var_req_builder.build()?;
583    let local_var_resp = local_var_client.execute(local_var_req).await?;
584
585    let local_var_status = local_var_resp.status();
586    let local_var_content = local_var_resp.text().await?;
587
588    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
589        serde_json::from_str(&local_var_content).map_err(Error::from)
590    } else {
591        let local_var_entity: Option<UpdateIncomingPhoneNumberError> = serde_json::from_str(&local_var_content).ok();
592        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
593        Err(Error::ResponseError(local_var_error))
594    }
595}
596