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 mod submissions;
pub use submissions::SubmissionsClient;
pub struct BountiesClient {
    pub http_client: HttpClient,
    pub submissions: SubmissionsClient,
}

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

    /// Lists bounties visible to the credential — for an account API key, the account's bounties including scheduled drafts; for a user token, the bounties the user can see and work.
    ///
    /// # Arguments
    ///
    /// * `account_id` - Scope the list to this account (`biz_` tag). Requires read access to the account; account API keys may pass their own account or a connected account.
    /// * `user_id` - List the bounties this user participated in (`user_` tag). Must be the authenticated user.
    /// * `status` - Filter by lifecycle state.
    /// * `business_goal_type` - Filter by the poster's declared goal. Bounties created before the goal taxonomy carry no goal and never match this filter.
    /// * `country` - Only bounties workable from this country, as an ISO 3166-1 alpha-2 code. Bounties with no country targeting are workable worldwide and always match.
    /// * `experience_id` - Only bounties posted to this forum experience, prefixed `exp_`. An unknown experience, or one outside the caller's scope, matches nothing.
    /// * `query` - Substring match on the bounty title or ID.
    /// * `created_after` - Only bounties created after this ISO 8601 timestamp.
    /// * `created_before` - Only bounties created before this ISO 8601 timestamp.
    /// * `order` - Sort field.
    /// * `direction` - Sort direction.
    /// * `first` - Number of bounties to return from the start of the window.
    /// * `after` - Cursor to paginate forwards from.
    /// * `last` - Number of bounties to return from the end of the window.
    /// * `before` - Cursor to paginate backwards from.
    /// * `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
    ///         .bounties
    ///         .list(
    ///             &BountiesListQueryRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn list(
        &self,
        request: &BountiesListQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<ListBountiesResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                "bounties",
                None,
                QueryBuilder::new()
                    .string("account_id", request.account_id.clone())
                    .string("user_id", request.user_id.clone())
                    .serialize("status", request.status.clone())
                    .serialize("business_goal_type", request.business_goal_type.clone())
                    .string("country", request.country.clone())
                    .string("experience_id", request.experience_id.clone())
                    .structured_query("query", request.query.clone())
                    .string("created_after", request.created_after.clone())
                    .string("created_before", request.created_before.clone())
                    .serialize("order", request.order.clone())
                    .serialize("direction", request.direction.clone())
                    .int("first", request.first.clone())
                    .string("after", request.after.clone())
                    .int("last", request.last.clone())
                    .string("before", request.before.clone())
                    .build(),
                options,
            )
            .await
    }

    /// Creates a bounty and escrows its reward pool. Publishes immediately, or as a scheduled draft when you set `publish_at`.
    ///
    /// # Arguments
    ///
    /// * `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.bounties.create(&CreateBountiesRequest {
    ///         description: "Record one continuous pass of a full interior detail, dash to trunk, on a customer vehicle.".to_string(),
    ///         gross_reward_amount: 40.0,
    ///         title: "Record interior detailing passes".to_string(),
    ///         accepted_submissions_limit: None,
    ///         accepted_submissions_per_user_limit: None,
    ///         account_id: None,
    ///         allowed_country_codes: None,
    ///         business_goal_type: None,
    ///         capture_spec: None,
    ///         experience_id: None,
    ///         frequency: None,
    ///         publish_at: None,
    ///         publish_at_timezone: None
    ///     }, None).await;
    /// }
    /// ```
    pub async fn create(
        &self,
        request: &CreateBountiesRequest,
        options: Option<RequestOptions>,
    ) -> Result<Bounty, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                "bounties",
                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
                None,
                options,
            )
            .await
    }

    /// Retrieves a bounty by ID. Authentication is optional: a request with no credential reads the bounty when it is publicly visible — published or completed, and not restricted to a private experience's members. Bounties outside the caller's scope, and bounties not publicly visible to an anonymous caller, return `404`.
    ///
    /// # Arguments
    ///
    /// * `id` - Bounty ID (`bnty_` tag).
    /// * `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.bounties.retrieve(&"id".to_string(), None).await;
    /// }
    /// ```
    pub async fn retrieve(
        &self,
        id: &str,
        options: Option<RequestOptions>,
    ) -> Result<Bounty, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("bounties/{}", id),
                None,
                None,
                options,
            )
            .await
    }

    /// Updates a bounty. A published bounty accepts title, description, and country targeting while it is still open with nothing under review. A scheduled (not-yet-published) draft additionally accepts the reward, winner slots, and schedule.
    ///
    /// # Arguments
    ///
    /// * `id` - Bounty ID (`bnty_` tag).
    /// * `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
    ///         .bounties
    ///         .update(
    ///             &"id".to_string(),
    ///             &UpdateBountiesRequest {
    ///                 ..Default::default()
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn update(
        &self,
        id: &str,
        request: &UpdateBountiesRequest,
        options: Option<RequestOptions>,
    ) -> Result<Bounty, ApiError> {
        self.http_client
            .execute_request(
                Method::PATCH,
                &format!("bounties/{}", id),
                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
                None,
                options,
            )
            .await
    }

    /// Cancels a bounty. With no in-flight work, it cancels immediately and refunds the funder. Otherwise it stops new submissions and cancels once the in-flight work resolves and pays out. Repeating the request is a no-op. A bounty that already paid out every slot returns `400`.
    ///
    /// # Arguments
    ///
    /// * `id` - Bounty ID (`bnty_` tag).
    /// * `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.bounties.cancel(&"id".to_string(), None).await;
    /// }
    /// ```
    pub async fn cancel(
        &self,
        id: &str,
        options: Option<RequestOptions>,
    ) -> Result<Bounty, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                &format!("bounties/{}/cancel", id),
                None,
                None,
                options,
            )
            .await
    }
}