diff --git a/sdgb-api/src/title/model/mod.rs b/sdgb-api/src/title/model/mod.rs index ec6d833..4138346 100644 --- a/sdgb-api/src/title/model/mod.rs +++ b/sdgb-api/src/title/model/mod.rs @@ -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}; diff --git a/sdgb-api/src/title/model/ping/mod.rs b/sdgb-api/src/title/model/ping/mod.rs new file mode 100644 index 0000000..f1ba1de --- /dev/null +++ b/sdgb-api/src/title/model/ping/mod.rs @@ -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(()) + } +} diff --git a/sdgb-cli/src/main.rs b/sdgb-cli/src/main.rs index 7ebe437..0cf4d04 100644 --- a/sdgb-cli/src/main.rs +++ b/sdgb-cli/src/main.rs @@ -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> { 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 };