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::user_s_account_memberships_membership_details`]
    ///
    ///[`Client::user_s_account_memberships_membership_details`]: crate::Client::user_s_account_memberships_membership_details
    #[derive(Debug, Clone)]
    pub struct UserSAccountMembershipsMembershipDetails<'a> {
        client: &'a crate::Client,
        membership_id: Result<types::IamMembershipComponentsSchemasIdentifier, String>,
    }
    impl<'a> UserSAccountMembershipsMembershipDetails<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                membership_id: Err("membership_id was not initialized".to_string()),
            }
        }

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

        ///Sends a `GET` request to `/memberships/{membership_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                membership_id,
            } = self;
            let membership_id = membership_id.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/memberships/{}",
                client.baseurl,
                encode_path(&membership_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"),
                )
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "user_s_account_memberships_membership_details",
            };
            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::user_s_account_memberships_update_membership`]
    ///
    ///[`Client::user_s_account_memberships_update_membership`]: crate::Client::user_s_account_memberships_update_membership
    #[derive(Debug, Clone)]
    pub struct UserSAccountMembershipsUpdateMembership<'a> {
        client: &'a crate::Client,
        membership_id: Result<types::IamMembershipComponentsSchemasIdentifier, String>,
        body: Result<types::builder::UserSAccountMembershipsUpdateMembershipBody, String>,
    }
    impl<'a> UserSAccountMembershipsUpdateMembership<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                membership_id: Err("membership_id was not initialized".to_string()),
                body: Ok(::std::default::Default::default()),
            }
        }

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

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

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

        ///Sends a `PUT` request to `/memberships/{membership_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                membership_id,
                body,
            } = self;
            let membership_id = membership_id.map_err(Error::InvalidRequest)?;
            let body = body
                .and_then(|v| {
                    types::UserSAccountMembershipsUpdateMembershipBody::try_from(v)
                        .map_err(|e| e.to_string())
                })
                .map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/memberships/{}",
                client.baseurl,
                encode_path(&membership_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: "user_s_account_memberships_update_membership",
            };
            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::user_s_account_memberships_delete_membership`]
    ///
    ///[`Client::user_s_account_memberships_delete_membership`]: crate::Client::user_s_account_memberships_delete_membership
    #[derive(Debug, Clone)]
    pub struct UserSAccountMembershipsDeleteMembership<'a> {
        client: &'a crate::Client,
        membership_id: Result<types::IamMembershipComponentsSchemasIdentifier, String>,
        body: Result<::serde_json::Map<::std::string::String, ::serde_json::Value>, String>,
    }
    impl<'a> UserSAccountMembershipsDeleteMembership<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                membership_id: Err("membership_id was not initialized".to_string()),
                body: Err("body was not initialized".to_string()),
            }
        }

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

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

        ///Sends a `DELETE` request to `/memberships/{membership_id}`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                membership_id,
                body,
            } = self;
            let membership_id = membership_id.map_err(Error::InvalidRequest)?;
            let body = body.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/memberships/{}",
                client.baseurl,
                encode_path(&membership_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
                .delete(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .json(&body)
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "user_s_account_memberships_delete_membership",
            };
            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)),
            }
        }
    }