1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::prelude::*;
use rive_models::{channel::Channel, payload::EditChannelPayload};

impl Client {
    /// Fetch channel by its ID.
    pub async fn fetch_channel(&self, id: impl Into<String>) -> Result<Channel> {
        Ok(self
            .client
            .get(ep!(self, "/channels/{}", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Deletes a server channel, leaves a group or closes a group.
    pub async fn close_channel(&self, id: impl Into<String>) -> Result<()> {
        self.client
            .delete(ep!(self, "/channels/{}", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }

    /// Edit a channel object by its id.
    pub async fn edit_channel(
        &self,
        id: impl Into<String>,
        payload: EditChannelPayload,
    ) -> Result<Channel> {
        Ok(self
            .client
            .patch(ep!(self, "/channels/{}", id.into()))
            .auth(&self.authentication)
            .json(&payload)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }
}