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

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

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

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

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

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

mod feedback;

pub use feedback::*;