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 PermissionsClient {
    pub http_client: HttpClient,
}

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

    /// Lists permission actions and whether the calling credential is granted each one for a resource. Answers for whichever identity authenticated the request — a user session, an OAuth token, or an account or app API key — so it never describes who else can reach the resource.
    ///
    /// # Arguments
    ///
    /// * `resource_id` - Tag of the resource to check against: an account (`biz_`), product (`prod_`), experience (`exp_`), or app (`app_`). A resource the credential cannot see is reported as granted nothing rather than as an error.
    /// * `actions` - Comma-separated permission actions to check, for example `stats:read,payment:basic:read`. Every action is returned when omitted.
    /// * `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
    ///         .permissions
    ///         .list(
    ///             &PermissionsListQueryRequest {
    ///                 resource_id: "resource_id".to_string(),
    ///                 actions: None,
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn list(
        &self,
        request: &PermissionsListQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<ListPermissionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                "permissions",
                None,
                QueryBuilder::new()
                    .string("resource_id", request.resource_id.clone())
                    .string("actions", request.actions.clone())
                    .build(),
                options,
            )
            .await
    }
}