feat: introduce typed resp request

This commit is contained in:
mokurin000
2025-07-30 04:27:32 +08:00
parent 5ea8ebbf64
commit dd1bb5fb5c
5 changed files with 87 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ use sdgb_api::{
title::{
MaiVersionExt, Sdgb1_40, Sdgb1_50,
methods::APIMethod,
model::{GetUserPreviewApi, GetUserPreviewApiResp, Ping},
model::{GetUserPreviewApi, GetUserPreviewApiResp, Ping, UserLogoutApi, UserLogoutApiResp},
},
};
use spdlog::{error, info};
@@ -22,8 +22,21 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
let client = ClientBuilder::default().build_async().await?;
match cmd.command {
commands::Commands::Logout { user_id } => {
let logout: UserLogoutApiResp = Sdgb1_50::request(
&client,
APIMethod::UserLogoutApi,
user_id,
UserLogoutApi {
user_id,
..Default::default()
},
)
.await?;
println!("{logout:?}");
}
commands::Commands::Preview { user_id } => {
let preview = Sdgb1_50::request(
let preview: GetUserPreviewApiResp = Sdgb1_50::request(
&client,
APIMethod::GetUserPreviewApi,
user_id,
@@ -31,11 +44,10 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
)
.await?;
let preview: GetUserPreviewApiResp = serde_json::from_slice(&preview)?;
println!("{preview}");
}
commands::Commands::Ping => {
let decoded = Sdgb1_40::request(
let decoded = Sdgb1_40::request_raw(
&client,
APIMethod::Ping,
"",
@@ -43,7 +55,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
)
.await?;
info!("sdgb 1.40 resp: {:?}", String::from_utf8_lossy(&decoded));
let decoded = Sdgb1_50::request(&client, APIMethod::Ping, "", Ping {}).await?;
let decoded = Sdgb1_50::request_raw(&client, APIMethod::Ping, "", Ping {}).await?;
info!("sdgb 1.50 resp: {:?}", String::from_utf8_lossy(&decoded));
}
commands::Commands::QRLogin { ref qrcode_content } => {