cloudflare-api 0.1.0

Typed Rust client bindings for the Cloudflare API generated from OpenAPI definitions.
Documentation
use super::types;
use crate::{
    ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
    ResponseValue, encode_path,
};

    ///Builder for [`Client::zero_trust_networks_subnets_list`]
    ///
    ///[`Client::zero_trust_networks_subnets_list`]: crate::Client::zero_trust_networks_subnets_list
    #[derive(Debug, Clone)]
    pub struct ZeroTrustNetworksSubnetsList<'a> {
        client: &'a crate::Client,
        account_id: Result<types::TunnelAccountId, String>,
        address_family: Result<types::TunnelAddressFamily, String>,
        comment: Result<types::TunnelSubnetQueryComment, String>,
        existed_at: Result<types::TunnelExistedAt, String>,
        is_default_network: Result<bool, String>,
        is_deleted: Result<bool, String>,
        name: Result<types::TunnelSubnetQueryName, String>,
        network: Result<types::TunnelIpNetworkEncoded, String>,
        page: Result<types::TunnelPageNumber, String>,
        per_page: Result<types::TunnelPerPage, String>,
        sort_order: Result<types::ZeroTrustNetworksSubnetsListSortOrder, String>,
        subnet_types: Result<types::ZeroTrustNetworksSubnetsListSubnetTypes, String>,
    }
    impl<'a> ZeroTrustNetworksSubnetsList<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                address_family: Err("address_family was not initialized".to_string()),
                comment: Err("comment was not initialized".to_string()),
                existed_at: Err("existed_at was not initialized".to_string()),
                is_default_network: Err("is_default_network was not initialized".to_string()),
                is_deleted: Err("is_deleted was not initialized".to_string()),
                name: Err("name was not initialized".to_string()),
                network: Err("network was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                sort_order: Err("sort_order was not initialized".to_string()),
                subnet_types: Err("subnet_types was not initialized".to_string()),
            }
        }

        pub fn account_id<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelAccountId>,
        {
            self.account_id = value
                .try_into()
                .map_err(|_| "conversion to `TunnelAccountId` for account_id failed".to_string());
            self
        }

        pub fn address_family<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelAddressFamily>,
        {
            self.address_family = value.try_into().map_err(|_| {
                "conversion to `TunnelAddressFamily` for address_family failed".to_string()
            });
            self
        }

        pub fn comment<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelSubnetQueryComment>,
        {
            self.comment = value.try_into().map_err(|_| {
                "conversion to `TunnelSubnetQueryComment` for comment failed".to_string()
            });
            self
        }

        pub fn existed_at<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelExistedAt>,
        {
            self.existed_at = value
                .try_into()
                .map_err(|_| "conversion to `TunnelExistedAt` for existed_at failed".to_string());
            self
        }

        pub fn is_default_network<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<bool>,
        {
            self.is_default_network = value
                .try_into()
                .map_err(|_| "conversion to `bool` for is_default_network failed".to_string());
            self
        }

        pub fn is_deleted<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<bool>,
        {
            self.is_deleted = value
                .try_into()
                .map_err(|_| "conversion to `bool` for is_deleted failed".to_string());
            self
        }

        pub fn name<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelSubnetQueryName>,
        {
            self.name = value
                .try_into()
                .map_err(|_| "conversion to `TunnelSubnetQueryName` for name failed".to_string());
            self
        }

        pub fn network<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelIpNetworkEncoded>,
        {
            self.network = value.try_into().map_err(|_| {
                "conversion to `TunnelIpNetworkEncoded` for network failed".to_string()
            });
            self
        }

        pub fn page<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelPageNumber>,
        {
            self.page = value
                .try_into()
                .map_err(|_| "conversion to `TunnelPageNumber` for page failed".to_string());
            self
        }

        pub fn per_page<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelPerPage>,
        {
            self.per_page = value
                .try_into()
                .map_err(|_| "conversion to `TunnelPerPage` for per_page failed".to_string());
            self
        }

        pub fn sort_order<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::ZeroTrustNetworksSubnetsListSortOrder>,
        {
            self.sort_order = value.try_into().map_err(|_| {
                "conversion to `ZeroTrustNetworksSubnetsListSortOrder` for sort_order failed"
                    .to_string()
            });
            self
        }

        pub fn subnet_types<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::ZeroTrustNetworksSubnetsListSubnetTypes>,
        {
            self . subnet_types = value . try_into () . map_err (| _ | "conversion to `ZeroTrustNetworksSubnetsListSubnetTypes` for subnet_types failed" . to_string ()) ;
            self
        }

        ///Sends a `GET` request to `/accounts/{account_id}/zerotrust/subnets`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                address_family,
                comment,
                existed_at,
                is_default_network,
                is_deleted,
                name,
                network,
                page,
                per_page,
                sort_order,
                subnet_types,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let address_family = address_family.map_err(Error::InvalidRequest)?;
            let comment = comment.map_err(Error::InvalidRequest)?;
            let existed_at = existed_at.map_err(Error::InvalidRequest)?;
            let is_default_network = is_default_network.map_err(Error::InvalidRequest)?;
            let is_deleted = is_deleted.map_err(Error::InvalidRequest)?;
            let name = name.map_err(Error::InvalidRequest)?;
            let network = network.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let sort_order = sort_order.map_err(Error::InvalidRequest)?;
            let subnet_types = subnet_types.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/zerotrust/subnets",
                client.baseurl,
                encode_path(&account_id.to_string()),
            );
            let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
            header_map.append(
                ::reqwest::header::HeaderName::from_static("api-version"),
                ::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
            );
            #[allow(unused_mut)]
            let mut request = client
                .client
                .get(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .query(&progenitor_client::QueryParam::new(
                    "address_family",
                    &address_family,
                ))
                .query(&progenitor_client::QueryParam::new("comment", &comment))
                .query(&progenitor_client::QueryParam::new(
                    "existed_at",
                    &existed_at,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "is_default_network",
                    &is_default_network,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "is_deleted",
                    &is_deleted,
                ))
                .query(&progenitor_client::QueryParam::new("name", &name))
                .query(&progenitor_client::QueryParam::new("network", &network))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new(
                    "sort_order",
                    &sort_order,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "subnet_types",
                    &subnet_types,
                ))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "zero_trust_networks_subnets_list",
            };
            client.pre(&mut request, &info).await?;
            let result = client.exec(request, &info).await;
            client.post(&result, &info).await?;
            let response = result?;
            match response.status().as_u16() {
                200u16 => ResponseValue::from_response(response).await,
                _ => Err(Error::UnexpectedResponse(response)),
            }
        }
    }