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::botnet_threat_feed_get_day_report`]
    ///
    ///[`Client::botnet_threat_feed_get_day_report`]: crate::Client::botnet_threat_feed_get_day_report
    #[derive(Debug, Clone)]
    pub struct BotnetThreatFeedGetDayReport<'a> {
        client: &'a crate::Client,
        account_id: Result<types::DosIdentifier, String>,
        asn_id: Result<types::DosAsn, String>,
        date: Result<types::DosTimestamp, String>,
    }
    impl<'a> BotnetThreatFeedGetDayReport<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                asn_id: Err("asn_id was not initialized".to_string()),
                date: Err("date was not initialized".to_string()),
            }
        }

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

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

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

        ///Sends a `GET` request to
        /// `/accounts/{account_id}/botnet_feed/asn/{asn_id}/day_report`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                asn_id,
                date,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let asn_id = asn_id.map_err(Error::InvalidRequest)?;
            let date = date.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/botnet_feed/asn/{}/day_report",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&asn_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("date", &date))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "botnet_threat_feed_get_day_report",
            };
            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::botnet_threat_feed_get_full_report`]
    ///
    ///[`Client::botnet_threat_feed_get_full_report`]: crate::Client::botnet_threat_feed_get_full_report
    #[derive(Debug, Clone)]
    pub struct BotnetThreatFeedGetFullReport<'a> {
        client: &'a crate::Client,
        account_id: Result<types::DosIdentifier, String>,
        asn_id: Result<types::DosAsn, String>,
    }
    impl<'a> BotnetThreatFeedGetFullReport<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                asn_id: Err("asn_id was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `GET` request to
        /// `/accounts/{account_id}/botnet_feed/asn/{asn_id}/full_report`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                asn_id,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let asn_id = asn_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/botnet_feed/asn/{}/full_report",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&asn_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: "botnet_threat_feed_get_full_report",
            };
            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::botnet_threat_feed_list_asn`]
    ///
    ///[`Client::botnet_threat_feed_list_asn`]: crate::Client::botnet_threat_feed_list_asn
    #[derive(Debug, Clone)]
    pub struct BotnetThreatFeedListAsn<'a> {
        client: &'a crate::Client,
        account_id: Result<types::DosIdentifier, String>,
    }
    impl<'a> BotnetThreatFeedListAsn<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
            }
        }

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

        ///Sends a `GET` request to
        /// `/accounts/{account_id}/botnet_feed/configs/asn`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self { client, account_id } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/botnet_feed/configs/asn",
                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"),
                )
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "botnet_threat_feed_list_asn",
            };
            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::botnet_threat_feed_delete_asn`]
    ///
    ///[`Client::botnet_threat_feed_delete_asn`]: crate::Client::botnet_threat_feed_delete_asn
    #[derive(Debug, Clone)]
    pub struct BotnetThreatFeedDeleteAsn<'a> {
        client: &'a crate::Client,
        account_id: Result<types::DosIdentifier, String>,
        asn_id: Result<types::DosAsn, String>,
    }
    impl<'a> BotnetThreatFeedDeleteAsn<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                asn_id: Err("asn_id was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `DELETE` request to
        /// `/accounts/{account_id}/botnet_feed/configs/asn/{asn_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                asn_id,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let asn_id = asn_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/botnet_feed/configs/asn/{}",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&asn_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"),
                )
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "botnet_threat_feed_delete_asn",
            };
            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)),
            }
        }
    }