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::cloudflare_tunnel_list_cloudflare_tunnels`]
    ///
    ///[`Client::cloudflare_tunnel_list_cloudflare_tunnels`]: crate::Client::cloudflare_tunnel_list_cloudflare_tunnels
    #[derive(Debug, Clone)]
    pub struct CloudflareTunnelListCloudflareTunnels<'a> {
        client: &'a crate::Client,
        account_id: Result<types::TunnelAccountId, String>,
        exclude_prefix: Result<::std::string::String, String>,
        existed_at: Result<types::TunnelExistedAt, String>,
        include_prefix: Result<::std::string::String, String>,
        is_deleted: Result<bool, String>,
        name: Result<types::TunnelTunnelName, String>,
        page: Result<types::TunnelPageNumber, String>,
        per_page: Result<types::TunnelPerPage, String>,
        status: Result<types::TunnelStatus, String>,
        uuid: Result<types::TunnelTunnelId, String>,
        was_active_at: Result<::chrono::DateTime<::chrono::offset::Utc>, String>,
        was_inactive_at: Result<::chrono::DateTime<::chrono::offset::Utc>, String>,
    }
    impl<'a> CloudflareTunnelListCloudflareTunnels<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                exclude_prefix: Err("exclude_prefix was not initialized".to_string()),
                existed_at: Err("existed_at was not initialized".to_string()),
                include_prefix: Err("include_prefix was not initialized".to_string()),
                is_deleted: Err("is_deleted was not initialized".to_string()),
                name: Err("name was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                status: Err("status was not initialized".to_string()),
                uuid: Err("uuid was not initialized".to_string()),
                was_active_at: Err("was_active_at was not initialized".to_string()),
                was_inactive_at: Err("was_inactive_at 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 exclude_prefix<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.exclude_prefix = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for exclude_prefix 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 include_prefix<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.include_prefix = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for include_prefix 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::TunnelTunnelName>,
        {
            self.name = value
                .try_into()
                .map_err(|_| "conversion to `TunnelTunnelName` for name 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 status<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::TunnelStatus>,
        {
            self.status = value
                .try_into()
                .map_err(|_| "conversion to `TunnelStatus` for status failed".to_string());
            self
        }

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

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

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

        ///Sends a `GET` request to `/accounts/{account_id}/cfd_tunnel`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                exclude_prefix,
                existed_at,
                include_prefix,
                is_deleted,
                name,
                page,
                per_page,
                status,
                uuid,
                was_active_at,
                was_inactive_at,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let exclude_prefix = exclude_prefix.map_err(Error::InvalidRequest)?;
            let existed_at = existed_at.map_err(Error::InvalidRequest)?;
            let include_prefix = include_prefix.map_err(Error::InvalidRequest)?;
            let is_deleted = is_deleted.map_err(Error::InvalidRequest)?;
            let name = name.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let status = status.map_err(Error::InvalidRequest)?;
            let uuid = uuid.map_err(Error::InvalidRequest)?;
            let was_active_at = was_active_at.map_err(Error::InvalidRequest)?;
            let was_inactive_at = was_inactive_at.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/cfd_tunnel",
                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(
                    "exclude_prefix",
                    &exclude_prefix,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "existed_at",
                    &existed_at,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "include_prefix",
                    &include_prefix,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "is_deleted",
                    &is_deleted,
                ))
                .query(&progenitor_client::QueryParam::new("name", &name))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new("status", &status))
                .query(&progenitor_client::QueryParam::new("uuid", &uuid))
                .query(&progenitor_client::QueryParam::new(
                    "was_active_at",
                    &was_active_at,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "was_inactive_at",
                    &was_inactive_at,
                ))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "cloudflare_tunnel_list_cloudflare_tunnels",
            };
            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)),
            }
        }
    }

    ///Builder for [`Client::cloudflare_tunnel_create_a_cloudflare_tunnel`]
    ///
    ///[`Client::cloudflare_tunnel_create_a_cloudflare_tunnel`]: crate::Client::cloudflare_tunnel_create_a_cloudflare_tunnel
    #[derive(Debug, Clone)]
    pub struct CloudflareTunnelCreateACloudflareTunnel<'a> {
        client: &'a crate::Client,
        account_id: Result<types::TunnelAccountId, String>,
        body: Result<types::builder::CloudflareTunnelCreateACloudflareTunnelBody, String>,
    }
    impl<'a> CloudflareTunnelCreateACloudflareTunnel<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

        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 body<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<types::CloudflareTunnelCreateACloudflareTunnelBody>,
            <V as std::convert::TryInto<types::CloudflareTunnelCreateACloudflareTunnelBody>>::Error:
                std::fmt::Display,
        {
            self . body = value . try_into () . map (From :: from) . map_err (| s | format ! ("conversion to `CloudflareTunnelCreateACloudflareTunnelBody` for body failed: {}" , s)) ;
            self
        }

        pub fn body<F>(mut self, f: F) -> Self
        where
            F: std::ops::FnOnce(
                types::builder::CloudflareTunnelCreateACloudflareTunnelBody,
            )
                -> types::builder::CloudflareTunnelCreateACloudflareTunnelBody,
        {
            self.body = self.body.map(f);
            self
        }

        ///Sends a `POST` request to `/accounts/{account_id}/cfd_tunnel`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                body,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::CloudflareTunnelCreateACloudflareTunnelBody::try_from(v)
                        .map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/cfd_tunnel",
                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
                .post(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .json(&body)
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "cloudflare_tunnel_create_a_cloudflare_tunnel",
            };
            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)),
            }
        }
    }