bw_web_api_rs/endpoints/
aurora_profile_by_toon.rs1use serde::Serialize;
2
3use crate::endpoints::Endpoint;
4use crate::error::ApiError;
5use crate::models::{ScrMmGameLoading, ScrMmToonInfo, ScrProfile, 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 =
74 AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrProfile);
75 let json = self.request(&endpoint, &()).await?;
76
77 AuroraProfileEndpoint::validate_response(&json)?;
78 serde_json::from_value(json).map_err(Into::into)
79 }
80
81 pub async fn get_aurora_profile_by_toon_mm_game_loading(
85 &self,
86 toon: String,
87 gateway: Gateway,
88 ) -> Result<ScrMmGameLoading, ApiError> {
89 let endpoint =
90 AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrMmGameLoading);
91 let json = self.request(&endpoint, &()).await?;
92
93 AuroraProfileEndpoint::validate_response(&json)?;
94 serde_json::from_value(json).map_err(Into::into)
95 }
96
97 pub async fn get_aurora_profile_by_toon_mm_toon_info(
101 &self,
102 toon: String,
103 gateway: Gateway,
104 ) -> Result<ScrMmToonInfo, ApiError> {
105 let endpoint =
106 AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrMmToonInfo);
107 let json = self.request(&endpoint, &()).await?;
108
109 AuroraProfileEndpoint::validate_response(&json)?;
110 serde_json::from_value(json).map_err(Into::into)
111 }
112
113 pub async fn get_aurora_profile_by_toon_toon_info(
117 &self,
118 toon: String,
119 gateway: Gateway,
120 ) -> Result<ScrToonInfo, ApiError> {
121 let endpoint =
122 AuroraProfileEndpoint::new(toon, gateway, AuroraProfileFieldMask::ScrToonInfo);
123 let json = self.request(&endpoint, &()).await?;
124
125 AuroraProfileEndpoint::validate_response(&json)?;
126 serde_json::from_value(json).map_err(Into::into)
127 }
128}