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::{AuthRequired, 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_token) = local_var_configuration.oauth_access_token {
78            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
79        };
80        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
81
82        let local_var_req = local_var_req_builder.build()?;
83        let local_var_resp = local_var_client.execute(local_var_req).await?;
84
85        let local_var_status = local_var_resp.status();
86        let local_var_content = local_var_resp.text().await?;
87
88        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89            Ok(())
90        } else {
91            let local_var_entity: Option<CreateError> =
92                serde_json::from_str(&local_var_content).ok();
93            let local_var_error = ResponseContent {
94                status: local_var_status,
95                content: local_var_content,
96                entity: local_var_entity,
97            };
98            Err(Error::ResponseError(local_var_error))
99        }
100    }
101
102    async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>> {
103        let local_var_configuration = &self.configuration;
104
105        let local_var_client = &local_var_configuration.client;
106
107        let local_var_uri_str = format!(
108            "{}/organizations/{organizationId}/integrations/slack/redirect",
109            local_var_configuration.base_path,
110            organizationId = organization_id
111        );
112        let mut local_var_req_builder =
113            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
114
115        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
116            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
117        };
118        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
119
120        let local_var_req = local_var_req_builder.build()?;
121        let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123        let local_var_status = local_var_resp.status();
124        let local_var_content = local_var_resp.text().await?;
125
126        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127            Ok(())
128        } else {
129            let local_var_entity: Option<RedirectError> =
130                serde_json::from_str(&local_var_content).ok();
131            let local_var_error = ResponseContent {
132                status: local_var_status,
133                content: local_var_content,
134                entity: local_var_entity,
135            };
136            Err(Error::ResponseError(local_var_error))
137        }
138    }
139}
140
141/// struct for typed errors of method [`SlackIntegrationApi::create`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum CreateError {
145    UnknownValue(serde_json::Value),
146}
147/// struct for typed errors of method [`SlackIntegrationApi::redirect`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum RedirectError {
151    UnknownValue(serde_json::Value),
152}