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::secrets_store_system_list`]
    ///
    ///[`Client::secrets_store_system_list`]: crate::Client::secrets_store_system_list
    #[derive(Debug, Clone)]
    pub struct SecretsStoreSystemList<'a> {
        client: &'a crate::Client,
        account_tag: Result<types::SecretsStoreAccountTag, String>,
        direction: Result<types::SecretsStoreSystemListDirection, String>,
        order: Result<types::SecretsStoreSystemListOrder, String>,
        page: Result<u64, String>,
        per_page: Result<i64, String>,
    }
    impl<'a> SecretsStoreSystemList<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_tag: Err("account_tag was not initialized".to_string()),
                direction: Err("direction was not initialized".to_string()),
                order: Err("order was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
            }
        }

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

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

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

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

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

        ///Sends a `GET` request to `/system/accounts/{account_tag}/stores`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_tag,
                direction,
                order,
                page,
                per_page,
            } = self;
            let account_tag = account_tag.map_err(Error::InvalidRequest)?;
            let direction = direction.map_err(Error::InvalidRequest)?;
            let order = order.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/system/accounts/{}/stores",
                client.baseurl,
                encode_path(&account_tag.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("order", &order))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "secrets_store_system_list",
            };
            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::secrets_store_system_create`]
    ///
    ///[`Client::secrets_store_system_create`]: crate::Client::secrets_store_system_create
    #[derive(Debug, Clone)]
    pub struct SecretsStoreSystemCreate<'a> {
        client: &'a crate::Client,
        account_tag: Result<types::SecretsStoreAccountTag, String>,
        body: Result<types::builder::SecretsStoreCreateStoreObjectSystem, String>,
    }
    impl<'a> SecretsStoreSystemCreate<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_tag: Err("account_tag was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

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

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

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

        ///Sends a `POST` request to `/system/accounts/{account_tag}/stores`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_tag,
                body,
            } = self;
            let account_tag = account_tag.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::SecretsStoreCreateStoreObjectSystem::try_from(v)
                        .map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/system/accounts/{}/stores",
                client.baseurl,
                encode_path(&account_tag.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
                .post(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .json(&body)
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "secrets_store_system_create",
            };
            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)),
            }
        }
    }