bitwarden_api_api/apis/
teams_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 TeamsIntegrationApi: Send + Sync {
29    /// GET /organizations/integrations/teams/create
30    async fn create<'a>(
31        &self,
32        code: Option<&'a str>,
33        state: Option<&'a str>,
34    ) -> Result<(), Error<CreateError>>;
35
36    /// POST /organizations/integrations/teams/incoming
37    async fn incoming_post(&self) -> Result<(), Error<IncomingPostError>>;
38
39    /// GET /organizations/{organizationId}/integrations/teams/redirect
40    async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>>;
41}
42
43pub struct TeamsIntegrationApiClient {
44    configuration: Arc<configuration::Configuration>,
45}
46
47impl TeamsIntegrationApiClient {
48    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
49        Self { configuration }
50    }
51}
52
53#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
54#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
55impl TeamsIntegrationApi for TeamsIntegrationApiClient {
56    async fn create<'a>(
57        &self,
58        code: Option<&'a str>,
59        state: Option<&'a str>,
60    ) -> Result<(), Error<CreateError>> {
61        let local_var_configuration = &self.configuration;
62
63        let local_var_client = &local_var_configuration.client;
64
65        let local_var_uri_str = format!(
66            "{}/organizations/integrations/teams/create",
67            local_var_configuration.base_path
68        );
69        let mut local_var_req_builder =
70            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
71
72        if let Some(ref param_value) = code {
73            local_var_req_builder =
74                local_var_req_builder.query(&[("code", &param_value.to_string())]);
75        }
76        if let Some(ref param_value) = state {
77            local_var_req_builder =
78                local_var_req_builder.query(&[("state", &param_value.to_string())]);
79        }
80        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
81            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82        };
83        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
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 incoming_post(&self) -> Result<(), Error<IncomingPostError>> {
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/integrations/teams/incoming",
112            local_var_configuration.base_path
113        );
114        let mut local_var_req_builder =
115            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
116
117        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
118            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
119        };
120        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
121
122        let local_var_req = local_var_req_builder.build()?;
123        let local_var_resp = local_var_client.execute(local_var_req).await?;
124
125        let local_var_status = local_var_resp.status();
126        let local_var_content = local_var_resp.text().await?;
127
128        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129            Ok(())
130        } else {
131            let local_var_entity: Option<IncomingPostError> =
132                serde_json::from_str(&local_var_content).ok();
133            let local_var_error = ResponseContent {
134                status: local_var_status,
135                content: local_var_content,
136                entity: local_var_entity,
137            };
138            Err(Error::ResponseError(local_var_error))
139        }
140    }
141
142    async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>> {
143        let local_var_configuration = &self.configuration;
144
145        let local_var_client = &local_var_configuration.client;
146
147        let local_var_uri_str = format!(
148            "{}/organizations/{organizationId}/integrations/teams/redirect",
149            local_var_configuration.base_path,
150            organizationId = organization_id
151        );
152        let mut local_var_req_builder =
153            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
154
155        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
156            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157        };
158        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
159
160        let local_var_req = local_var_req_builder.build()?;
161        let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163        let local_var_status = local_var_resp.status();
164        let local_var_content = local_var_resp.text().await?;
165
166        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167            Ok(())
168        } else {
169            let local_var_entity: Option<RedirectError> =
170                serde_json::from_str(&local_var_content).ok();
171            let local_var_error = ResponseContent {
172                status: local_var_status,
173                content: local_var_content,
174                entity: local_var_entity,
175            };
176            Err(Error::ResponseError(local_var_error))
177        }
178    }
179}
180
181/// struct for typed errors of method [`TeamsIntegrationApi::create`]
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(untagged)]
184pub enum CreateError {
185    UnknownValue(serde_json::Value),
186}
187/// struct for typed errors of method [`TeamsIntegrationApi::incoming_post`]
188#[derive(Debug, Clone, Serialize, Deserialize)]
189#[serde(untagged)]
190pub enum IncomingPostError {
191    UnknownValue(serde_json::Value),
192}
193/// struct for typed errors of method [`TeamsIntegrationApi::redirect`]
194#[derive(Debug, Clone, Serialize, Deserialize)]
195#[serde(untagged)]
196pub enum RedirectError {
197    UnknownValue(serde_json::Value),
198}