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

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

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

        ///Sends a `GET` request to
        /// `/accounts/{account_id}/registrar/domains/{domain_name}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                domain_name,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let domain_name = domain_name.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/registrar/domains/{}",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&domain_name.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: "registrar_domains_get_domain",
            };
            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::registrar_domains_update_domain`]
    ///
    ///[`Client::registrar_domains_update_domain`]: crate::Client::registrar_domains_update_domain
    #[derive(Debug, Clone)]
    pub struct RegistrarDomainsUpdateDomain<'a> {
        client: &'a crate::Client,
        account_id: Result<types::RegistrarApiIdentifier, String>,
        domain_name: Result<types::RegistrarApiDomainName, String>,
        body: Result<types::builder::RegistrarApiDomainUpdateProperties, String>,
    }
    impl<'a> RegistrarDomainsUpdateDomain<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                domain_name: Err("domain_name 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::RegistrarApiIdentifier>,
        {
            self.account_id = value.try_into().map_err(|_| {
                "conversion to `RegistrarApiIdentifier` for account_id failed".to_string()
            });
            self
        }

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

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

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

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