bw_web_api_rs/endpoints/
aurora_profile_by_toon.rs1use serde::Serialize;
2
3use crate::endpoints::Endpoint;
4use crate::error::ApiError;
5use crate::models::{ScrProfile, ScrMmGameLoading, ScrMmToonInfo, ScrToonInfo};
6use crate::types::Gateway;
7
8#[derive(Debug, Clone, Copy, Serialize)]
9pub enum AuroraProfileFieldMask {
10 #[serde(rename = "scr_profile")]
11 ScrProfile,
12 #[serde(rename = "scr_mmgameloading")]
13 ScrMmGameLoading,
14 #[serde(rename = "scr_mmtooninfo")]
15 ScrMmToonInfo,
16 #[serde(rename = "scr_tooninfo")]
17 ScrToonInfo,
18}
19
20pub struct AuroraProfileEndpoint {
21 toon: String,
22 gateway: Gateway,
23 field_mask: AuroraProfileFieldMask,
24}
25
26impl AuroraProfileEndpoint {
27 pub fn new(toon: String, gateway: Gateway, field_mask: AuroraProfileFieldMask) -> Self {
28 Self {
29 toon,
30 gateway,
31 field_mask,
32 }
33 }
34}
35
36impl Endpoint for AuroraProfileEndpoint {
37 type Request = ();
38 type Response = serde_json::Value;
39
40 fn endpoint(&self) -> String {
41 format!(
42 "/web-api/v2/aurora-profile-by-toon/{}/{}?request_flags={}",
43 urlencoding::encode(&self.toon),
44 self.gateway as i32,
45 match self.field_mask {
46 AuroraProfileFieldMask::ScrProfile => "scr_profile",
47 AuroraProfileFieldMask::ScrMmGameLoading => "scr_mmgameloading",
48 AuroraProfileFieldMask::ScrMmToonInfo => "scr_mmtooninfo",
49 AuroraProfileFieldMask::ScrToonInfo => "scr_tooninfo",
50 }
51 )
52 }
53
54 fn validate_response(response: &serde_json::Value) -> Result<(), ApiError> {
55 if let Some(aurora_id) = response.get("aurora_id") {
56 if aurora_id == 0 {
57 return Err(ApiError::ValidationError("Profile not found".to_string()));
58 }
59 }
60 Ok(())
61 }
62}
63
64impl crate::client::ApiClient {
65 pub async fn get_aurora_profile_by_toon_scr_profile(
69 &self,
70 toon: String,
71 gateway: Gateway,
72 ) -> Result<ScrProfile, ApiError> {
73 let endpoint = AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrProfile);
74 let json = self.request(&endpoint, &()).await?;
75
76 AuroraProfileEndpoint::validate_response(&json)?;
77 serde_json::from_value(json).map_err(Into::into)
78 }
79
80 pub async fn get_aurora_profile_by_toon_mm_game_loading(
84 &self,
85 toon: String,
86 gateway: Gateway,
87 ) -> Result<ScrMmGameLoading, ApiError> {
88 let endpoint = AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrMmGameLoading);
89 let json = self.request(&endpoint, &()).await?;
90
91 AuroraProfileEndpoint::validate_response(&json)?;
92 serde_json::from_value(json).map_err(Into::into)
93 }
94
95 pub async fn get_aurora_profile_by_toon_mm_toon_info(
99 &self,
100 toon: String,
101 gateway: Gateway,
102 ) -> Result<ScrMmToonInfo, ApiError> {
103 let endpoint = AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrMmToonInfo);
104 let json = self.request(&endpoint, &()).await?;
105
106 AuroraProfileEndpoint::validate_response(&json)?;
107 serde_json::from_value(json).map_err(Into::into)
108 }
109
110 pub async fn get_aurora_profile_by_toon_toon_info(
114 &self,
115 toon: String,
116 gateway: Gateway,
117 ) -> Result<ScrToonInfo, ApiError> {
118 let endpoint = AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrToonInfo);
119 let json = self.request(&endpoint, &()).await?;
120
121 AuroraProfileEndpoint::validate_response(&json)?;
122 serde_json::from_value(json).map_err(Into::into)
123 }
124}