rive_http/servers/
server_members.rs1use crate::prelude::*;
2use rive_models::{
3 channel::PartialInvite,
4 data::{BanUserData, EditMemberData, FetchMembersData},
5 member::{Member, MemberList},
6 server::{BanList, ServerBan},
7};
8
9impl Client {
10 pub async fn fetch_members(
12 &self,
13 server_id: impl Into<String>,
14 data: FetchMembersData,
15 ) -> Result<MemberList> {
16 Ok(self
17 .client
18 .get(ep!(self, "/servers/{}/members", server_id.into()))
19 .query(&data)
20 .auth(&self.authentication)
21 .send()
22 .await?
23 .process_error()
24 .await?
25 .json()
26 .await?)
27 }
28
29 pub async fn fetch_member(
31 &self,
32 server_id: impl Into<String>,
33 member_id: impl Into<String>,
34 ) -> Result<Member> {
35 Ok(self
36 .client
37 .get(ep!(
38 self,
39 "/servers/{}/members/{}",
40 server_id.into(),
41 member_id.into()
42 ))
43 .auth(&self.authentication)
44 .send()
45 .await?
46 .process_error()
47 .await?
48 .json()
49 .await?)
50 }
51
52 pub async fn kick_member(
54 &self,
55 server_id: impl Into<String>,
56 member_id: impl Into<String>,
57 ) -> Result<()> {
58 self.client
59 .delete(ep!(
60 self,
61 "/servers/{}/members/{}",
62 server_id.into(),
63 member_id.into()
64 ))
65 .auth(&self.authentication)
66 .send()
67 .await?
68 .process_error()
69 .await?;
70 Ok(())
71 }
72
73 pub async fn edit_member(
75 &self,
76 server_id: impl Into<String>,
77 member_id: impl Into<String>,
78 data: EditMemberData,
79 ) -> Result<Member> {
80 Ok(self
81 .client
82 .patch(ep!(
83 self,
84 "/servers/{}/members/{}",
85 server_id.into(),
86 member_id.into()
87 ))
88 .json(&data)
89 .auth(&self.authentication)
90 .send()
91 .await?
92 .process_error()
93 .await?
94 .json()
95 .await?)
96 }
97
98 pub async fn ban_user(
100 &self,
101 server_id: impl Into<String>,
102 user_id: impl Into<String>,
103 data: BanUserData,
104 ) -> Result<ServerBan> {
105 Ok(self
106 .client
107 .put(ep!(
108 self,
109 "/servers/{}/bans/{}",
110 server_id.into(),
111 user_id.into()
112 ))
113 .json(&data)
114 .auth(&self.authentication)
115 .send()
116 .await?
117 .process_error()
118 .await?
119 .json()
120 .await?)
121 }
122
123 pub async fn unban_user(
125 &self,
126 server_id: impl Into<String>,
127 user_id: impl Into<String>,
128 ) -> Result<()> {
129 self.client
130 .delete(ep!(
131 self,
132 "/servers/{}/bans/{}",
133 server_id.into(),
134 user_id.into()
135 ))
136 .auth(&self.authentication)
137 .send()
138 .await?
139 .process_error()
140 .await?
141 .json()
142 .await?;
143 Ok(())
144 }
145
146 pub async fn fetch_bans(&self, server_id: impl Into<String>) -> Result<BanList> {
148 Ok(self
149 .client
150 .get(ep!(self, "/servers/{}/bans", server_id.into()))
151 .auth(&self.authentication)
152 .send()
153 .await?
154 .process_error()
155 .await?
156 .json()
157 .await?)
158 }
159
160 pub async fn fetch_invites(&self, server_id: impl Into<String>) -> Result<PartialInvite> {
162 Ok(self
163 .client
164 .get(ep!(self, "/servers/{}/invites", server_id.into()))
165 .auth(&self.authentication)
166 .send()
167 .await?
168 .process_error()
169 .await?
170 .json()
171 .await?)
172 }
173}