twilio_rust_openapi/apis/
api20100401_assigned_add_on_extension_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_incoming_phone_number_assigned_add_on_extension`]
18#[derive(Clone, Debug)]
19pub struct FetchIncomingPhoneNumberAssignedAddOnExtensionParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resource to fetch.
21    pub account_sid: String,
22    /// The SID of the Phone Number to which the Add-on is assigned.
23    pub resource_sid: String,
24    /// The SID that uniquely identifies the assigned Add-on installation.
25    pub assigned_add_on_sid: String,
26    /// The Twilio-provided string that uniquely identifies the resource to fetch.
27    pub sid: String
28}
29
30/// struct for passing parameters to the method [`list_incoming_phone_number_assigned_add_on_extension`]
31#[derive(Clone, Debug)]
32pub struct ListIncomingPhoneNumberAssignedAddOnExtensionParams {
33    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resources to read.
34    pub account_sid: String,
35    /// The SID of the Phone Number to which the Add-on is assigned.
36    pub resource_sid: String,
37    /// The SID that uniquely identifies the assigned Add-on installation.
38    pub assigned_add_on_sid: String,
39    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
40    pub page_size: Option<i32>,
41    /// The page index. This value is simply for client state.
42    pub page: Option<i32>,
43    /// The page token. This is provided by the API.
44    pub page_token: Option<String>
45}
46
47
48/// struct for typed errors of method [`fetch_incoming_phone_number_assigned_add_on_extension`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum FetchIncomingPhoneNumberAssignedAddOnExtensionError {
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`list_incoming_phone_number_assigned_add_on_extension`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum ListIncomingPhoneNumberAssignedAddOnExtensionError {
59    UnknownValue(serde_json::Value),
60}
61
62
63/// Fetch an instance of an Extension for the Assigned Add-on.
64pub async fn fetch_incoming_phone_number_assigned_add_on_extension(configuration: &configuration::Configuration, params: FetchIncomingPhoneNumberAssignedAddOnExtensionParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodIncomingPhoneNumberPeriodIncomingPhoneNumberAssignedAddOnPeriodIncomingPhoneNumberAssignedAddOnExtension, Error<FetchIncomingPhoneNumberAssignedAddOnExtensionError>> {
65    let local_var_configuration = configuration;
66
67    // unbox the parameters
68    let account_sid = params.account_sid;
69    let resource_sid = params.resource_sid;
70    let assigned_add_on_sid = params.assigned_add_on_sid;
71    let sid = params.sid;
72
73
74    let local_var_client = &local_var_configuration.client;
75
76    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid), AssignedAddOnSid=crate::apis::urlencode(assigned_add_on_sid), Sid=crate::apis::urlencode(sid));
77    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
78
79    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
80        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
81    }
82    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
83        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
84    };
85
86    let local_var_req = local_var_req_builder.build()?;
87    let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89    let local_var_status = local_var_resp.status();
90    let local_var_content = local_var_resp.text().await?;
91
92    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93        serde_json::from_str(&local_var_content).map_err(Error::from)
94    } else {
95        let local_var_entity: Option<FetchIncomingPhoneNumberAssignedAddOnExtensionError> = serde_json::from_str(&local_var_content).ok();
96        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
97        Err(Error::ResponseError(local_var_error))
98    }
99}
100
101/// Retrieve a list of Extensions for the Assigned Add-on.
102pub async fn list_incoming_phone_number_assigned_add_on_extension(configuration: &configuration::Configuration, params: ListIncomingPhoneNumberAssignedAddOnExtensionParams) -> Result<models::ListIncomingPhoneNumberAssignedAddOnExtensionResponse, Error<ListIncomingPhoneNumberAssignedAddOnExtensionError>> {
103    let local_var_configuration = configuration;
104
105    // unbox the parameters
106    let account_sid = params.account_sid;
107    let resource_sid = params.resource_sid;
108    let assigned_add_on_sid = params.assigned_add_on_sid;
109    let page_size = params.page_size;
110    let page = params.page;
111    let page_token = params.page_token;
112
113
114    let local_var_client = &local_var_configuration.client;
115
116    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), ResourceSid=crate::apis::urlencode(resource_sid), AssignedAddOnSid=crate::apis::urlencode(assigned_add_on_sid));
117    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
118
119    if let Some(ref local_var_str) = page_size {
120        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
121    }
122    if let Some(ref local_var_str) = page {
123        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
124    }
125    if let Some(ref local_var_str) = page_token {
126        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
127    }
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130    }
131    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
132        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
133    };
134
135    let local_var_req = local_var_req_builder.build()?;
136    let local_var_resp = local_var_client.execute(local_var_req).await?;
137
138    let local_var_status = local_var_resp.status();
139    let local_var_content = local_var_resp.text().await?;
140
141    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
142        serde_json::from_str(&local_var_content).map_err(Error::from)
143    } else {
144        let local_var_entity: Option<ListIncomingPhoneNumberAssignedAddOnExtensionError> = serde_json::from_str(&local_var_content).ok();
145        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
146        Err(Error::ResponseError(local_var_error))
147    }
148}
149