Skip to main content

slack_web_api/api/
api_test.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 [`api.test`](https://docs.slack.dev/reference/methods/api.test): Checks API calling code.
12///
13/// Send it with [`SlackClient::api_test`].
14#[doc(alias = "api.test")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct ApiTestRequest {
18    /// Error response to return
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub error: Option<String>,
21}
22
23impl ApiTestRequest {
24    pub fn new() -> Self {
25        Self { error: None }
26    }
27
28    pub fn error(mut self, error: impl Into<String>) -> Self {
29        self.error = Some(error.into());
30        self
31    }
32}
33
34impl SlackApiMethod for ApiTestRequest {
35    const METHOD: &'static str = "api.test";
36    type Response = ApiTestResponse;
37}
38
39/// Successful response of the Slack Web API method [`api.test`](https://docs.slack.dev/reference/methods/api.test).
40#[doc(alias = "api.test")]
41#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
42pub struct ApiTestResponse {
43    #[serde(
44        default,
45        deserialize_with = "crate::de::opt_object",
46        skip_serializing_if = "Option::is_none"
47    )]
48    pub args: Option<ApiTestResponseArgs>,
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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
64pub struct ApiTestResponseArgs {
65    #[serde(
66        default,
67        deserialize_with = "crate::de::opt_string",
68        skip_serializing_if = "Option::is_none"
69    )]
70    pub foo: Option<String>,
71}
72
73impl SlackClient {
74    /// Calls the Slack Web API method [`api.test`](https://docs.slack.dev/reference/methods/api.test): Checks API calling code.
75    ///
76    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
77    ///
78    /// # Errors
79    ///
80    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
81    #[doc(alias = "api.test")]
82    pub async fn api_test(&self, request: &ApiTestRequest) -> Result<ApiTestResponse, SlackError> {
83        self.call(request).await
84    }
85}