whop_sdk 1.0.13

The official Rust SDK for the Whop API.
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;

pub struct RecommendedActionsClient {
    pub http_client: HttpClient,
}

impl RecommendedActionsClient {
    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
        Ok(Self {
            http_client: HttpClient::new(config.clone())?,
        })
    }

    /// Lists the recommended action chains for an account — short sequences of actions (create a product, price it, publish it) the account should run next, gated on what it already has.
    ///
    /// # Arguments
    ///
    /// * `account_id` - Account ID, prefixed `biz_`. Defaults to the API key's own account.
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use whop_sdk::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let config = ClientConfig {
    ///         token: Some("<token>".to_string()),
    ///         ..Default::default()
    ///     };
    ///     let client = Whop::new(config).expect("Failed to build client");
    ///     client
    ///         .recommended_actions
    ///         .list(
    ///             &RecommendedActionsListQueryRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn list(
        &self,
        request: &RecommendedActionsListQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<ListRecommendedActionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                "recommended_actions",
                None,
                QueryBuilder::new()
                    .string("account_id", request.account_id.clone())
                    .build(),
                options,
            )
            .await
    }

    /// Retrieves a recommended action chain by id, including chains that have already been run. Seeded chains are reconstructed from their hard-coded chain; generated chains are read from the account's stored chain, with each step's filled-in input.
    ///
    /// # Arguments
    ///
    /// * `id` - Chain ID from the list endpoint, e.g. `rac_seed_start_selling_9f2c1a7b04`.
    /// * `account_id` - Account ID, prefixed `biz_`. Defaults to the API key's own account.
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use whop_sdk::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let config = ClientConfig {
    ///         token: Some("<token>".to_string()),
    ///         ..Default::default()
    ///     };
    ///     let client = Whop::new(config).expect("Failed to build client");
    ///     client
    ///         .recommended_actions
    ///         .retrieve(
    ///             &"id".to_string(),
    ///             &RecommendedActionsRetrieveQueryRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn retrieve(
        &self,
        id: &str,
        request: &RecommendedActionsRetrieveQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<AccountRecommendedActionChain, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("recommended_actions/{}", id),
                None,
                QueryBuilder::new()
                    .string("account_id", request.account_id.clone())
                    .build(),
                options,
            )
            .await
    }

    /// Records that the caller ran a recommended action chain. Nothing is executed server-side yet — the client follows the chain's step CTAs itself; this writes the `recommended_action_chain.executed` analytics event.
    ///
    /// # Arguments
    ///
    /// * `id` - Chain ID from the list endpoint, e.g. `rac_seed_start_selling_9f2c1a7b04`.
    /// * `account_id` - Account ID, prefixed `biz_`. Defaults to the API key's own account.
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use whop_sdk::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let config = ClientConfig {
    ///         token: Some("<token>".to_string()),
    ///         ..Default::default()
    ///     };
    ///     let client = Whop::new(config).expect("Failed to build client");
    ///     client
    ///         .recommended_actions
    ///         .run(
    ///             &"id".to_string(),
    ///             &RunQueryRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn run(
        &self,
        id: &str,
        request: &RunQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<RunRecommendedActionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                &format!("recommended_actions/{}", id),
                None,
                QueryBuilder::new()
                    .string("account_id", request.account_id.clone())
                    .build(),
                options,
            )
            .await
    }

    /// Lists the per-step record of a recommended action chain the server ran — one entry per step in position order, each carrying its current status and, once the step completed, the API response it produced. A chain that was never run server-side returns an empty list.
    ///
    /// # Arguments
    ///
    /// * `id` - Chain ID from the list endpoint.
    /// * `account_id` - Account ID, prefixed `biz_`. Defaults to the API key's own account.
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use whop_sdk::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let config = ClientConfig {
    ///         token: Some("<token>".to_string()),
    ///         ..Default::default()
    ///     };
    ///     let client = Whop::new(config).expect("Failed to build client");
    ///     client
    ///         .recommended_actions
    ///         .list_executions(
    ///             &"id".to_string(),
    ///             &ListExecutionsQueryRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn list_executions(
        &self,
        id: &str,
        request: &ListExecutionsQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<ListExecutionsRecommendedActionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("recommended_actions/{}/executions", id),
                None,
                QueryBuilder::new()
                    .string("account_id", request.account_id.clone())
                    .build(),
                options,
            )
            .await
    }
}