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::page_shield_get_settings`]
    ///
    ///[`Client::page_shield_get_settings`]: crate::Client::page_shield_get_settings
    #[derive(Debug, Clone)]
    pub struct PageShieldGetSettings<'a> {
        client: &'a crate::Client,
        zone_id: Result<types::PageShieldId, String>,
    }
    impl<'a> PageShieldGetSettings<'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::PageShieldId>,
        {
            self.zone_id = value
                .try_into()
                .map_err(|_| "conversion to `PageShieldId` for zone_id failed".to_string());
            self
        }

        ///Sends a `GET` request to `/zones/{zone_id}/page_shield`
        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/{}/page_shield",
                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: "page_shield_get_settings",
            };
            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::page_shield_update_settings`]
    ///
    ///[`Client::page_shield_update_settings`]: crate::Client::page_shield_update_settings
    #[derive(Debug, Clone)]
    pub struct PageShieldUpdateSettings<'a> {
        client: &'a crate::Client,
        zone_id: Result<types::PageShieldId, String>,
        body: Result<types::builder::PageShieldUpdateSettingsBody, String>,
    }
    impl<'a> PageShieldUpdateSettings<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                zone_id: Err("zone_id was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

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

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

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

        ///Sends a `PUT` request to `/zones/{zone_id}/page_shield`
        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
                .and_then(|v| {
                    types::PageShieldUpdateSettingsBody::try_from(v).map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/zones/{}/page_shield",
                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: "page_shield_update_settings",
            };
            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 connections;
mod cookies;
mod policies;
mod scripts;

pub use connections::*;
pub use cookies::*;
pub use policies::*;
pub use scripts::*;