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::audit_logs_get_user_audit_logs`]
    ///
    ///[`Client::audit_logs_get_user_audit_logs`]: crate::Client::audit_logs_get_user_audit_logs
    #[derive(Debug, Clone)]
    pub struct AuditLogsGetUserAuditLogs<'a> {
        client: &'a crate::Client,
        action_type: Result<::std::string::String, String>,
        actor_email: Result<::std::string::String, String>,
        actor_ip: Result<::std::string::String, String>,
        before: Result<types::AuditLogsGetUserAuditLogsBefore, String>,
        direction: Result<types::AuditLogsGetUserAuditLogsDirection, String>,
        export: Result<bool, String>,
        hide_user_logs: Result<bool, String>,
        id: Result<::std::string::String, String>,
        page: Result<f64, String>,
        per_page: Result<f64, String>,
        since: Result<types::AuditLogsGetUserAuditLogsSince, String>,
        zone_name: Result<::std::string::String, String>,
    }
    impl<'a> AuditLogsGetUserAuditLogs<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                action_type: Err("action_type was not initialized".to_string()),
                actor_email: Err("actor_email was not initialized".to_string()),
                actor_ip: Err("actor_ip was not initialized".to_string()),
                before: Err("before was not initialized".to_string()),
                direction: Err("direction was not initialized".to_string()),
                export: Err("export was not initialized".to_string()),
                hide_user_logs: Err("hide_user_logs was not initialized".to_string()),
                id: Err("id was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                since: Err("since was not initialized".to_string()),
                zone_name: Err("zone_name was not initialized".to_string()),
            }
        }

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

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

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

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

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

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

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

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

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

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

        ///Sends a `GET` request to `/user/audit_logs`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                action_type,
                actor_email,
                actor_ip,
                before,
                direction,
                export,
                hide_user_logs,
                id,
                page,
                per_page,
                since,
                zone_name,
            } = self;
            let action_type = action_type.map_err(Error::InvalidRequest)?;
            let actor_email = actor_email.map_err(Error::InvalidRequest)?;
            let actor_ip = actor_ip.map_err(Error::InvalidRequest)?;
            let before = before.map_err(Error::InvalidRequest)?;
            let direction = direction.map_err(Error::InvalidRequest)?;
            let export = export.map_err(Error::InvalidRequest)?;
            let hide_user_logs = hide_user_logs.map_err(Error::InvalidRequest)?;
            let id = id.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let since = since.map_err(Error::InvalidRequest)?;
            let zone_name = zone_name.map_err(Error::InvalidRequest)?;
            let url = format!("{}/user/audit_logs", client.baseurl,);
            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(
                    "action.type",
                    &action_type,
                ))
                .query(&progenitor_client::QueryParam::new(
                    "actor.email",
                    &actor_email,
                ))
                .query(&progenitor_client::QueryParam::new("actor.ip", &actor_ip))
                .query(&progenitor_client::QueryParam::new("before", &before))
                .query(&progenitor_client::QueryParam::new("direction", &direction))
                .query(&progenitor_client::QueryParam::new("export", &export))
                .query(&progenitor_client::QueryParam::new(
                    "hide_user_logs",
                    &hide_user_logs,
                ))
                .query(&progenitor_client::QueryParam::new("id", &id))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new("since", &since))
                .query(&progenitor_client::QueryParam::new("zone.name", &zone_name))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "audit_logs_get_user_audit_logs",
            };
            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)),
            }
        }
    }