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 ProfileResource<'a> {
pub(crate) t: &'a Transport,
}
impl ProfileResource<'_> {
pub async fn block(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/blocks/{}", encode_path(handle)), "", None).await
}
pub async fn follow(self, handle: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/follow/{}", encode_path(handle)), "", Some(body_or_empty(body))).await
}
pub async fn get(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/profile/{}", encode_path(handle)), "", None).await
}
pub async fn get_highlight(self, handle: &str, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/profile/{}/highlights/{}", encode_path(handle), encode_path(id)), "", None).await
}
pub async fn list_blocks(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/blocks", "", None).await
}
pub async fn list_connections(self, handle: &str, list: &str, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/profile/{}/{}", encode_path(handle), encode_path(list)), &build_query(query.as_ref(), &[]), None).await
}
pub async fn list_highlights(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/profile/{}/highlights", encode_path(handle)), "", None).await
}
pub async fn mute(self, handle: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/mutes/{}", encode_path(handle)), "", Some(body_or_empty(body))).await
}
pub async fn unblock(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/blocks/{}", encode_path(handle)), "", None).await
}
pub async fn unfollow(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/follow/{}", encode_path(handle)), "", None).await
}
pub async fn unmute(self, handle: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/mutes/{}", encode_path(handle)), "", None).await
}
}