Skip to main content

slack_web_api/api/
auth.rs

1// このファイルは codegen/generate.py が生成する。手で編集しない
2
3#![allow(unused_imports)]
4
5use crate::objects::*;
6use crate::{
7    CursorPaginated, NextCursor, ResponseMetadata, SlackApiMethod, SlackClient, SlackError,
8};
9use serde::{Deserialize, Serialize};
10
11/// Arguments for the Slack Web API method [`auth.revoke`](https://docs.slack.dev/reference/methods/auth.revoke): Revokes a token.
12///
13/// Send it with [`SlackClient::auth_revoke`].
14#[doc(alias = "auth.revoke")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct AuthRevokeRequest {
18    /// Setting this parameter to `1` triggers a _testing mode_ where the specified token will not actually be revoked.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub test: Option<bool>,
21}
22
23impl AuthRevokeRequest {
24    pub fn new() -> Self {
25        Self { test: None }
26    }
27
28    pub fn test(mut self, test: bool) -> Self {
29        self.test = Some(test);
30        self
31    }
32}
33
34impl SlackApiMethod for AuthRevokeRequest {
35    const METHOD: &'static str = "auth.revoke";
36    type Response = AuthRevokeResponse;
37}
38
39/// Successful response of the Slack Web API method [`auth.revoke`](https://docs.slack.dev/reference/methods/auth.revoke).
40#[doc(alias = "auth.revoke")]
41#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
42pub struct AuthRevokeResponse {
43    #[serde(
44        default,
45        deserialize_with = "crate::de::opt_bool",
46        skip_serializing_if = "Option::is_none"
47    )]
48    pub revoked: Option<bool>,
49    #[serde(
50        default,
51        deserialize_with = "crate::de::opt_object",
52        skip_serializing_if = "Option::is_none"
53    )]
54    pub response_metadata: Option<ResponseMetadata>,
55    #[serde(
56        default,
57        deserialize_with = "crate::de::opt_string",
58        skip_serializing_if = "Option::is_none"
59    )]
60    pub warning: Option<String>,
61}
62
63/// Arguments for the Slack Web API method [`auth.teams.list`](https://docs.slack.dev/reference/methods/auth.teams.list): Obtain a full list of workspaces your org-wide app has been approved for.
64///
65/// Send it with [`SlackClient::auth_teams_list`].
66#[doc(alias = "auth.teams.list")]
67#[derive(Debug, Clone, PartialEq, Serialize, Default)]
68#[non_exhaustive]
69pub struct AuthTeamsListRequest {
70    /// The maximum number of workspaces to return. Must be a positive integer no larger than 1000.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub limit: Option<i64>,
73    /// Set `cursor` to `next_cursor` returned by the previous call to list items in the next page.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub cursor: Option<String>,
76    /// Whether to return icon paths for each workspace. An icon path represents a URI pointing to the image signifying the workspace.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub include_icon: Option<bool>,
79}
80
81impl AuthTeamsListRequest {
82    pub fn new() -> Self {
83        Self {
84            limit: None,
85            cursor: None,
86            include_icon: None,
87        }
88    }
89
90    pub fn limit(mut self, limit: i64) -> Self {
91        self.limit = Some(limit);
92        self
93    }
94
95    pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
96        self.cursor = Some(cursor.into());
97        self
98    }
99
100    pub fn include_icon(mut self, include_icon: bool) -> Self {
101        self.include_icon = Some(include_icon);
102        self
103    }
104}
105
106impl SlackApiMethod for AuthTeamsListRequest {
107    const METHOD: &'static str = "auth.teams.list";
108    type Response = AuthTeamsListResponse;
109}
110
111impl CursorPaginated for AuthTeamsListRequest {
112    fn set_cursor(&mut self, cursor: String) {
113        self.cursor = Some(cursor);
114    }
115}
116
117impl NextCursor for AuthTeamsListResponse {
118    fn next_cursor(&self) -> Option<&str> {
119        self.response_metadata.as_ref()?.next_cursor.as_deref()
120    }
121}
122
123/// Successful response of the Slack Web API method [`auth.teams.list`](https://docs.slack.dev/reference/methods/auth.teams.list).
124#[doc(alias = "auth.teams.list")]
125#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
126pub struct AuthTeamsListResponse {
127    #[serde(
128        default,
129        deserialize_with = "crate::de::vec",
130        skip_serializing_if = "Vec::is_empty"
131    )]
132    pub teams: Vec<AuthTeamsListResponseTeams>,
133    #[serde(
134        default,
135        deserialize_with = "crate::de::opt_object",
136        skip_serializing_if = "Option::is_none"
137    )]
138    pub response_metadata: Option<ResponseMetadata>,
139    #[serde(
140        default,
141        deserialize_with = "crate::de::opt_string",
142        skip_serializing_if = "Option::is_none"
143    )]
144    pub warning: Option<String>,
145}
146
147#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
148pub struct AuthTeamsListResponseTeams {
149    #[serde(
150        default,
151        deserialize_with = "crate::de::opt_string",
152        skip_serializing_if = "Option::is_none"
153    )]
154    pub name: Option<String>,
155    #[serde(
156        default,
157        deserialize_with = "crate::de::opt_string",
158        skip_serializing_if = "Option::is_none"
159    )]
160    pub id: Option<String>,
161}
162
163/// Arguments for the Slack Web API method [`auth.test`](https://docs.slack.dev/reference/methods/auth.test): Checks authentication & identity.
164///
165/// Send it with [`SlackClient::auth_test`].
166#[doc(alias = "auth.test")]
167#[derive(Debug, Clone, PartialEq, Serialize, Default)]
168#[non_exhaustive]
169pub struct AuthTestRequest {}
170
171impl AuthTestRequest {
172    pub fn new() -> Self {
173        Self {}
174    }
175}
176
177impl SlackApiMethod for AuthTestRequest {
178    const METHOD: &'static str = "auth.test";
179    type Response = AuthTestResponse;
180}
181
182/// Successful response of the Slack Web API method [`auth.test`](https://docs.slack.dev/reference/methods/auth.test).
183#[doc(alias = "auth.test")]
184#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
185pub struct AuthTestResponse {
186    #[serde(
187        default,
188        deserialize_with = "crate::de::opt_string",
189        skip_serializing_if = "Option::is_none"
190    )]
191    pub url: Option<String>,
192    #[serde(
193        default,
194        deserialize_with = "crate::de::opt_string",
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub team: Option<String>,
198    #[serde(
199        default,
200        deserialize_with = "crate::de::opt_string",
201        skip_serializing_if = "Option::is_none"
202    )]
203    pub user: Option<String>,
204    #[serde(
205        default,
206        deserialize_with = "crate::de::opt_string",
207        skip_serializing_if = "Option::is_none"
208    )]
209    pub team_id: Option<String>,
210    #[serde(
211        default,
212        deserialize_with = "crate::de::opt_string",
213        skip_serializing_if = "Option::is_none"
214    )]
215    pub user_id: Option<String>,
216    #[serde(
217        default,
218        deserialize_with = "crate::de::opt_string",
219        skip_serializing_if = "Option::is_none"
220    )]
221    pub bot_id: Option<String>,
222    #[serde(
223        default,
224        deserialize_with = "crate::de::opt_object",
225        skip_serializing_if = "Option::is_none"
226    )]
227    pub response_metadata: Option<ResponseMetadata>,
228    #[serde(
229        default,
230        deserialize_with = "crate::de::opt_string",
231        skip_serializing_if = "Option::is_none"
232    )]
233    pub warning: Option<String>,
234}
235
236impl SlackClient {
237    /// Calls the Slack Web API method [`auth.revoke`](https://docs.slack.dev/reference/methods/auth.revoke): Revokes a token.
238    ///
239    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
240    ///
241    /// # Errors
242    ///
243    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
244    #[doc(alias = "auth.revoke")]
245    pub async fn auth_revoke(
246        &self,
247        request: &AuthRevokeRequest,
248    ) -> Result<AuthRevokeResponse, SlackError> {
249        self.call(request).await
250    }
251
252    /// Calls the Slack Web API method [`auth.teams.list`](https://docs.slack.dev/reference/methods/auth.teams.list): Obtain a full list of workspaces your org-wide app has been approved for.
253    ///
254    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
255    ///
256    /// # Errors
257    ///
258    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
259    #[doc(alias = "auth.teams.list")]
260    pub async fn auth_teams_list(
261        &self,
262        request: &AuthTeamsListRequest,
263    ) -> Result<AuthTeamsListResponse, SlackError> {
264        self.call(request).await
265    }
266
267    /// Calls the Slack Web API method [`auth.test`](https://docs.slack.dev/reference/methods/auth.test): Checks authentication & identity.
268    ///
269    /// Rate limit: Tier 5 (<https://docs.slack.dev/apis/web-api/rate-limits>).
270    ///
271    /// # Errors
272    ///
273    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
274    #[doc(alias = "auth.test")]
275    pub async fn auth_test(
276        &self,
277        request: &AuthTestRequest,
278    ) -> Result<AuthTestResponse, SlackError> {
279        self.call(request).await
280    }
281}