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::origin_ca_get_certificate`]
    ///
    ///[`Client::origin_ca_get_certificate`]: crate::Client::origin_ca_get_certificate
    #[derive(Debug, Clone)]
    pub struct OriginCaGetCertificate<'a> {
        client: &'a crate::Client,
        certificate_id: Result<types::TlsCertificatesAndHostnamesIdentifier, String>,
    }
    impl<'a> OriginCaGetCertificate<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                certificate_id: Err("certificate_id was not initialized".to_string()),
            }
        }

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

        ///Sends a `GET` request to `/certificates/{certificate_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                certificate_id,
            } = self;
            let certificate_id = certificate_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/certificates/{}",
                client.baseurl,
                encode_path(&certificate_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"),
                )
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "origin_ca_get_certificate",
            };
            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::origin_ca_revoke_certificate`]
    ///
    ///[`Client::origin_ca_revoke_certificate`]: crate::Client::origin_ca_revoke_certificate
    #[derive(Debug, Clone)]
    pub struct OriginCaRevokeCertificate<'a> {
        client: &'a crate::Client,
        certificate_id: Result<types::TlsCertificatesAndHostnamesIdentifier, String>,
        body: Result<::serde_json::Map<::std::string::String, ::serde_json::Value>, String>,
    }
    impl<'a> OriginCaRevokeCertificate<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                certificate_id: Err("certificate_id was not initialized".to_string()),
                body: Err("body was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `DELETE` request to `/certificates/{certificate_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                certificate_id,
                body,
            } = self;
            let certificate_id = certificate_id.map_err(Error::InvalidRequest)?;
            let body = body.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/certificates/{}",
                client.baseurl,
                encode_path(&certificate_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
                .delete(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .json(&body)
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "origin_ca_revoke_certificate",
            };
            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)),
            }
        }
    }