openapi_rs/api/v1/rdp_go/
internal_rdp_go_clean.rs

1use crate::common::define::{
2    AsyncResponseFn, BaseRequest, BaseResponse, HttpBuilder, HttpFn, RequestFn,
3};
4use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
5use reqwest::{Method, Response};
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
10#[serde(default)]
11pub struct InternalRdpGoCleanRequest {
12    #[serde(rename = "PrivateIP")]
13    pub private_ip: Option<String>,
14    #[serde(rename = "x-ys-request-id")]
15    pub request_id: Option<String>,
16}
17
18impl InternalRdpGoCleanRequest {
19    pub fn new() -> Self {
20        Self::default()
21    }
22    pub fn with_private_ip(mut self, private_ip: String) -> Self {
23        self.private_ip = Some(private_ip);
24        self
25    }
26    pub fn with_request_id(mut self, request_id: String) -> Self {
27        self.request_id = Some(request_id);
28        self
29    }
30}
31
32#[derive(Debug, Default, Clone, Serialize, Deserialize)]
33#[serde(default)]
34pub struct InternalRdpGoCleanResponse {}
35
36impl HttpBuilder for InternalRdpGoCleanRequest {
37    type Response = BaseResponse<InternalRdpGoCleanResponse>;
38    fn builder(self) -> HttpFn<Self::Response> {
39        Box::new(move || {
40            let request_fn: RequestFn = Box::new(move || {
41                let mut headers = HeaderMap::new();
42                if let Some(ref request_id) = self.request_id {
43                    headers.insert(
44                        HeaderName::from_bytes("x-ys-request-id".as_bytes()).unwrap(),
45                        HeaderValue::from_str(request_id).unwrap(),
46                    );
47                }
48                let mut queries = HashMap::new();
49                if let Some(ref private_ip) = self.private_ip {
50                    queries.insert("PrivateIP".to_string(), private_ip.clone());
51                }
52                BaseRequest {
53                    method: Method::POST,
54                    uri: "/internal/clean".to_string(),
55                    headers,
56                    queries: Some(queries),
57                    ..Default::default()
58                }
59            });
60            let response_fn: AsyncResponseFn<Self::Response> =
61                Box::new(|response: Response| Box::pin(async move { Ok(response.json().await?) }));
62            (request_fn, response_fn)
63        })
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70    use crate::common::client::OpenApiClient;
71    use crate::common::config::OpenApiConfig;
72    use tracing::info;
73
74    #[tokio::test]
75    async fn test_internal_rdp_go_clean() -> anyhow::Result<()> {
76        tracing_subscriber::fmt::init();
77        dotenvy::dotenv()?;
78        let config = OpenApiConfig::new().load_from_env()?;
79        let mut client = OpenApiClient::new(config);
80
81        let http_fn = InternalRdpGoCleanRequest::new()
82            .with_private_ip("123".to_string())
83            .builder();
84        let response = client.send(http_fn).await?;
85        info!("response: {:#?}", response);
86
87        Ok(())
88    }
89}