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/{organizationId}/integrations/slack/create
30    async fn create<'a>(
31        &self,
32        organization_id: uuid::Uuid,
33        code: 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        organization_id: uuid::Uuid,
56        code: 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/{organizationId}/integrations/slack/create",
64            local_var_configuration.base_path,
65            organizationId = organization_id
66        );
67        let mut local_var_req_builder =
68            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
69
70        if let Some(ref param_value) = code {
71            local_var_req_builder =
72                local_var_req_builder.query(&[("code", &param_value.to_string())]);
73        }
74        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
75            local_var_req_builder = local_var_req_builder
76                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
77        }
78        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
79            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
80        };
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_user_agent) = local_var_configuration.user_agent {
116            local_var_req_builder = local_var_req_builder
117                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118        }
119        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
120            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
121        };
122
123        let local_var_req = local_var_req_builder.build()?;
124        let local_var_resp = local_var_client.execute(local_var_req).await?;
125
126        let local_var_status = local_var_resp.status();
127        let local_var_content = local_var_resp.text().await?;
128
129        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
130            Ok(())
131        } else {
132            let local_var_entity: Option<RedirectError> =
133                serde_json::from_str(&local_var_content).ok();
134            let local_var_error = ResponseContent {
135                status: local_var_status,
136                content: local_var_content,
137                entity: local_var_entity,
138            };
139            Err(Error::ResponseError(local_var_error))
140        }
141    }
142}
143
144/// struct for typed errors of method [`SlackIntegrationApi::create`]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum CreateError {
148    UnknownValue(serde_json::Value),
149}
150/// struct for typed errors of method [`SlackIntegrationApi::redirect`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum RedirectError {
154    UnknownValue(serde_json::Value),
155}