rive_http/servers/
server_information.rs1use crate::prelude::*;
2use rive_models::{
3 channel::Channel,
4 data::{CreateChannelData, CreateServerData, EditServerData},
5 server::Server,
6};
7
8impl Client {
9 pub async fn create_server(&self, data: CreateServerData) -> Result<Server> {
11 Ok(self
12 .client
13 .post(ep!(self, "/servers/create"))
14 .json(&data)
15 .auth(&self.authentication)
16 .send()
17 .await?
18 .process_error()
19 .await?
20 .json()
21 .await?)
22 }
23
24 pub async fn fetch_server(&self, id: impl Into<String>) -> Result<Server> {
26 Ok(self
27 .client
28 .get(ep!(self, "/servers/{}", id.into()))
29 .auth(&self.authentication)
30 .send()
31 .await?
32 .process_error()
33 .await?
34 .json()
35 .await?)
36 }
37
38 pub async fn delete_or_leave_server(&self, id: impl Into<String>) -> Result<()> {
40 self.client
41 .delete(ep!(self, "/servers/{}", id.into()))
42 .auth(&self.authentication)
43 .send()
44 .await?
45 .process_error()
46 .await?
47 .json()
48 .await?;
49 Ok(())
50 }
51
52 pub async fn edit_server(&self, id: impl Into<String>, data: EditServerData) -> Result<Server> {
54 Ok(self
55 .client
56 .patch(ep!(self, "/servers/{}", id.into()))
57 .json(&data)
58 .auth(&self.authentication)
59 .send()
60 .await?
61 .process_error()
62 .await?
63 .json()
64 .await?)
65 }
66
67 pub async fn mark_server_as_read(&self, id: impl Into<String>) -> Result<()> {
69 self.client
70 .put(ep!(self, "/servers/{}/ack", id.into()))
71 .auth(&self.authentication)
72 .send()
73 .await?
74 .process_error()
75 .await?
76 .json()
77 .await?;
78 Ok(())
79 }
80
81 pub async fn create_channel(
83 &self,
84 server_id: impl Into<String>,
85 data: CreateChannelData,
86 ) -> Result<Channel> {
87 Ok(self
88 .client
89 .post(ep!(self, "/servers/{}/channels", server_id.into()))
90 .json(&data)
91 .auth(&self.authentication)
92 .send()
93 .await?
94 .process_error()
95 .await?
96 .json()
97 .await?)
98 }
99}