bitwarden_api_api/apis/
slack_integration_api.rs1use 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 async fn create<'a>(
31 &self,
32 code: Option<&'a str>,
33 state: Option<&'a str>,
34 ) -> Result<(), Error<CreateError>>;
35
36 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", ¶m_value.to_string())]);
72 }
73 if let Some(ref param_value) = state {
74 local_var_req_builder =
75 local_var_req_builder.query(&[("state", ¶m_value.to_string())]);
76 }
77 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
78
79 let local_var_resp = local_var_req_builder.send().await?;
80
81 let local_var_status = local_var_resp.status();
82 let local_var_content = local_var_resp.text().await?;
83
84 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85 Ok(())
86 } else {
87 let local_var_entity: Option<CreateError> =
88 serde_json::from_str(&local_var_content).ok();
89 let local_var_error = ResponseContent {
90 status: local_var_status,
91 content: local_var_content,
92 entity: local_var_entity,
93 };
94 Err(Error::ResponseError(local_var_error))
95 }
96 }
97
98 async fn redirect<'a>(&self, organization_id: uuid::Uuid) -> Result<(), Error<RedirectError>> {
99 let local_var_configuration = &self.configuration;
100
101 let local_var_client = &local_var_configuration.client;
102
103 let local_var_uri_str = format!(
104 "{}/organizations/{organizationId}/integrations/slack/redirect",
105 local_var_configuration.base_path,
106 organizationId = organization_id
107 );
108 let mut local_var_req_builder =
109 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
110
111 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
112
113 let local_var_resp = local_var_req_builder.send().await?;
114
115 let local_var_status = local_var_resp.status();
116 let local_var_content = local_var_resp.text().await?;
117
118 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119 Ok(())
120 } else {
121 let local_var_entity: Option<RedirectError> =
122 serde_json::from_str(&local_var_content).ok();
123 let local_var_error = ResponseContent {
124 status: local_var_status,
125 content: local_var_content,
126 entity: local_var_entity,
127 };
128 Err(Error::ResponseError(local_var_error))
129 }
130 }
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum CreateError {
137 UnknownValue(serde_json::Value),
138}
139#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum RedirectError {
143 UnknownValue(serde_json::Value),
144}