casdoor_sdk/apis/
service_api.rs1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8#[derive(Clone, Debug)]
10pub struct ApiControllerSendEmailParams {
11 pub client_id: String,
13 pub client_secret: String,
15 pub from: models::ControllersEmailForm
17}
18
19#[derive(Clone, Debug)]
21pub struct ApiControllerSendNotificationParams {
22 pub from: models::ControllersNotificationForm
24}
25
26#[derive(Clone, Debug)]
28pub struct ApiControllerSendSmsParams {
29 pub client_id: String,
31 pub client_secret: String,
33 pub from: models::ControllersSmsForm
35}
36
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ApiControllerSendEmailError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ApiControllerSendNotificationError {
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ApiControllerSendSmsError {
56 UnknownValue(serde_json::Value),
57}
58
59
60pub async fn send_email(configuration: &configuration::Configuration, params: ApiControllerSendEmailParams) -> Result<models::ControllersResponse, Error<ApiControllerSendEmailError>> {
62 let local_var_configuration = configuration;
63
64 let client_id = params.client_id;
66 let client_secret = params.client_secret;
67 let from = params.from;
68
69
70 let local_var_client = &local_var_configuration.client;
71
72 let local_var_uri_str = format!("{}/api/send-email", local_var_configuration.base_path);
73 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
74
75 local_var_req_builder = local_var_req_builder.query(&[("clientId", &client_id.to_string())]);
76 local_var_req_builder = local_var_req_builder.query(&[("clientSecret", &client_secret.to_string())]);
77 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79 }
80 local_var_req_builder = local_var_req_builder.json(&from);
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 serde_json::from_str(&local_var_content).map_err(Error::from)
90 } else {
91 let local_var_entity: Option<ApiControllerSendEmailError> = serde_json::from_str(&local_var_content).ok();
92 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
93 Err(Error::ResponseError(local_var_error))
94 }
95}
96
97pub async fn send_notification(configuration: &configuration::Configuration, params: ApiControllerSendNotificationParams) -> Result<models::ControllersResponse, Error<ApiControllerSendNotificationError>> {
99 let local_var_configuration = configuration;
100
101 let from = params.from;
103
104
105 let local_var_client = &local_var_configuration.client;
106
107 let local_var_uri_str = format!("{}/api/send-notification", local_var_configuration.base_path);
108 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
109
110 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
111 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112 }
113 local_var_req_builder = local_var_req_builder.json(&from);
114
115 let local_var_req = local_var_req_builder.build()?;
116 let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118 let local_var_status = local_var_resp.status();
119 let local_var_content = local_var_resp.text().await?;
120
121 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122 serde_json::from_str(&local_var_content).map_err(Error::from)
123 } else {
124 let local_var_entity: Option<ApiControllerSendNotificationError> = serde_json::from_str(&local_var_content).ok();
125 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126 Err(Error::ResponseError(local_var_error))
127 }
128}
129
130pub async fn send_sms(configuration: &configuration::Configuration, params: ApiControllerSendSmsParams) -> Result<models::ControllersResponse, Error<ApiControllerSendSmsError>> {
132 let local_var_configuration = configuration;
133
134 let client_id = params.client_id;
136 let client_secret = params.client_secret;
137 let from = params.from;
138
139
140 let local_var_client = &local_var_configuration.client;
141
142 let local_var_uri_str = format!("{}/api/send-sms", local_var_configuration.base_path);
143 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145 local_var_req_builder = local_var_req_builder.query(&[("clientId", &client_id.to_string())]);
146 local_var_req_builder = local_var_req_builder.query(&[("clientSecret", &client_secret.to_string())]);
147 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149 }
150 local_var_req_builder = local_var_req_builder.json(&from);
151
152 let local_var_req = local_var_req_builder.build()?;
153 let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155 let local_var_status = local_var_resp.status();
156 let local_var_content = local_var_resp.text().await?;
157
158 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159 serde_json::from_str(&local_var_content).map_err(Error::from)
160 } else {
161 let local_var_entity: Option<ApiControllerSendSmsError> = serde_json::from_str(&local_var_content).ok();
162 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163 Err(Error::ResponseError(local_var_error))
164 }
165}
166