slack_chat_api/
files.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Files {
5    pub client: Client,
6}
7
8impl Files {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Files { client }
12    }
13
14    /**
15     * This function performs a `POST` to the `/files.delete` endpoint.
16     *
17     * Deletes a file.
18     *
19     * FROM: <https://api.slack.com/methods/files.delete>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `files:write:user`.
24     */
25    pub async fn delete(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
26        let url = self.client.url("/files.delete", None);
27        self.client
28            .post(
29                &url,
30                crate::Message {
31                    body: None,
32                    content_type: Some("application/x-www-form-urlencoded".to_string()),
33                },
34            )
35            .await
36    }
37    /**
38     * This function performs a `GET` to the `/files.info` endpoint.
39     *
40     * Gets information about a file.
41     *
42     * FROM: <https://api.slack.com/methods/files.info>
43     *
44     * **Parameters:**
45     *
46     * * `token: &str` -- Authentication token. Requires scope: `files:read`.
47     * * `file: &str` -- Specify a file by providing its ID.
48     * * `count: &str`
49     * * `page: &str`
50     * * `limit: i64` -- The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the list hasn't been reached.
51     * * `cursor: &str` -- Parameter for pagination. File comments are paginated for a single file. Set `cursor` equal to the `next_cursor` attribute returned by the previous request's `response_metadata`. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection of comments. See [pagination](/docs/pagination) for more details.
52     */
53    pub async fn info(
54        &self,
55        file: &str,
56        count: &str,
57        page: &str,
58        limit: i64,
59        cursor: &str,
60    ) -> ClientResult<crate::Response<crate::types::FilesInfoSchema>> {
61        let mut query_args: Vec<(String, String)> = Default::default();
62        if !count.is_empty() {
63            query_args.push(("count".to_string(), count.to_string()));
64        }
65        if !cursor.is_empty() {
66            query_args.push(("cursor".to_string(), cursor.to_string()));
67        }
68        if !file.is_empty() {
69            query_args.push(("file".to_string(), file.to_string()));
70        }
71        if limit > 0 {
72            query_args.push(("limit".to_string(), limit.to_string()));
73        }
74        if !page.is_empty() {
75            query_args.push(("page".to_string(), page.to_string()));
76        }
77        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
78        let url = self.client.url(&format!("/files.info?{}", query_), None);
79        self.client
80            .get(
81                &url,
82                crate::Message {
83                    body: None,
84                    content_type: None,
85                },
86            )
87            .await
88    }
89    /**
90     * This function performs a `GET` to the `/files.list` endpoint.
91     *
92     * List for a team, in a channel, or from a user with applied filters.
93     *
94     * FROM: <https://api.slack.com/methods/files.list>
95     *
96     * **Parameters:**
97     *
98     * * `token: &str` -- Authentication token. Requires scope: `files:read`.
99     * * `user: &str` -- Filter files created by a single user.
100     * * `channel: &str` -- Filter files appearing in a specific channel, indicated by its ID.
101     * * `ts_from: f64` -- Filter files created after this timestamp (inclusive).
102     * * `ts_to: f64` -- Filter files created before this timestamp (inclusive).
103     * * `types: &str` -- Filter files by type ([see below](#file_types)). You can pass multiple values in the types argument, like `types=spaces,snippets`.The default value is `all`, which does not filter the list.
104     * * `count: &str`
105     * * `page: &str`
106     * * `show_files_hidden_by_limit: bool` -- Show truncated file info for files hidden due to being too old, and the team who owns the file being over the file limit.
107     */
108    pub async fn list(
109        &self,
110        user: &str,
111        channel: &str,
112        ts_from: f64,
113        ts_to: f64,
114        types: &str,
115        count: &str,
116        page: &str,
117        show_files_hidden_by_limit: bool,
118    ) -> ClientResult<crate::Response<crate::types::FilesListSchema>> {
119        let mut query_args: Vec<(String, String)> = Default::default();
120        if !channel.is_empty() {
121            query_args.push(("channel".to_string(), channel.to_string()));
122        }
123        if !count.is_empty() {
124            query_args.push(("count".to_string(), count.to_string()));
125        }
126        if !page.is_empty() {
127            query_args.push(("page".to_string(), page.to_string()));
128        }
129        if show_files_hidden_by_limit {
130            query_args.push((
131                "show_files_hidden_by_limit".to_string(),
132                show_files_hidden_by_limit.to_string(),
133            ));
134        }
135        if !ts_from.to_string().is_empty() {
136            query_args.push(("ts_from".to_string(), ts_from.to_string()));
137        }
138        if !ts_to.to_string().is_empty() {
139            query_args.push(("ts_to".to_string(), ts_to.to_string()));
140        }
141        if !types.is_empty() {
142            query_args.push(("types".to_string(), types.to_string()));
143        }
144        if !user.is_empty() {
145            query_args.push(("user".to_string(), user.to_string()));
146        }
147        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
148        let url = self.client.url(&format!("/files.list?{}", query_), None);
149        self.client
150            .get(
151                &url,
152                crate::Message {
153                    body: None,
154                    content_type: None,
155                },
156            )
157            .await
158    }
159    /**
160     * This function performs a `POST` to the `/files.revokePublicURL` endpoint.
161     *
162     * Revokes public/external sharing access for a file
163     *
164     * FROM: <https://api.slack.com/methods/files.revokePublicURL>
165     *
166     * **Parameters:**
167     *
168     * * `token: &str` -- Authentication token. Requires scope: `files:write:user`.
169     */
170    pub async fn revoke_public_url(
171        &self,
172    ) -> ClientResult<crate::Response<crate::types::FilesUploadSchema>> {
173        let url = self.client.url("/files.revokePublicURL", None);
174        self.client
175            .post(
176                &url,
177                crate::Message {
178                    body: None,
179                    content_type: Some("application/x-www-form-urlencoded".to_string()),
180                },
181            )
182            .await
183    }
184    /**
185     * This function performs a `POST` to the `/files.sharedPublicURL` endpoint.
186     *
187     * Enables a file for public/external sharing.
188     *
189     * FROM: <https://api.slack.com/methods/files.sharedPublicURL>
190     *
191     * **Parameters:**
192     *
193     * * `token: &str` -- Authentication token. Requires scope: `files:write:user`.
194     */
195    pub async fn shared_public_url(
196        &self,
197    ) -> ClientResult<crate::Response<crate::types::FilesUploadSchema>> {
198        let url = self.client.url("/files.sharedPublicURL", None);
199        self.client
200            .post(
201                &url,
202                crate::Message {
203                    body: None,
204                    content_type: Some("application/x-www-form-urlencoded".to_string()),
205                },
206            )
207            .await
208    }
209    /**
210     * This function performs a `POST` to the `/files.upload` endpoint.
211     *
212     * Uploads or creates a file.
213     *
214     * FROM: <https://api.slack.com/methods/files.upload>
215     */
216    pub async fn upload(&self) -> ClientResult<crate::Response<crate::types::FilesUploadSchema>> {
217        let url = self.client.url("/files.upload", None);
218        self.client
219            .post(
220                &url,
221                crate::Message {
222                    body: None,
223                    content_type: Some("application/x-www-form-urlencoded".to_string()),
224                },
225            )
226            .await
227    }
228}