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::passive_dns_by_ip_get_passive_dns_by_ip`]
    ///
    ///[`Client::passive_dns_by_ip_get_passive_dns_by_ip`]: crate::Client::passive_dns_by_ip_get_passive_dns_by_ip
    #[derive(Debug, Clone)]
    pub struct PassiveDnsByIpGetPassiveDnsByIp<'a> {
        client: &'a crate::Client,
        account_id: Result<types::IntelIdentifier, String>,
        ipv4: Result<::std::string::String, String>,
        page: Result<f64, String>,
        per_page: Result<f64, String>,
        start_end_params: Result<::std::string::String, String>,
    }
    impl<'a> PassiveDnsByIpGetPassiveDnsByIp<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                ipv4: Err("ipv4 was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                start_end_params: Err("start_end_params was not initialized".to_string()),
            }
        }

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

        pub fn ipv4<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.ipv4 = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for ipv4 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 start_end_params<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.start_end_params = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for start_end_params failed".to_string()
            });
            self
        }

        ///Sends a `GET` request to `/accounts/{account_id}/intel/dns`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                ipv4,
                page,
                per_page,
                start_end_params,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let ipv4 = ipv4.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let start_end_params = start_end_params.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/intel/dns",
                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("ipv4", &ipv4))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new(
                    "start_end_params",
                    &start_end_params,
                ))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "passive_dns_by_ip_get_passive_dns_by_ip",
            };
            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)),
            }
        }
    }