foru_ms_sdk 0.0.40

SDK for the Foru.ms API
Documentation
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;

pub struct UsersClient {
    pub http_client: HttpClient,
}

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

    pub async fn list_all_users(
        &self,
        request: &ListAllUsersQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                "users",
                None,
                QueryBuilder::new()
                    .int("page", request.page.clone())
                    .int("limit", request.limit.clone())
                    .string("search", request.search.clone())
                    .build(),
                options,
            )
            .await
    }

    pub async fn get_a_user(
        &self,
        id: &String,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersIDResponse, ApiError> {
        self.http_client
            .execute_request(Method::GET, &format!("users/{}", id), None, None, options)
            .await
    }

    pub async fn delete_a_user(
        &self,
        id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeleteUsersIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("users/{}", id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn update_a_user(
        &self,
        id: &String,
        request: &PatchUsersIDRequest,
        options: Option<RequestOptions>,
    ) -> Result<PatchUsersIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::PATCH,
                &format!("users/{}", id),
                Some(serde_json::to_value(request).unwrap_or_default()),
                None,
                options,
            )
            .await
    }

    pub async fn list_user_followers(
        &self,
        id: &String,
        request: &ListUserFollowersQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersIDFollowersResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("users/{}/followers", id),
                None,
                QueryBuilder::new()
                    .string("cursor", request.cursor.clone())
                    .int("limit", request.limit.clone())
                    .build(),
                options,
            )
            .await
    }

    pub async fn get_a_follower_from_user(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersIDFollowersSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("users/{}/followers/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn delete_a_follower_from_user(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeleteUsersIDFollowersSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("users/{}/followers/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn list_user_following(
        &self,
        id: &String,
        request: &ListUserFollowingQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersIDFollowingResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("users/{}/following", id),
                None,
                QueryBuilder::new()
                    .string("cursor", request.cursor.clone())
                    .int("limit", request.limit.clone())
                    .build(),
                options,
            )
            .await
    }

    pub async fn get_a_following_from_user(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<GetUsersIDFollowingSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("users/{}/following/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn delete_a_following_from_user(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeleteUsersIDFollowingSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("users/{}/following/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }
}