clerk_sdk_rust_community/apis/
webhooks_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSvixAppError {
22 Status400(crate::models::ClerkErrors),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteSvixAppError {
30 Status400(crate::models::ClerkErrors),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GenerateSvixAuthUrlError {
38 Status400(crate::models::ClerkErrors),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn create_svix_app(configuration: &configuration::Configuration, ) -> Result<crate::models::SvixUrl, Error<CreateSvixAppError>> {
45 let local_var_configuration = configuration;
46
47 let local_var_client = &local_var_configuration.client;
48
49 let local_var_uri_str = format!("{}/webhooks/svix", local_var_configuration.base_path);
50 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
51
52 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
53 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54 }
55 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
56 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
57 };
58
59 let local_var_req = local_var_req_builder.build()?;
60 let local_var_resp = local_var_client.execute(local_var_req).await?;
61
62 let local_var_status = local_var_resp.status();
63 let local_var_content = local_var_resp.text().await?;
64
65 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
66 serde_json::from_str(&local_var_content).map_err(Error::from)
67 } else {
68 let local_var_entity: Option<CreateSvixAppError> = serde_json::from_str(&local_var_content).ok();
69 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
70 Err(Error::ResponseError(local_var_error))
71 }
72}
73
74pub async fn delete_svix_app(configuration: &configuration::Configuration, ) -> Result<(), Error<DeleteSvixAppError>> {
76 let local_var_configuration = configuration;
77
78 let local_var_client = &local_var_configuration.client;
79
80 let local_var_uri_str = format!("{}/webhooks/svix", local_var_configuration.base_path);
81 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
82
83 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
84 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
85 }
86 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
87 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
88 };
89
90 let local_var_req = local_var_req_builder.build()?;
91 let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93 let local_var_status = local_var_resp.status();
94 let local_var_content = local_var_resp.text().await?;
95
96 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97 Ok(())
98 } else {
99 let local_var_entity: Option<DeleteSvixAppError> = serde_json::from_str(&local_var_content).ok();
100 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
101 Err(Error::ResponseError(local_var_error))
102 }
103}
104
105pub async fn generate_svix_auth_url(configuration: &configuration::Configuration, ) -> Result<crate::models::SvixUrl, Error<GenerateSvixAuthUrlError>> {
107 let local_var_configuration = configuration;
108
109 let local_var_client = &local_var_configuration.client;
110
111 let local_var_uri_str = format!("{}/webhooks/svix_url", local_var_configuration.base_path);
112 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
113
114 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
116 }
117 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
118 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
119 };
120
121 let local_var_req = local_var_req_builder.build()?;
122 let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124 let local_var_status = local_var_resp.status();
125 let local_var_content = local_var_resp.text().await?;
126
127 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
128 serde_json::from_str(&local_var_content).map_err(Error::from)
129 } else {
130 let local_var_entity: Option<GenerateSvixAuthUrlError> = serde_json::from_str(&local_var_content).ok();
131 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
132 Err(Error::ResponseError(local_var_error))
133 }
134}
135