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

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

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

    pub async fn create_a_post(
        &self,
        request: &PostPostsRequest,
        options: Option<RequestOptions>,
    ) -> Result<PostPostsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                "posts",
                Some(serde_json::to_value(request).unwrap_or_default()),
                None,
                options,
            )
            .await
    }

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

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

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

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

    pub async fn create_a_reaction_in_post(
        &self,
        id: &String,
        request: &PostPostsIDReactionsRequest,
        options: Option<RequestOptions>,
    ) -> Result<PostPostsIDReactionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                &format!("posts/{}/reactions", id),
                Some(serde_json::to_value(request).unwrap_or_default()),
                None,
                options,
            )
            .await
    }

    /// Removes the authenticated user's reaction. No subId needed.
    ///
    /// # Arguments
    ///
    /// * `id` - Post ID
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    pub async fn remove_your_reaction_from_post(
        &self,
        id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeletePostsIDReactionsResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("posts/{}/reactions", id),
                None,
                None,
                options,
            )
            .await
    }

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

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

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

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

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