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::archive_security_center_insight_deprecated`]
    ///
    ///[`Client::archive_security_center_insight_deprecated`]: crate::Client::archive_security_center_insight_deprecated
    #[derive(Debug, Clone)]
    pub struct ArchiveSecurityCenterInsightDeprecated<'a> {
        client: &'a crate::Client,
        account_id: Result<types::SecurityCenterIdentifier, String>,
        issue_id: Result<::std::string::String, String>,
        body: Result<types::builder::ArchiveSecurityCenterInsightDeprecatedBody, String>,
    }
    impl<'a> ArchiveSecurityCenterInsightDeprecated<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                issue_id: Err("issue_id was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

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

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

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

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

        ///Sends a `PUT` request to
        /// `/accounts/{account_id}/intel/attack-surface-report/{issue_id}/
        /// dismiss`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                issue_id,
                body,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let issue_id = issue_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::ArchiveSecurityCenterInsightDeprecatedBody::try_from(v)
                        .map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/intel/attack-surface-report/{}/dismiss",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&issue_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: "archive_security_center_insight_deprecated",
            };
            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::archive_security_center_insight`]
    ///
    ///[`Client::archive_security_center_insight`]: crate::Client::archive_security_center_insight
    #[derive(Debug, Clone)]
    pub struct ArchiveSecurityCenterInsight<'a> {
        client: &'a crate::Client,
        account_id: Result<types::SecurityCenterIdentifier, String>,
        issue_id: Result<::std::string::String, String>,
        body: Result<types::builder::ArchiveSecurityCenterInsightBody, String>,
    }
    impl<'a> ArchiveSecurityCenterInsight<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                issue_id: Err("issue_id was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

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

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

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

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

        ///Sends a `PUT` request to
        /// `/accounts/{account_id}/security-center/insights/{issue_id}/dismiss`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                issue_id,
                body,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let issue_id = issue_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::ArchiveSecurityCenterInsightBody::try_from(v).map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/security-center/insights/{}/dismiss",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&issue_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: "archive_security_center_insight",
            };
            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::archive_zone_security_center_insight`]
    ///
    ///[`Client::archive_zone_security_center_insight`]: crate::Client::archive_zone_security_center_insight
    #[derive(Debug, Clone)]
    pub struct ArchiveZoneSecurityCenterInsight<'a> {
        client: &'a crate::Client,
        zone_id: Result<types::SecurityCenterIdentifier, String>,
        issue_id: Result<::std::string::String, String>,
        body: Result<types::builder::ArchiveZoneSecurityCenterInsightBody, String>,
    }
    impl<'a> ArchiveZoneSecurityCenterInsight<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                zone_id: Err("zone_id was not initialized".to_string()),
                issue_id: Err("issue_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::SecurityCenterIdentifier>,
        {
            self.zone_id = value.try_into().map_err(|_| {
                "conversion to `SecurityCenterIdentifier` for zone_id failed".to_string()
            });
            self
        }

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

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

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

        ///Sends a `PUT` request to
        /// `/zones/{zone_id}/security-center/insights/{issue_id}/dismiss`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                zone_id,
                issue_id,
                body,
            } = self;
            let zone_id = zone_id.map_err(Error::InvalidRequest)?;
            let issue_id = issue_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::ArchiveZoneSecurityCenterInsightBody::try_from(v)
                        .map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/zones/{}/security-center/insights/{}/dismiss",
                client.baseurl,
                encode_path(&zone_id.to_string()),
                encode_path(&issue_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: "archive_zone_security_center_insight",
            };
            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)),
            }
        }
    }