twilio-rust-openapi 1.0.0

This is the public Twilio REST API.
Documentation
/*
 * Twilio - Api
 *
 * This is the public Twilio REST API.
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: support@twilio.com
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};

/// struct for passing parameters to the method [`create_sip_ip_address`]
#[derive(Clone, Debug)]
pub struct CreateSipIpAddressParams {
    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
    pub account_sid: String,
    /// The IpAccessControlList Sid with which to associate the created IpAddress resource.
    pub ip_access_control_list_sid: String,
    /// A human readable descriptive text for this resource, up to 255 characters long.
    pub friendly_name: String,
    /// An IP address in dotted decimal notation from which you want to accept traffic. Any SIP requests from this IP address will be allowed by Twilio. IPv4 only supported today.
    pub ip_address: String,
    /// An integer representing the length of the CIDR prefix to use with this IP address when accepting traffic. By default the entire IP address is used.
    pub cidr_prefix_length: Option<i32>
}

/// struct for passing parameters to the method [`delete_sip_ip_address`]
#[derive(Clone, Debug)]
pub struct DeleteSipIpAddressParams {
    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
    pub account_sid: String,
    /// The IpAccessControlList Sid that identifies the IpAddress resources to delete.
    pub ip_access_control_list_sid: String,
    /// A 34 character string that uniquely identifies the resource to delete.
    pub sid: String
}

/// struct for passing parameters to the method [`fetch_sip_ip_address`]
#[derive(Clone, Debug)]
pub struct FetchSipIpAddressParams {
    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
    pub account_sid: String,
    /// The IpAccessControlList Sid that identifies the IpAddress resources to fetch.
    pub ip_access_control_list_sid: String,
    /// A 34 character string that uniquely identifies the IpAddress resource to fetch.
    pub sid: String
}

/// struct for passing parameters to the method [`list_sip_ip_address`]
#[derive(Clone, Debug)]
pub struct ListSipIpAddressParams {
    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
    pub account_sid: String,
    /// The IpAccessControlList Sid that identifies the IpAddress resources to read.
    pub ip_access_control_list_sid: String,
    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
    pub page_size: Option<i32>,
    /// The page index. This value is simply for client state.
    pub page: Option<i32>,
    /// The page token. This is provided by the API.
    pub page_token: Option<String>
}

/// struct for passing parameters to the method [`update_sip_ip_address`]
#[derive(Clone, Debug)]
pub struct UpdateSipIpAddressParams {
    /// The unique id of the [Account](https://www.twilio.com/docs/iam/api/account) responsible for this resource.
    pub account_sid: String,
    /// The IpAccessControlList Sid that identifies the IpAddress resources to update.
    pub ip_access_control_list_sid: String,
    /// A 34 character string that identifies the IpAddress resource to update.
    pub sid: String,
    /// An IP address in dotted decimal notation from which you want to accept traffic. Any SIP requests from this IP address will be allowed by Twilio. IPv4 only supported today.
    pub ip_address: Option<String>,
    /// A human readable descriptive text for this resource, up to 255 characters long.
    pub friendly_name: Option<String>,
    /// An integer representing the length of the CIDR prefix to use with this IP address when accepting traffic. By default the entire IP address is used.
    pub cidr_prefix_length: Option<i32>
}


/// struct for typed errors of method [`create_sip_ip_address`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSipIpAddressError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_sip_ip_address`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSipIpAddressError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`fetch_sip_ip_address`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FetchSipIpAddressError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_sip_ip_address`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSipIpAddressError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`update_sip_ip_address`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSipIpAddressError {
    UnknownValue(serde_json::Value),
}


/// Create a new IpAddress resource.
pub async fn create_sip_ip_address(configuration: &configuration::Configuration, params: CreateSipIpAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipIpAccessControlListPeriodSipIpAddress, Error<CreateSipIpAddressError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let account_sid = params.account_sid;
    let ip_access_control_list_sid = params.ip_access_control_list_sid;
    let friendly_name = params.friendly_name;
    let ip_address = params.ip_address;
    let cidr_prefix_length = params.cidr_prefix_length;


    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), IpAccessControlListSid=crate::apis::urlencode(ip_access_control_list_sid));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
    };
    let mut local_var_form_params = std::collections::HashMap::new();
    local_var_form_params.insert("FriendlyName", friendly_name.to_string());
    local_var_form_params.insert("IpAddress", ip_address.to_string());
    if let Some(local_var_param_value) = cidr_prefix_length {
        local_var_form_params.insert("CidrPrefixLength", local_var_param_value.to_string());
    }
    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<CreateSipIpAddressError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Delete an IpAddress resource.
pub async fn delete_sip_ip_address(configuration: &configuration::Configuration, params: DeleteSipIpAddressParams) -> Result<(), Error<DeleteSipIpAddressError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let account_sid = params.account_sid;
    let ip_access_control_list_sid = params.ip_access_control_list_sid;
    let sid = params.sid;


    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), IpAccessControlListSid=crate::apis::urlencode(ip_access_control_list_sid), Sid=crate::apis::urlencode(sid));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        Ok(())
    } else {
        let local_var_entity: Option<DeleteSipIpAddressError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Read one IpAddress resource.
pub async fn fetch_sip_ip_address(configuration: &configuration::Configuration, params: FetchSipIpAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipIpAccessControlListPeriodSipIpAddress, Error<FetchSipIpAddressError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let account_sid = params.account_sid;
    let ip_access_control_list_sid = params.ip_access_control_list_sid;
    let sid = params.sid;


    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), IpAccessControlListSid=crate::apis::urlencode(ip_access_control_list_sid), Sid=crate::apis::urlencode(sid));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FetchSipIpAddressError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Read multiple IpAddress resources.
pub async fn list_sip_ip_address(configuration: &configuration::Configuration, params: ListSipIpAddressParams) -> Result<models::ListSipIpAddressResponse, Error<ListSipIpAddressError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let account_sid = params.account_sid;
    let ip_access_control_list_sid = params.ip_access_control_list_sid;
    let page_size = params.page_size;
    let page = params.page;
    let page_token = params.page_token;


    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), IpAccessControlListSid=crate::apis::urlencode(ip_access_control_list_sid));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = page_size {
        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = page {
        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = page_token {
        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListSipIpAddressError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Update an IpAddress resource.
pub async fn update_sip_ip_address(configuration: &configuration::Configuration, params: UpdateSipIpAddressParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodSipPeriodSipIpAccessControlListPeriodSipIpAddress, Error<UpdateSipIpAddressError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let account_sid = params.account_sid;
    let ip_access_control_list_sid = params.ip_access_control_list_sid;
    let sid = params.sid;
    let ip_address = params.ip_address;
    let friendly_name = params.friendly_name;
    let cidr_prefix_length = params.cidr_prefix_length;


    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), IpAccessControlListSid=crate::apis::urlencode(ip_access_control_list_sid), Sid=crate::apis::urlencode(sid));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
    };
    let mut local_var_form_params = std::collections::HashMap::new();
    if let Some(local_var_param_value) = ip_address {
        local_var_form_params.insert("IpAddress", local_var_param_value.to_string());
    }
    if let Some(local_var_param_value) = friendly_name {
        local_var_form_params.insert("FriendlyName", local_var_param_value.to_string());
    }
    if let Some(local_var_param_value) = cidr_prefix_length {
        local_var_form_params.insert("CidrPrefixLength", local_var_param_value.to_string());
    }
    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<UpdateSipIpAddressError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}