twilio_rust_openapi/apis/
api20100401_machine_to_machine_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_available_phone_number_machine_to_machine`]
18#[derive(Clone, Debug)]
19pub struct ListAvailablePhoneNumberMachineToMachineParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) requesting the AvailablePhoneNumber resources.
21    pub account_sid: String,
22    /// The [ISO-3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code of the country from which to read phone numbers.
23    pub country_code: String,
24    /// The area code of the phone numbers to read. Applies to only phone numbers in the US and Canada.
25    pub area_code: Option<i32>,
26    /// The pattern on which to match phone numbers. Valid characters are `*`, `0-9`, `a-z`, and `A-Z`. The `*` character matches any single digit. For examples, see [Example 2](https://www.twilio.com/docs/phone-numbers/api/availablephonenumber-resource#local-get-basic-example-2) and [Example 3](https://www.twilio.com/docs/phone-numbers/api/availablephonenumber-resource#local-get-basic-example-3). If specified, this value must have at least two characters.
27    pub contains: Option<String>,
28    /// Whether the phone numbers can receive text messages. Can be: `true` or `false`.
29    pub sms_enabled: Option<bool>,
30    /// Whether the phone numbers can receive MMS messages. Can be: `true` or `false`.
31    pub mms_enabled: Option<bool>,
32    /// Whether the phone numbers can receive calls. Can be: `true` or `false`.
33    pub voice_enabled: Option<bool>,
34    /// Whether to exclude phone numbers that require an [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
35    pub exclude_all_address_required: Option<bool>,
36    /// Whether to exclude phone numbers that require a local [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
37    pub exclude_local_address_required: Option<bool>,
38    /// Whether to exclude phone numbers that require a foreign [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
39    pub exclude_foreign_address_required: Option<bool>,
40    /// Whether to read phone numbers that are new to the Twilio platform. Can be: `true` or `false` and the default is `true`.
41    pub beta: Option<bool>,
42    /// Given a phone number, find a geographically close number within `distance` miles. Distance defaults to 25 miles. Applies to only phone numbers in the US and Canada.
43    pub near_number: Option<String>,
44    /// Given a latitude/longitude pair `lat,long` find geographically close numbers within `distance` miles. Applies to only phone numbers in the US and Canada.
45    pub near_lat_long: Option<String>,
46    /// The search radius, in miles, for a `near_` query.  Can be up to `500` and the default is `25`. Applies to only phone numbers in the US and Canada.
47    pub distance: Option<i32>,
48    /// Limit results to a particular postal code. Given a phone number, search within the same postal code as that number. Applies to only phone numbers in the US and Canada.
49    pub in_postal_code: Option<String>,
50    /// Limit results to a particular region, state, or province. Given a phone number, search within the same region as that number. Applies to only phone numbers in the US and Canada.
51    pub in_region: Option<String>,
52    /// Limit results to a specific rate center, or given a phone number search within the same rate center as that number. Requires `in_lata` to be set as well. Applies to only phone numbers in the US and Canada.
53    pub in_rate_center: Option<String>,
54    /// Limit results to a specific local access and transport area ([LATA](https://en.wikipedia.org/wiki/Local_access_and_transport_area)). Given a phone number, search within the same [LATA](https://en.wikipedia.org/wiki/Local_access_and_transport_area) as that number. Applies to only phone numbers in the US and Canada.
55    pub in_lata: Option<String>,
56    /// Limit results to a particular locality or city. Given a phone number, search within the same Locality as that number.
57    pub in_locality: Option<String>,
58    /// Whether the phone numbers can receive faxes. Can be: `true` or `false`.
59    pub fax_enabled: Option<bool>,
60    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
61    pub page_size: Option<i32>,
62    /// The page index. This value is simply for client state.
63    pub page: Option<i32>,
64    /// The page token. This is provided by the API.
65    pub page_token: Option<String>
66}
67
68
69/// struct for typed errors of method [`list_available_phone_number_machine_to_machine`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListAvailablePhoneNumberMachineToMachineError {
73    UnknownValue(serde_json::Value),
74}
75
76
77/// 
78pub async fn list_available_phone_number_machine_to_machine(configuration: &configuration::Configuration, params: ListAvailablePhoneNumberMachineToMachineParams) -> Result<models::ListAvailablePhoneNumberMachineToMachineResponse, Error<ListAvailablePhoneNumberMachineToMachineError>> {
79    let local_var_configuration = configuration;
80
81    // unbox the parameters
82    let account_sid = params.account_sid;
83    let country_code = params.country_code;
84    let area_code = params.area_code;
85    let contains = params.contains;
86    let sms_enabled = params.sms_enabled;
87    let mms_enabled = params.mms_enabled;
88    let voice_enabled = params.voice_enabled;
89    let exclude_all_address_required = params.exclude_all_address_required;
90    let exclude_local_address_required = params.exclude_local_address_required;
91    let exclude_foreign_address_required = params.exclude_foreign_address_required;
92    let beta = params.beta;
93    let near_number = params.near_number;
94    let near_lat_long = params.near_lat_long;
95    let distance = params.distance;
96    let in_postal_code = params.in_postal_code;
97    let in_region = params.in_region;
98    let in_rate_center = params.in_rate_center;
99    let in_lata = params.in_lata;
100    let in_locality = params.in_locality;
101    let fax_enabled = params.fax_enabled;
102    let page_size = params.page_size;
103    let page = params.page;
104    let page_token = params.page_token;
105
106
107    let local_var_client = &local_var_configuration.client;
108
109    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CountryCode=crate::apis::urlencode(country_code));
110    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
111
112    if let Some(ref local_var_str) = area_code {
113        local_var_req_builder = local_var_req_builder.query(&[("AreaCode", &local_var_str.to_string())]);
114    }
115    if let Some(ref local_var_str) = contains {
116        local_var_req_builder = local_var_req_builder.query(&[("Contains", &local_var_str.to_string())]);
117    }
118    if let Some(ref local_var_str) = sms_enabled {
119        local_var_req_builder = local_var_req_builder.query(&[("SmsEnabled", &local_var_str.to_string())]);
120    }
121    if let Some(ref local_var_str) = mms_enabled {
122        local_var_req_builder = local_var_req_builder.query(&[("MmsEnabled", &local_var_str.to_string())]);
123    }
124    if let Some(ref local_var_str) = voice_enabled {
125        local_var_req_builder = local_var_req_builder.query(&[("VoiceEnabled", &local_var_str.to_string())]);
126    }
127    if let Some(ref local_var_str) = exclude_all_address_required {
128        local_var_req_builder = local_var_req_builder.query(&[("ExcludeAllAddressRequired", &local_var_str.to_string())]);
129    }
130    if let Some(ref local_var_str) = exclude_local_address_required {
131        local_var_req_builder = local_var_req_builder.query(&[("ExcludeLocalAddressRequired", &local_var_str.to_string())]);
132    }
133    if let Some(ref local_var_str) = exclude_foreign_address_required {
134        local_var_req_builder = local_var_req_builder.query(&[("ExcludeForeignAddressRequired", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = beta {
137        local_var_req_builder = local_var_req_builder.query(&[("Beta", &local_var_str.to_string())]);
138    }
139    if let Some(ref local_var_str) = near_number {
140        local_var_req_builder = local_var_req_builder.query(&[("NearNumber", &local_var_str.to_string())]);
141    }
142    if let Some(ref local_var_str) = near_lat_long {
143        local_var_req_builder = local_var_req_builder.query(&[("NearLatLong", &local_var_str.to_string())]);
144    }
145    if let Some(ref local_var_str) = distance {
146        local_var_req_builder = local_var_req_builder.query(&[("Distance", &local_var_str.to_string())]);
147    }
148    if let Some(ref local_var_str) = in_postal_code {
149        local_var_req_builder = local_var_req_builder.query(&[("InPostalCode", &local_var_str.to_string())]);
150    }
151    if let Some(ref local_var_str) = in_region {
152        local_var_req_builder = local_var_req_builder.query(&[("InRegion", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_str) = in_rate_center {
155        local_var_req_builder = local_var_req_builder.query(&[("InRateCenter", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_str) = in_lata {
158        local_var_req_builder = local_var_req_builder.query(&[("InLata", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_str) = in_locality {
161        local_var_req_builder = local_var_req_builder.query(&[("InLocality", &local_var_str.to_string())]);
162    }
163    if let Some(ref local_var_str) = fax_enabled {
164        local_var_req_builder = local_var_req_builder.query(&[("FaxEnabled", &local_var_str.to_string())]);
165    }
166    if let Some(ref local_var_str) = page_size {
167        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
168    }
169    if let Some(ref local_var_str) = page {
170        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
171    }
172    if let Some(ref local_var_str) = page_token {
173        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
174    }
175    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
176        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
177    }
178    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
179        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
180    };
181
182    let local_var_req = local_var_req_builder.build()?;
183    let local_var_resp = local_var_client.execute(local_var_req).await?;
184
185    let local_var_status = local_var_resp.status();
186    let local_var_content = local_var_resp.text().await?;
187
188    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189        serde_json::from_str(&local_var_content).map_err(Error::from)
190    } else {
191        let local_var_entity: Option<ListAvailablePhoneNumberMachineToMachineError> = serde_json::from_str(&local_var_content).ok();
192        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
193        Err(Error::ResponseError(local_var_error))
194    }
195}
196