use reqwest::Client;
use serde_json::to_string;
use crate::{
errors::ChorusResult,
instance::ChorusUser,
ratelimiter::ChorusRequest,
types::{Channel, LimitType, PrivateChannelCreateSchema},
};
impl ChorusUser {
pub async fn get_private_channels(&mut self) -> ChorusResult<Vec<Channel>> {
let url = format!(
"{}/users/@me/channels",
self.belongs_to.read().unwrap().urls.api
);
ChorusRequest {
request: Client::new().get(url),
limit_type: LimitType::Global,
}
.with_headers_for(self)
.send_and_deserialize_response::<Vec<Channel>>(self)
.await
}
pub async fn create_private_channel(
&mut self,
create_private_channel_schema: PrivateChannelCreateSchema,
) -> ChorusResult<Channel> {
let url = format!(
"{}/users/@me/channels",
self.belongs_to.read().unwrap().urls.api
);
ChorusRequest {
request: Client::new().post(url).json(&create_private_channel_schema),
limit_type: LimitType::Global,
}
.with_headers_for(self)
.send_and_deserialize_response::<Channel>(self)
.await
}
}