twilio_rust_openapi/apis/
api20100401_available_phone_number_country_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 [`fetch_available_phone_number_country`]
18#[derive(Clone, Debug)]
19pub struct FetchAvailablePhoneNumberCountryParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) requesting the available phone number Country resource.
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 to fetch available phone number information about.
23    pub country_code: String
24}
25
26/// struct for passing parameters to the method [`list_available_phone_number_country`]
27#[derive(Clone, Debug)]
28pub struct ListAvailablePhoneNumberCountryParams {
29    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) requesting the available phone number Country resources.
30    pub account_sid: String,
31    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
32    pub page_size: Option<i32>,
33    /// The page index. This value is simply for client state.
34    pub page: Option<i32>,
35    /// The page token. This is provided by the API.
36    pub page_token: Option<String>
37}
38
39
40/// struct for typed errors of method [`fetch_available_phone_number_country`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum FetchAvailablePhoneNumberCountryError {
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`list_available_phone_number_country`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ListAvailablePhoneNumberCountryError {
51    UnknownValue(serde_json::Value),
52}
53
54
55/// 
56pub async fn fetch_available_phone_number_country(configuration: &configuration::Configuration, params: FetchAvailablePhoneNumberCountryParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodAvailablePhoneNumberCountry, Error<FetchAvailablePhoneNumberCountryError>> {
57    let local_var_configuration = configuration;
58
59    // unbox the parameters
60    let account_sid = params.account_sid;
61    let country_code = params.country_code;
62
63
64    let local_var_client = &local_var_configuration.client;
65
66    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CountryCode=crate::apis::urlencode(country_code));
67    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
68
69    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
71    }
72    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
73        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
74    };
75
76    let local_var_req = local_var_req_builder.build()?;
77    let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79    let local_var_status = local_var_resp.status();
80    let local_var_content = local_var_resp.text().await?;
81
82    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83        serde_json::from_str(&local_var_content).map_err(Error::from)
84    } else {
85        let local_var_entity: Option<FetchAvailablePhoneNumberCountryError> = serde_json::from_str(&local_var_content).ok();
86        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
87        Err(Error::ResponseError(local_var_error))
88    }
89}
90
91/// 
92pub async fn list_available_phone_number_country(configuration: &configuration::Configuration, params: ListAvailablePhoneNumberCountryParams) -> Result<models::ListAvailablePhoneNumberCountryResponse, Error<ListAvailablePhoneNumberCountryError>> {
93    let local_var_configuration = configuration;
94
95    // unbox the parameters
96    let account_sid = params.account_sid;
97    let page_size = params.page_size;
98    let page = params.page;
99    let page_token = params.page_token;
100
101
102    let local_var_client = &local_var_configuration.client;
103
104    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
105    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
106
107    if let Some(ref local_var_str) = page_size {
108        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
109    }
110    if let Some(ref local_var_str) = page {
111        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
112    }
113    if let Some(ref local_var_str) = page_token {
114        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
115    }
116    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
117        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118    }
119    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
120        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
121    };
122
123    let local_var_req = local_var_req_builder.build()?;
124    let local_var_resp = local_var_client.execute(local_var_req).await?;
125
126    let local_var_status = local_var_resp.status();
127    let local_var_content = local_var_resp.text().await?;
128
129    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
130        serde_json::from_str(&local_var_content).map_err(Error::from)
131    } else {
132        let local_var_entity: Option<ListAvailablePhoneNumberCountryError> = serde_json::from_str(&local_var_content).ok();
133        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
134        Err(Error::ResponseError(local_var_error))
135    }
136}
137