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::custom_hostname_for_a_zone_list_custom_hostnames`]
    ///
    ///[`Client::custom_hostname_for_a_zone_list_custom_hostnames`]: crate::Client::custom_hostname_for_a_zone_list_custom_hostnames
    #[derive(Debug, Clone)]
    pub struct CustomHostnameForAZoneListCustomHostnames<'a> {
        client: &'a crate::Client,
        zone_id: Result<types::TlsCertificatesAndHostnamesIdentifier, String>,
        direction: Result<types::CustomHostnameForAZoneListCustomHostnamesDirection, String>,
        hostname: Result<types::CustomHostnameForAZoneListCustomHostnamesHostname, String>,
        id: Result<types::CustomHostnameForAZoneListCustomHostnamesId, String>,
        order: Result<types::CustomHostnameForAZoneListCustomHostnamesOrder, String>,
        page: Result<f64, String>,
        per_page: Result<f64, String>,
        ssl: Result<types::CustomHostnameForAZoneListCustomHostnamesSsl, String>,
    }
    impl<'a> CustomHostnameForAZoneListCustomHostnames<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                zone_id: Err("zone_id was not initialized".to_string()),
                direction: Err("direction was not initialized".to_string()),
                hostname: Err("hostname was not initialized".to_string()),
                id: Err("id was not initialized".to_string()),
                order: Err("order was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                ssl: Err("ssl was not initialized".to_string()),
            }
        }

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

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

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

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

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

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

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

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

        ///Sends a `GET` request to `/zones/{zone_id}/custom_hostnames`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                zone_id,
                direction,
                hostname,
                id,
                order,
                page,
                per_page,
                ssl,
            } = self;
            let zone_id = zone_id.map_err(Error::InvalidRequest)?;
            let direction = direction.map_err(Error::InvalidRequest)?;
            let hostname = hostname.map_err(Error::InvalidRequest)?;
            let id = id.map_err(Error::InvalidRequest)?;
            let order = order.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let ssl = ssl.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/zones/{}/custom_hostnames",
                client.baseurl,
                encode_path(&zone_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("direction", &direction))
                .query(&progenitor_client::QueryParam::new("hostname", &hostname))
                .query(&progenitor_client::QueryParam::new("id", &id))
                .query(&progenitor_client::QueryParam::new("order", &order))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new("ssl", &ssl))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "custom_hostname_for_a_zone_list_custom_hostnames",
            };
            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)),
            }
        }
    }