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_list_cookies`]
    ///
    ///[`Client::page_shield_list_cookies`]: crate::Client::page_shield_list_cookies
    #[derive(Debug, Clone)]
    pub struct PageShieldListCookies<'a> {
        client: &'a crate::Client,
        zone_id: Result<types::PageShieldId, String>,
        direction: Result<types::PageShieldListCookiesDirection, String>,
        domain: Result<types::PageShieldListCookiesDomain, String>,
        export: Result<types::PageShieldListCookiesExport, String>,
        hosts: Result<::std::string::String, String>,
        http_only: Result<bool, String>,
        name: Result<types::PageShieldListCookiesName, String>,
        order_by: Result<types::PageShieldListCookiesOrderBy, String>,
        page: Result<::std::string::String, String>,
        page_url: Result<::std::string::String, String>,
        path: Result<types::PageShieldListCookiesPath, String>,
        per_page: Result<f64, String>,
        same_site: Result<types::PageShieldListCookiesSameSite, String>,
        secure: Result<bool, String>,
        kind: Result<types::PageShieldListCookiesType, String>,
    }
    impl<'a> PageShieldListCookies<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                zone_id: Err("zone_id was not initialized".to_string()),
                direction: Err("direction was not initialized".to_string()),
                domain: Err("domain was not initialized".to_string()),
                export: Err("export was not initialized".to_string()),
                hosts: Err("hosts was not initialized".to_string()),
                http_only: Err("http_only was not initialized".to_string()),
                name: Err("name was not initialized".to_string()),
                order_by: Err("order_by was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                page_url: Err("page_url was not initialized".to_string()),
                path: Err("path was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                same_site: Err("same_site was not initialized".to_string()),
                secure: Err("secure was not initialized".to_string()),
                kind: Err("kind 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
        }

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

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

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

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

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

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

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

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

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

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

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

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

        ///Sends a `GET` request to `/zones/{zone_id}/page_shield/cookies`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                zone_id,
                direction,
                domain,
                export,
                hosts,
                http_only,
                name,
                order_by,
                page,
                page_url,
                path,
                per_page,
                same_site,
                secure,
                kind,
            } = self;
            let zone_id = zone_id.map_err(Error::InvalidRequest)?;
            let direction = direction.map_err(Error::InvalidRequest)?;
            let domain = domain.map_err(Error::InvalidRequest)?;
            let export = export.map_err(Error::InvalidRequest)?;
            let hosts = hosts.map_err(Error::InvalidRequest)?;
            let http_only = http_only.map_err(Error::InvalidRequest)?;
            let name = name.map_err(Error::InvalidRequest)?;
            let order_by = order_by.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let page_url = page_url.map_err(Error::InvalidRequest)?;
            let path = path.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let same_site = same_site.map_err(Error::InvalidRequest)?;
            let secure = secure.map_err(Error::InvalidRequest)?;
            let kind = kind.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/zones/{}/page_shield/cookies",
                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"),
                )
                .query(&progenitor_client::QueryParam::new("direction", &direction))
                .query(&progenitor_client::QueryParam::new("domain", &domain))
                .query(&progenitor_client::QueryParam::new("export", &export))
                .query(&progenitor_client::QueryParam::new("hosts", &hosts))
                .query(&progenitor_client::QueryParam::new("http_only", &http_only))
                .query(&progenitor_client::QueryParam::new("name", &name))
                .query(&progenitor_client::QueryParam::new("order_by", &order_by))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("page_url", &page_url))
                .query(&progenitor_client::QueryParam::new("path", &path))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new("same_site", &same_site))
                .query(&progenitor_client::QueryParam::new("secure", &secure))
                .query(&progenitor_client::QueryParam::new("type", &kind))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "page_shield_list_cookies",
            };
            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)),
            }
        }
    }