slack_chat_api/files_remote.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct FilesRemote {
5 pub client: Client,
6}
7
8impl FilesRemote {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 FilesRemote { client }
12 }
13
14 /**
15 * This function performs a `POST` to the `/files.remote.add` endpoint.
16 *
17 * Adds a file from a remote service
18 *
19 * FROM: <https://api.slack.com/methods/files.remote.add>
20 */
21 pub async fn add(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
22 let url = self.client.url("/files.remote.add", None);
23 self.client
24 .post(
25 &url,
26 crate::Message {
27 body: None,
28 content_type: Some("application/x-www-form-urlencoded".to_string()),
29 },
30 )
31 .await
32 }
33 /**
34 * This function performs a `GET` to the `/files.remote.info` endpoint.
35 *
36 * Retrieve information about a remote file added to Slack
37 *
38 * FROM: <https://api.slack.com/methods/files.remote.info>
39 *
40 * **Parameters:**
41 *
42 * * `token: &str` -- Authentication token. Requires scope: `remote_files:read`.
43 * * `file: &str` -- Specify a file by providing its ID.
44 * * `external_id: &str` -- Creator defined GUID for the file.
45 */
46 pub async fn info(
47 &self,
48 file: &str,
49 external_id: &str,
50 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
51 let mut query_args: Vec<(String, String)> = Default::default();
52 if !external_id.is_empty() {
53 query_args.push(("external_id".to_string(), external_id.to_string()));
54 }
55 if !file.is_empty() {
56 query_args.push(("file".to_string(), file.to_string()));
57 }
58 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
59 let url = self
60 .client
61 .url(&format!("/files.remote.info?{}", query_), None);
62 self.client
63 .get(
64 &url,
65 crate::Message {
66 body: None,
67 content_type: None,
68 },
69 )
70 .await
71 }
72 /**
73 * This function performs a `GET` to the `/files.remote.list` endpoint.
74 *
75 * Retrieve information about a remote file added to Slack
76 *
77 * FROM: <https://api.slack.com/methods/files.remote.list>
78 *
79 * **Parameters:**
80 *
81 * * `token: &str` -- Authentication token. Requires scope: `remote_files:read`.
82 * * `channel: &str` -- Filter files appearing in a specific channel, indicated by its ID.
83 * * `ts_from: f64` -- Filter files created after this timestamp (inclusive).
84 * * `ts_to: f64` -- Filter files created before this timestamp (inclusive).
85 * * `limit: i64` -- The maximum number of items to return.
86 * * `cursor: &str` -- Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
87 */
88 pub async fn list(
89 &self,
90 channel: &str,
91 ts_from: f64,
92 ts_to: f64,
93 limit: i64,
94 cursor: &str,
95 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
96 let mut query_args: Vec<(String, String)> = Default::default();
97 if !channel.is_empty() {
98 query_args.push(("channel".to_string(), channel.to_string()));
99 }
100 if !cursor.is_empty() {
101 query_args.push(("cursor".to_string(), cursor.to_string()));
102 }
103 if limit > 0 {
104 query_args.push(("limit".to_string(), limit.to_string()));
105 }
106 if !ts_from.to_string().is_empty() {
107 query_args.push(("ts_from".to_string(), ts_from.to_string()));
108 }
109 if !ts_to.to_string().is_empty() {
110 query_args.push(("ts_to".to_string(), ts_to.to_string()));
111 }
112 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
113 let url = self
114 .client
115 .url(&format!("/files.remote.list?{}", query_), None);
116 self.client
117 .get(
118 &url,
119 crate::Message {
120 body: None,
121 content_type: None,
122 },
123 )
124 .await
125 }
126 /**
127 * This function performs a `POST` to the `/files.remote.remove` endpoint.
128 *
129 * Remove a remote file.
130 *
131 * FROM: <https://api.slack.com/methods/files.remote.remove>
132 */
133 pub async fn remove(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
134 let url = self.client.url("/files.remote.remove", None);
135 self.client
136 .post(
137 &url,
138 crate::Message {
139 body: None,
140 content_type: Some("application/x-www-form-urlencoded".to_string()),
141 },
142 )
143 .await
144 }
145 /**
146 * This function performs a `GET` to the `/files.remote.share` endpoint.
147 *
148 * Share a remote file into a channel.
149 *
150 * FROM: <https://api.slack.com/methods/files.remote.share>
151 *
152 * **Parameters:**
153 *
154 * * `token: &str` -- Authentication token. Requires scope: `remote_files:share`.
155 * * `file: &str` -- Specify a file registered with Slack by providing its ID. Either this field or `external_id` or both are required.
156 * * `external_id: &str` -- The globally unique identifier (GUID) for the file, as set by the app registering the file with Slack. Either this field or `file` or both are required.
157 * * `channels: &str` -- Comma-separated list of channel IDs where the file will be shared.
158 */
159 pub async fn share(
160 &self,
161 file: &str,
162 external_id: &str,
163 channels: &str,
164 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
165 let mut query_args: Vec<(String, String)> = Default::default();
166 if !channels.is_empty() {
167 query_args.push(("channels".to_string(), channels.to_string()));
168 }
169 if !external_id.is_empty() {
170 query_args.push(("external_id".to_string(), external_id.to_string()));
171 }
172 if !file.is_empty() {
173 query_args.push(("file".to_string(), file.to_string()));
174 }
175 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
176 let url = self
177 .client
178 .url(&format!("/files.remote.share?{}", query_), None);
179 self.client
180 .get(
181 &url,
182 crate::Message {
183 body: None,
184 content_type: None,
185 },
186 )
187 .await
188 }
189 /**
190 * This function performs a `POST` to the `/files.remote.update` endpoint.
191 *
192 * Updates an existing remote file.
193 *
194 * FROM: <https://api.slack.com/methods/files.remote.update>
195 */
196 pub async fn update(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
197 let url = self.client.url("/files.remote.update", None);
198 self.client
199 .post(
200 &url,
201 crate::Message {
202 body: None,
203 content_type: Some("application/x-www-form-urlencoded".to_string()),
204 },
205 )
206 .await
207 }
208}