use crate::error::MisarDevError;
use crate::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::build_query;
use crate::transport::encode_path;
use reqwest::Method;
use serde_json::Value;
#[derive(Debug, Clone, Copy)]
pub struct PostsResource<'a> {
pub(crate) t: &'a Transport,
}
impl PostsResource<'_> {
pub async fn create(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/posts", "", Some(body_or_empty(body))).await
}
pub async fn create_comment(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/posts/{}/comments", encode_path(id)), "", Some(body_or_empty(body))).await
}
pub async fn get(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/posts/{}", encode_path(id)), "", None).await
}
pub async fn like(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/posts/{}/like", encode_path(id)), "", None).await
}
pub async fn list(self, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/posts", &build_query(query.as_ref(), &[]), None).await
}
pub async fn list_comments(self, id: &str, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/posts/{}/comments", encode_path(id)), &build_query(query.as_ref(), &[]), None).await
}
pub async fn list_saved(self, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/me/saved", &build_query(query.as_ref(), &[]), None).await
}
pub async fn save(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/posts/{}/save", encode_path(id)), "", Some(body_or_empty(body))).await
}
pub async fn share_to_dm(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/posts/{}/share-dm", encode_path(id)), "", Some(body_or_empty(body))).await
}
pub async fn unlike(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/posts/{}/like", encode_path(id)), "", None).await
}
pub async fn unsave(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/posts/{}/save", encode_path(id)), "", None).await
}
pub async fn update(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::PATCH, &format!("/posts/{}", encode_path(id)), "", Some(body_or_empty(body))).await
}
}