workos 1.0.0

Official Rust SDK for the WorkOS API
Documentation
// Code generated by oagen. DO NOT EDIT.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct RadarApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateAttemptParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: RadarStandaloneAssessRequest,
}

impl CreateAttemptParams {
    /// Construct a new `CreateAttemptParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: RadarStandaloneAssessRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateAttemptParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: RadarStandaloneUpdateRadarAttemptRequest,
}

impl UpdateAttemptParams {
    /// Construct a new `UpdateAttemptParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: RadarStandaloneUpdateRadarAttemptRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct AddListEntryParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: RadarStandaloneUpdateRadarListRequest,
}

impl AddListEntryParams {
    /// Construct a new `AddListEntryParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: RadarStandaloneUpdateRadarListRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct RemoveListEntryParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: RadarStandaloneDeleteRadarListEntryRequest,
}

impl RemoveListEntryParams {
    /// Construct a new `RemoveListEntryParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: RadarStandaloneDeleteRadarListEntryRequest) -> Self {
        Self { body }
    }
}

impl<'a> RadarApi<'a> {
    /// Create an attempt
    ///
    /// Assess a request for risk using the Radar engine and receive a verdict.
    pub async fn create_attempt(
        &self,
        params: CreateAttemptParams,
    ) -> Result<RadarStandaloneResponse, Error> {
        self.create_attempt_with_options(params, None).await
    }

    /// Variant of [`Self::create_attempt`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_attempt_with_options(
        &self,
        params: CreateAttemptParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<RadarStandaloneResponse, Error> {
        let path = "/radar/attempts".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Update a Radar attempt
    ///
    /// You may optionally inform Radar that an authentication attempt or challenge was successful using this endpoint. Some Radar controls depend on tracking recent successful attempts, such as impossible travel.
    pub async fn update_attempt(&self, id: &str, params: UpdateAttemptParams) -> Result<(), Error> {
        self.update_attempt_with_options(id, params, None).await
    }

    /// Variant of [`Self::update_attempt`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_attempt_with_options(
        &self,
        id: &str,
        params: UpdateAttemptParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let id = crate::client::path_segment(id);
        let path = format!("/radar/attempts/{id}");
        let method = http::Method::PUT;
        self.client
            .request_with_body_opts_empty(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Add an entry to a Radar list
    ///
    /// Add an entry to a Radar list.
    pub async fn add_list_entry(
        &self,
        type_: &str,
        action: &str,
        params: AddListEntryParams,
    ) -> Result<RadarListEntryAlreadyPresentResponse, Error> {
        self.add_list_entry_with_options(type_, action, params, None)
            .await
    }

    /// Variant of [`Self::add_list_entry`] that accepts per-request [`crate::RequestOptions`].
    pub async fn add_list_entry_with_options(
        &self,
        type_: &str,
        action: &str,
        params: AddListEntryParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<RadarListEntryAlreadyPresentResponse, Error> {
        let type_ = crate::client::path_segment(type_);
        let action = crate::client::path_segment(action);
        let path = format!("/radar/lists/{type_}/{action}");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Remove an entry from a Radar list
    ///
    /// Remove an entry from a Radar list.
    pub async fn remove_list_entry(
        &self,
        type_: &str,
        action: &str,
        params: RemoveListEntryParams,
    ) -> Result<(), Error> {
        self.remove_list_entry_with_options(type_, action, params, None)
            .await
    }

    /// Variant of [`Self::remove_list_entry`] that accepts per-request [`crate::RequestOptions`].
    pub async fn remove_list_entry_with_options(
        &self,
        type_: &str,
        action: &str,
        params: RemoveListEntryParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let type_ = crate::client::path_segment(type_);
        let action = crate::client::path_segment(action);
        let path = format!("/radar/lists/{type_}/{action}");
        let method = http::Method::DELETE;
        self.client
            .request_with_body_opts_empty(method, &path, &params, Some(&params.body), options)
            .await
    }
}