bitwarden_api_api/apis/
slack_integration_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait SlackIntegrationApi: Send + Sync {
29    /// GET /organizations/integrations/slack/create
30    async fn create<'a>(
31        &self,
32        code: Option<&'a str>,
33        state: Option<&'a str>,
34    ) -> Result<(), Error<CreateError>>;
35
36    /// GET /organizations/{organizationId}/integrations/slack/redirect
37    async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>>;
38}
39
40pub struct SlackIntegrationApiClient {
41    configuration: Arc<configuration::Configuration>,
42}
43
44impl SlackIntegrationApiClient {
45    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
46        Self { configuration }
47    }
48}
49
50#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
51#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
52impl SlackIntegrationApi for SlackIntegrationApiClient {
53    async fn create<'a>(
54        &self,
55        code: Option<&'a str>,
56        state: Option<&'a str>,
57    ) -> Result<(), Error<CreateError>> {
58        let local_var_configuration = &self.configuration;
59
60        let local_var_client = &local_var_configuration.client;
61
62        let local_var_uri_str = format!(
63            "{}/organizations/integrations/slack/create",
64            local_var_configuration.base_path
65        );
66        let mut local_var_req_builder =
67            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
68
69        if let Some(ref param_value) = code {
70            local_var_req_builder =
71                local_var_req_builder.query(&[("code", &param_value.to_string())]);
72        }
73        if let Some(ref param_value) = state {
74            local_var_req_builder =
75                local_var_req_builder.query(&[("state", &param_value.to_string())]);
76        }
77        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78            local_var_req_builder = local_var_req_builder
79                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80        }
81        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
82            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
83        };
84
85        let local_var_req = local_var_req_builder.build()?;
86        let local_var_resp = local_var_client.execute(local_var_req).await?;
87
88        let local_var_status = local_var_resp.status();
89        let local_var_content = local_var_resp.text().await?;
90
91        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92            Ok(())
93        } else {
94            let local_var_entity: Option<CreateError> =
95                serde_json::from_str(&local_var_content).ok();
96            let local_var_error = ResponseContent {
97                status: local_var_status,
98                content: local_var_content,
99                entity: local_var_entity,
100            };
101            Err(Error::ResponseError(local_var_error))
102        }
103    }
104
105    async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>> {
106        let local_var_configuration = &self.configuration;
107
108        let local_var_client = &local_var_configuration.client;
109
110        let local_var_uri_str = format!(
111            "{}/organizations/{organizationId}/integrations/slack/redirect",
112            local_var_configuration.base_path,
113            organizationId = organization_id
114        );
115        let mut local_var_req_builder =
116            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
117
118        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
119            local_var_req_builder = local_var_req_builder
120                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
121        }
122        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
123            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
124        };
125
126        let local_var_req = local_var_req_builder.build()?;
127        let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129        let local_var_status = local_var_resp.status();
130        let local_var_content = local_var_resp.text().await?;
131
132        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133            Ok(())
134        } else {
135            let local_var_entity: Option<RedirectError> =
136                serde_json::from_str(&local_var_content).ok();
137            let local_var_error = ResponseContent {
138                status: local_var_status,
139                content: local_var_content,
140                entity: local_var_entity,
141            };
142            Err(Error::ResponseError(local_var_error))
143        }
144    }
145}
146
147/// struct for typed errors of method [`SlackIntegrationApi::create`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum CreateError {
151    UnknownValue(serde_json::Value),
152}
153/// struct for typed errors of method [`SlackIntegrationApi::redirect`]
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[serde(untagged)]
156pub enum RedirectError {
157    UnknownValue(serde_json::Value),
158}