chore: add PingResp

This commit is contained in:
mokurin000
2025-07-30 10:43:49 +08:00
parent dd1bb5fb5c
commit 42575eaa32
3 changed files with 29 additions and 9 deletions

View File

@@ -1,7 +1,5 @@
use serde::Serialize; mod ping;
pub use ping::{Ping, PingResp};
#[derive(Serialize)]
pub struct Ping {}
mod get_user_preview_api; mod get_user_preview_api;
pub use get_user_preview_api::{GetUserPreviewApi, GetUserPreviewApiResp}; pub use get_user_preview_api::{GetUserPreviewApi, GetUserPreviewApiResp};

View File

@@ -0,0 +1,18 @@
use std::fmt::Display;
use serde::{Deserialize, Serialize};
#[derive(Serialize)]
pub struct Ping {}
#[derive(Debug, Deserialize)]
pub struct PingResp {
result: String,
}
impl Display for PingResp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.result)?;
Ok(())
}
}

View File

@@ -5,7 +5,10 @@ use sdgb_api::{
title::{ title::{
MaiVersionExt, Sdgb1_40, Sdgb1_50, MaiVersionExt, Sdgb1_40, Sdgb1_50,
methods::APIMethod, methods::APIMethod,
model::{GetUserPreviewApi, GetUserPreviewApiResp, Ping, UserLogoutApi, UserLogoutApiResp}, model::{
GetUserPreviewApi, GetUserPreviewApiResp, Ping, PingResp, UserLogoutApi,
UserLogoutApiResp,
},
}, },
}; };
use spdlog::{error, info}; use spdlog::{error, info};
@@ -47,16 +50,17 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
println!("{preview}"); println!("{preview}");
} }
commands::Commands::Ping => { commands::Commands::Ping => {
let decoded = Sdgb1_40::request_raw( let decoded: PingResp = Sdgb1_40::request(
&client, &client,
APIMethod::Ping, APIMethod::Ping,
"", "",
Ping {}, // note: must not be `Ping`, or serde_json serializes to nothing Ping {}, // note: must not be `Ping`, or serde_json serializes to nothing
) )
.await?; .await?;
info!("sdgb 1.40 resp: {:?}", String::from_utf8_lossy(&decoded)); info!("sdgb 1.40 resp: {decoded}");
let decoded = Sdgb1_50::request_raw(&client, APIMethod::Ping, "", Ping {}).await?; let decoded: PingResp =
info!("sdgb 1.50 resp: {:?}", String::from_utf8_lossy(&decoded)); Sdgb1_50::request(&client, APIMethod::Ping, "", Ping {}).await?;
info!("sdgb 1.50 resp: {decoded}");
} }
commands::Commands::QRLogin { ref qrcode_content } => { commands::Commands::QRLogin { ref qrcode_content } => {
let qrcode = QRCode { qrcode_content }; let qrcode = QRCode { qrcode_content };