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