use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct ThreadsClient {
pub http_client: HttpClient,
}
impl ThreadsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
pub async fn list_all_threads(
&self,
request: &ListAllThreadsQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetThreadsResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"threads",
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_thread(
&self,
request: &PostThreadsRequest,
options: Option<RequestOptions>,
) -> Result<PostThreadsResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"threads",
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
pub async fn get_a_thread(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDResponse, ApiError> {
self.http_client
.execute_request(Method::GET, &format!("threads/{}", id), None, None, options)
.await
}
pub async fn delete_a_thread(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteThreadsIDResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("threads/{}", id),
None,
None,
options,
)
.await
}
pub async fn update_a_thread(
&self,
id: &String,
request: &PatchThreadsIDRequest,
options: Option<RequestOptions>,
) -> Result<PatchThreadsIDResponse, ApiError> {
self.http_client
.execute_request(
Method::PATCH,
&format!("threads/{}", id),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
pub async fn list_thread_posts(
&self,
id: &String,
request: &ListThreadPostsQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDPostsResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/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_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDPostsSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/posts/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn delete_a_post_from_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteThreadsIDPostsSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("threads/{}/posts/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn list_thread_reactions(
&self,
id: &String,
request: &ListThreadReactionsQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDReactionsResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/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_thread(
&self,
id: &String,
request: &PostThreadsIDReactionsRequest,
options: Option<RequestOptions>,
) -> Result<PostThreadsIDReactionsResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("threads/{}/reactions", id),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
pub async fn remove_your_reaction_from_thread(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteThreadsIDReactionsResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("threads/{}/reactions", id),
None,
None,
options,
)
.await
}
pub async fn get_a_reaction_from_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDReactionsSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/reactions/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn delete_a_reaction_from_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteThreadsIDReactionsSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("threads/{}/reactions/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn list_thread_subscribers(
&self,
id: &String,
request: &ListThreadSubscribersQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDSubscribersResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/subscribers", id),
None,
QueryBuilder::new()
.string("cursor", request.cursor.clone())
.int("limit", request.limit.clone())
.build(),
options,
)
.await
}
pub async fn get_a_subscriber_from_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDSubscribersSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/subscribers/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn delete_a_subscriber_from_thread(
&self,
id: &String,
sub_id: &String,
options: Option<RequestOptions>,
) -> Result<DeleteThreadsIDSubscribersSubIDResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("threads/{}/subscribers/{}", id, sub_id),
None,
None,
options,
)
.await
}
pub async fn get_thread_poll(
&self,
id: &String,
options: Option<RequestOptions>,
) -> Result<GetThreadsIDPollResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("threads/{}/poll", id),
None,
None,
options,
)
.await
}
pub async fn create_thread_poll(
&self,
id: &String,
request: &PostThreadsIDPollRequest,
options: Option<RequestOptions>,
) -> Result<PostThreadsIDPollResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("threads/{}/poll", id),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
pub async fn update_thread_poll(
&self,
id: &String,
request: &PatchThreadsIDPollRequest,
options: Option<RequestOptions>,
) -> Result<PatchThreadsIDPollResponse, ApiError> {
self.http_client
.execute_request(
Method::PATCH,
&format!("threads/{}/poll", id),
Some(serde_json::to_value(request).unwrap_or_default()),
None,
options,
)
.await
}
}