twilio_rust_openapi/apis/
api20100401_assigned_add_on_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_assigned_add_on`]
18#[derive(Clone, Debug)]
19pub struct CreateIncomingPhoneNumberAssignedAddOnParams {
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 SID of the Phone Number to assign the Add-on.
23    pub resource_sid: String,
24    /// The SID that identifies the Add-on installation.
25    pub installed_add_on_sid: String
26}
27
28/// struct for passing parameters to the method [`delete_incoming_phone_number_assigned_add_on`]
29#[derive(Clone, Debug)]
30pub struct DeleteIncomingPhoneNumberAssignedAddOnParams {
31    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resources to delete.
32    pub account_sid: String,
33    /// The SID of the Phone Number to which the Add-on is assigned.
34    pub resource_sid: String,
35    /// The Twilio-provided string that uniquely identifies the resource to delete.
36    pub sid: String
37}
38
39/// struct for passing parameters to the method [`fetch_incoming_phone_number_assigned_add_on`]
40#[derive(Clone, Debug)]
41pub struct FetchIncomingPhoneNumberAssignedAddOnParams {
42    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resource to fetch.
43    pub account_sid: String,
44    /// The SID of the Phone Number to which the Add-on is assigned.
45    pub resource_sid: String,
46    /// The Twilio-provided string that uniquely identifies the resource to fetch.
47    pub sid: String
48}
49
50/// struct for passing parameters to the method [`list_incoming_phone_number_assigned_add_on`]
51#[derive(Clone, Debug)]
52pub struct ListIncomingPhoneNumberAssignedAddOnParams {
53    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resources to read.
54    pub account_sid: String,
55    /// The SID of the Phone Number to which the Add-on is assigned.
56    pub resource_sid: String,
57    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
58    pub page_size: Option<i32>,
59    /// The page index. This value is simply for client state.
60    pub page: Option<i32>,
61    /// The page token. This is provided by the API.
62    pub page_token: Option<String>
63}
64
65
66/// struct for typed errors of method [`create_incoming_phone_number_assigned_add_on`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum CreateIncomingPhoneNumberAssignedAddOnError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`delete_incoming_phone_number_assigned_add_on`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum DeleteIncomingPhoneNumberAssignedAddOnError {
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`fetch_incoming_phone_number_assigned_add_on`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum FetchIncomingPhoneNumberAssignedAddOnError {
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`list_incoming_phone_number_assigned_add_on`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum ListIncomingPhoneNumberAssignedAddOnError {
91    UnknownValue(serde_json::Value),
92}
93
94
95/// Assign an Add-on installation to the Number specified.
96pub async fn create_incoming_phone_number_assigned_add_on(configuration: &configuration::Configuration, params: CreateIncomingPhoneNumberAssignedAddOnParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumberPeriodIncomingPhoneNumberAssignedAddOn, Error<CreateIncomingPhoneNumberAssignedAddOnError>> {
97    let local_var_configuration = configuration;
98
99    // unbox the parameters
100    let account_sid = params.account_sid;
101    let resource_sid = params.resource_sid;
102    let installed_add_on_sid = params.installed_add_on_sid;
103
104
105    let local_var_client = &local_var_configuration.client;
106
107    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid));
108    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
109
110    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
111        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112    }
113    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
114        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
115    };
116    let mut local_var_form_params = std::collections::HashMap::new();
117    local_var_form_params.insert("InstalledAddOnSid", installed_add_on_sid.to_string());
118    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
119
120    let local_var_req = local_var_req_builder.build()?;
121    let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123    let local_var_status = local_var_resp.status();
124    let local_var_content = local_var_resp.text().await?;
125
126    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127        serde_json::from_str(&local_var_content).map_err(Error::from)
128    } else {
129        let local_var_entity: Option<CreateIncomingPhoneNumberAssignedAddOnError> = serde_json::from_str(&local_var_content).ok();
130        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134
135/// Remove the assignment of an Add-on installation from the Number specified.
136pub async fn delete_incoming_phone_number_assigned_add_on(configuration: &configuration::Configuration, params: DeleteIncomingPhoneNumberAssignedAddOnParams) -> Result<(), Error<DeleteIncomingPhoneNumberAssignedAddOnError>> {
137    let local_var_configuration = configuration;
138
139    // unbox the parameters
140    let account_sid = params.account_sid;
141    let resource_sid = params.resource_sid;
142    let sid = params.sid;
143
144
145    let local_var_client = &local_var_configuration.client;
146
147    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid), Sid=crate::apis::urlencode(sid));
148    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
149
150    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
151        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
152    }
153    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
154        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
155    };
156
157    let local_var_req = local_var_req_builder.build()?;
158    let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160    let local_var_status = local_var_resp.status();
161    let local_var_content = local_var_resp.text().await?;
162
163    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
164        Ok(())
165    } else {
166        let local_var_entity: Option<DeleteIncomingPhoneNumberAssignedAddOnError> = serde_json::from_str(&local_var_content).ok();
167        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
168        Err(Error::ResponseError(local_var_error))
169    }
170}
171
172/// Fetch an instance of an Add-on installation currently assigned to this Number.
173pub async fn fetch_incoming_phone_number_assigned_add_on(configuration: &configuration::Configuration, params: FetchIncomingPhoneNumberAssignedAddOnParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumberPeriodIncomingPhoneNumberAssignedAddOn, Error<FetchIncomingPhoneNumberAssignedAddOnError>> {
174    let local_var_configuration = configuration;
175
176    // unbox the parameters
177    let account_sid = params.account_sid;
178    let resource_sid = params.resource_sid;
179    let sid = params.sid;
180
181
182    let local_var_client = &local_var_configuration.client;
183
184    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid), Sid=crate::apis::urlencode(sid));
185    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
186
187    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189    }
190    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
191        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<FetchIncomingPhoneNumberAssignedAddOnError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209/// Retrieve a list of Add-on installations currently assigned to this Number.
210pub async fn list_incoming_phone_number_assigned_add_on(configuration: &configuration::Configuration, params: ListIncomingPhoneNumberAssignedAddOnParams) -> Result<models::ListIncomingPhoneNumberAssignedAddOnResponse, Error<ListIncomingPhoneNumberAssignedAddOnError>> {
211    let local_var_configuration = configuration;
212
213    // unbox the parameters
214    let account_sid = params.account_sid;
215    let resource_sid = params.resource_sid;
216    let page_size = params.page_size;
217    let page = params.page;
218    let page_token = params.page_token;
219
220
221    let local_var_client = &local_var_configuration.client;
222
223    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid));
224    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
225
226    if let Some(ref local_var_str) = page_size {
227        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
228    }
229    if let Some(ref local_var_str) = page {
230        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
231    }
232    if let Some(ref local_var_str) = page_token {
233        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
234    }
235    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
236        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237    }
238    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
239        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
240    };
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<ListIncomingPhoneNumberAssignedAddOnError> = serde_json::from_str(&local_var_content).ok();
252        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253        Err(Error::ResponseError(local_var_error))
254    }
255}
256