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::kick_partcipants`]
    ///
    ///[`Client::kick_partcipants`]: crate::Client::kick_partcipants
    #[derive(Debug, Clone)]
    pub struct KickPartcipants<'a> {
        client: &'a crate::Client,
        account_id: Result<types::RealtimekitAccountIdentifier, String>,
        app_id: Result<types::RealtimekitAppId, String>,
        meeting_id: Result<::std::string::String, String>,
        body: Result<types::builder::KickPartcipantsBody, String>,
    }
    impl<'a> KickPartcipants<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                app_id: Err("app_id was not initialized".to_string()),
                meeting_id: Err("meeting_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::RealtimekitAccountIdentifier>,
        {
            self.account_id = value.try_into().map_err(|_| {
                "conversion to `RealtimekitAccountIdentifier` for account_id failed".to_string()
            });
            self
        }

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

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

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

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

        ///Sends a `POST` request to
        /// `/accounts/{account_id}/realtime/kit/{app_id}/meetings/{meeting_id}/
        /// active-session/kick`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                app_id,
                meeting_id,
                body,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let app_id = app_id.map_err(Error::InvalidRequest)?;
            let meeting_id = meeting_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| types::KickPartcipantsBody::try_from(v).map_err(|e| e.to_string()))
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/realtime/kit/{}/meetings/{}/active-session/kick",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&app_id.to_string()),
                encode_path(&meeting_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"),
                )
                .json(&body)
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "kick_partcipants",
            };
            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::kick_all_participants`]
    ///
    ///[`Client::kick_all_participants`]: crate::Client::kick_all_participants
    #[derive(Debug, Clone)]
    pub struct KickAllParticipants<'a> {
        client: &'a crate::Client,
        account_id: Result<types::RealtimekitAccountIdentifier, String>,
        app_id: Result<types::RealtimekitAppId, String>,
        meeting_id: Result<::std::string::String, String>,
    }
    impl<'a> KickAllParticipants<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                app_id: Err("app_id was not initialized".to_string()),
                meeting_id: Err("meeting_id was not initialized".to_string()),
            }
        }

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

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

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

        ///Sends a `POST` request to
        /// `/accounts/{account_id}/realtime/kit/{app_id}/meetings/{meeting_id}/
        /// active-session/kick-all`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                app_id,
                meeting_id,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let app_id = app_id.map_err(Error::InvalidRequest)?;
            let meeting_id = meeting_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/realtime/kit/{}/meetings/{}/active-session/kick-all",
                client.baseurl,
                encode_path(&account_id.to_string()),
                encode_path(&app_id.to_string()),
                encode_path(&meeting_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: "kick_all_participants",
            };
            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)),
            }
        }
    }