use crate::prelude::*;
use rive_models::{
channel::Channel,
payload::{CreateChannelPayload, CreateServerPayload, EditServerPayload},
server::Server,
};
impl Client {
pub async fn create_server(&self, payload: CreateServerPayload) -> Result<Server> {
Ok(self
.client
.post(ep!(self, "/servers/create"))
.json(&payload)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn fetch_server(&self, id: impl Into<String>) -> Result<Server> {
Ok(self
.client
.get(ep!(self, "/servers/{}", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn delete_or_leave_server(&self, id: impl Into<String>) -> Result<()> {
self.client
.delete(ep!(self, "/servers/{}", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?;
Ok(())
}
pub async fn edit_server(
&self,
id: impl Into<String>,
payload: EditServerPayload,
) -> Result<Server> {
Ok(self
.client
.patch(ep!(self, "/servers/{}", id.into()))
.json(&payload)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn mark_server_as_read(&self, id: impl Into<String>) -> Result<()> {
self.client
.put(ep!(self, "/servers/{}/ack", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?;
Ok(())
}
pub async fn create_channel(
&self,
server_id: impl Into<String>,
payload: CreateChannelPayload,
) -> Result<Channel> {
Ok(self
.client
.post(ep!(self, "/servers/{}/channels", server_id.into()))
.json(&payload)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
}