slack_chat_api/
usergroups.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Usergroups {
5    pub client: Client,
6}
7
8impl Usergroups {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Usergroups { client }
12    }
13
14    /**
15     * This function performs a `POST` to the `/usergroups.create` endpoint.
16     *
17     * Create a User Group
18     *
19     * FROM: <https://api.slack.com/methods/usergroups.create>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `usergroups:write`.
24     */
25    pub async fn create(
26        &self,
27    ) -> ClientResult<crate::Response<crate::types::UsergroupsCreateSchema>> {
28        let url = self.client.url("/usergroups.create", None);
29        self.client
30            .post(
31                &url,
32                crate::Message {
33                    body: None,
34                    content_type: Some("application/x-www-form-urlencoded".to_string()),
35                },
36            )
37            .await
38    }
39    /**
40     * This function performs a `POST` to the `/usergroups.disable` endpoint.
41     *
42     * Disable an existing User Group
43     *
44     * FROM: <https://api.slack.com/methods/usergroups.disable>
45     *
46     * **Parameters:**
47     *
48     * * `token: &str` -- Authentication token. Requires scope: `usergroups:write`.
49     */
50    pub async fn disable(
51        &self,
52    ) -> ClientResult<crate::Response<crate::types::UsergroupsCreateSchema>> {
53        let url = self.client.url("/usergroups.disable", None);
54        self.client
55            .post(
56                &url,
57                crate::Message {
58                    body: None,
59                    content_type: Some("application/x-www-form-urlencoded".to_string()),
60                },
61            )
62            .await
63    }
64    /**
65     * This function performs a `POST` to the `/usergroups.enable` endpoint.
66     *
67     * Enable a User Group
68     *
69     * FROM: <https://api.slack.com/methods/usergroups.enable>
70     *
71     * **Parameters:**
72     *
73     * * `token: &str` -- Authentication token. Requires scope: `usergroups:write`.
74     */
75    pub async fn enable(
76        &self,
77    ) -> ClientResult<crate::Response<crate::types::UsergroupsCreateSchema>> {
78        let url = self.client.url("/usergroups.enable", None);
79        self.client
80            .post(
81                &url,
82                crate::Message {
83                    body: None,
84                    content_type: Some("application/x-www-form-urlencoded".to_string()),
85                },
86            )
87            .await
88    }
89    /**
90     * This function performs a `GET` to the `/usergroups.list` endpoint.
91     *
92     * List all User Groups for a team
93     *
94     * FROM: <https://api.slack.com/methods/usergroups.list>
95     *
96     * **Parameters:**
97     *
98     * * `include_users: bool` -- Include the list of users for each User Group.
99     * * `token: &str` -- Authentication token. Requires scope: `usergroups:read`.
100     * * `include_count: bool` -- Include the number of users in each User Group.
101     * * `include_disabled: bool` -- Include disabled User Groups.
102     */
103    pub async fn list(
104        &self,
105        include_users: bool,
106        include_count: bool,
107        include_disabled: bool,
108    ) -> ClientResult<crate::Response<crate::types::UsergroupsListSchema>> {
109        let mut query_args: Vec<(String, String)> = Default::default();
110        if include_count {
111            query_args.push(("include_count".to_string(), include_count.to_string()));
112        }
113        if include_disabled {
114            query_args.push(("include_disabled".to_string(), include_disabled.to_string()));
115        }
116        if include_users {
117            query_args.push(("include_users".to_string(), include_users.to_string()));
118        }
119        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
120        let url = self
121            .client
122            .url(&format!("/usergroups.list?{}", query_), None);
123        self.client
124            .get(
125                &url,
126                crate::Message {
127                    body: None,
128                    content_type: None,
129                },
130            )
131            .await
132    }
133    /**
134     * This function performs a `POST` to the `/usergroups.update` endpoint.
135     *
136     * Update an existing User Group
137     *
138     * FROM: <https://api.slack.com/methods/usergroups.update>
139     *
140     * **Parameters:**
141     *
142     * * `token: &str` -- Authentication token. Requires scope: `usergroups:write`.
143     */
144    pub async fn update(
145        &self,
146    ) -> ClientResult<crate::Response<crate::types::UsergroupsCreateSchema>> {
147        let url = self.client.url("/usergroups.update", None);
148        self.client
149            .post(
150                &url,
151                crate::Message {
152                    body: None,
153                    content_type: Some("application/x-www-form-urlencoded".to_string()),
154                },
155            )
156            .await
157    }
158}