twilio_rust_openapi/apis/
api20100401_short_code_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_short_code`]
18#[derive(Clone, Debug)]
19pub struct FetchShortCodeParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ShortCode resource(s) to fetch.
21    pub account_sid: String,
22    /// The Twilio-provided string that uniquely identifies the ShortCode resource to fetch
23    pub sid: String
24}
25
26/// struct for passing parameters to the method [`list_short_code`]
27#[derive(Clone, Debug)]
28pub struct ListShortCodeParams {
29    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ShortCode resource(s) to read.
30    pub account_sid: String,
31    /// The string that identifies the ShortCode resources to read.
32    pub friendly_name: Option<String>,
33    /// Only show the ShortCode resources that match this pattern. You can specify partial numbers and use '*' as a wildcard for any digit.
34    pub short_code: Option<String>,
35    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
36    pub page_size: Option<i32>,
37    /// The page index. This value is simply for client state.
38    pub page: Option<i32>,
39    /// The page token. This is provided by the API.
40    pub page_token: Option<String>
41}
42
43/// struct for passing parameters to the method [`update_short_code`]
44#[derive(Clone, Debug)]
45pub struct UpdateShortCodeParams {
46    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ShortCode resource(s) to update.
47    pub account_sid: String,
48    /// The Twilio-provided string that uniquely identifies the ShortCode resource to update
49    pub sid: String,
50    /// A descriptive string that you created to describe this resource. It can be up to 64 characters long. By default, the `FriendlyName` is the short code.
51    pub friendly_name: Option<String>,
52    /// The API version to use to start a new TwiML session. Can be: `2010-04-01` or `2008-08-01`.
53    pub api_version: Option<String>,
54    /// The URL we should call when receiving an incoming SMS message to this short code.
55    pub sms_url: Option<String>,
56    /// The HTTP method we should use when calling the `sms_url`. Can be: `GET` or `POST`.
57    pub sms_method: Option<String>,
58    /// The URL that we should call if an error occurs while retrieving or executing the TwiML from `sms_url`.
59    pub sms_fallback_url: Option<String>,
60    /// The HTTP method that we should use to call the `sms_fallback_url`. Can be: `GET` or `POST`.
61    pub sms_fallback_method: Option<String>
62}
63
64
65/// struct for typed errors of method [`fetch_short_code`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum FetchShortCodeError {
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`list_short_code`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum ListShortCodeError {
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`update_short_code`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum UpdateShortCodeError {
83    UnknownValue(serde_json::Value),
84}
85
86
87/// Fetch an instance of a short code
88pub async fn fetch_short_code(configuration: &configuration::Configuration, params: FetchShortCodeParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodShortCode, Error<FetchShortCodeError>> {
89    let local_var_configuration = configuration;
90
91    // unbox the parameters
92    let account_sid = params.account_sid;
93    let sid = params.sid;
94
95
96    let local_var_client = &local_var_configuration.client;
97
98    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
99    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
100
101    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
105        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
106    };
107
108    let local_var_req = local_var_req_builder.build()?;
109    let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        serde_json::from_str(&local_var_content).map_err(Error::from)
116    } else {
117        let local_var_entity: Option<FetchShortCodeError> = serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119        Err(Error::ResponseError(local_var_error))
120    }
121}
122
123/// Retrieve a list of short-codes belonging to the account used to make the request
124pub async fn list_short_code(configuration: &configuration::Configuration, params: ListShortCodeParams) -> Result<models::ListShortCodeResponse, Error<ListShortCodeError>> {
125    let local_var_configuration = configuration;
126
127    // unbox the parameters
128    let account_sid = params.account_sid;
129    let friendly_name = params.friendly_name;
130    let short_code = params.short_code;
131    let page_size = params.page_size;
132    let page = params.page;
133    let page_token = params.page_token;
134
135
136    let local_var_client = &local_var_configuration.client;
137
138    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
139    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
140
141    if let Some(ref local_var_str) = friendly_name {
142        local_var_req_builder = local_var_req_builder.query(&[("FriendlyName", &local_var_str.to_string())]);
143    }
144    if let Some(ref local_var_str) = short_code {
145        local_var_req_builder = local_var_req_builder.query(&[("ShortCode", &local_var_str.to_string())]);
146    }
147    if let Some(ref local_var_str) = page_size {
148        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
149    }
150    if let Some(ref local_var_str) = page {
151        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
152    }
153    if let Some(ref local_var_str) = page_token {
154        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
155    }
156    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
157        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158    }
159    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
160        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
161    };
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    let local_var_status = local_var_resp.status();
167    let local_var_content = local_var_resp.text().await?;
168
169    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
170        serde_json::from_str(&local_var_content).map_err(Error::from)
171    } else {
172        let local_var_entity: Option<ListShortCodeError> = serde_json::from_str(&local_var_content).ok();
173        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
174        Err(Error::ResponseError(local_var_error))
175    }
176}
177
178/// Update a short code with the following parameters
179pub async fn update_short_code(configuration: &configuration::Configuration, params: UpdateShortCodeParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodShortCode, Error<UpdateShortCodeError>> {
180    let local_var_configuration = configuration;
181
182    // unbox the parameters
183    let account_sid = params.account_sid;
184    let sid = params.sid;
185    let friendly_name = params.friendly_name;
186    let api_version = params.api_version;
187    let sms_url = params.sms_url;
188    let sms_method = params.sms_method;
189    let sms_fallback_url = params.sms_fallback_url;
190    let sms_fallback_method = params.sms_fallback_method;
191
192
193    let local_var_client = &local_var_configuration.client;
194
195    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
196    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
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    let mut local_var_form_params = std::collections::HashMap::new();
205    if let Some(local_var_param_value) = friendly_name {
206        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
207    }
208    if let Some(local_var_param_value) = api_version {
209        local_var_form_params.insert("ApiVersion", local_var_param_value.to_string());
210    }
211    if let Some(local_var_param_value) = sms_url {
212        local_var_form_params.insert("SmsUrl", local_var_param_value.to_string());
213    }
214    if let Some(local_var_param_value) = sms_method {
215        local_var_form_params.insert("SmsMethod", local_var_param_value.to_string());
216    }
217    if let Some(local_var_param_value) = sms_fallback_url {
218        local_var_form_params.insert("SmsFallbackUrl", local_var_param_value.to_string());
219    }
220    if let Some(local_var_param_value) = sms_fallback_method {
221        local_var_form_params.insert("SmsFallbackMethod", local_var_param_value.to_string());
222    }
223    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
224
225    let local_var_req = local_var_req_builder.build()?;
226    let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228    let local_var_status = local_var_resp.status();
229    let local_var_content = local_var_resp.text().await?;
230
231    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
232        serde_json::from_str(&local_var_content).map_err(Error::from)
233    } else {
234        let local_var_entity: Option<UpdateShortCodeError> = serde_json::from_str(&local_var_content).ok();
235        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
236        Err(Error::ResponseError(local_var_error))
237    }
238}
239