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::revoke_device`]
    ///
    ///[`Client::revoke_device`]: crate::Client::revoke_device
    #[derive(Debug, Clone)]
    pub struct RevokeDevice<'a> {
        client: &'a crate::Client,
        account_id: Result<::std::string::String, String>,
        device_id: Result<::std::string::String, String>,
    }
    impl<'a> RevokeDevice<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                device_id: Err("device_id was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `POST` request to
        /// `/accounts/{account_id}/devices/physical-devices/{device_id}/revoke`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                device_id,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let device_id = device_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/devices/physical-devices/{}/revoke",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&device_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
                .post(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "revoke_device",
            };
            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::revoke_registrations`]
    ///
    ///[`Client::revoke_registrations`]: crate::Client::revoke_registrations
    #[derive(Debug, Clone)]
    pub struct RevokeRegistrations<'a> {
        client: &'a crate::Client,
        account_id: Result<::std::string::String, String>,
        id: Result<::std::vec::Vec<::std::string::String>, String>,
    }
    impl<'a> RevokeRegistrations<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                id: Err("id was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `POST` request to
        /// `/accounts/{account_id}/devices/registrations/revoke`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                id,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let id = id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/devices/registrations/revoke",
                client.baseurl,
                encode_path(&account_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
                .post(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .query(&progenitor_client::QueryParam::new("id", &id))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "revoke_registrations",
            };
            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)),
            }
        }
    }