miHoYo_API/
lib.rs

1pub mod client;
2pub mod components;
3pub mod error;
4pub mod typing;
5
6
7#[cfg(test)]
8mod test {
9    use crate::client::Client;
10    use crate::typing::{Game, Languages};
11
12    #[tokio::test]
13    async fn demo() -> anyhow::Result<()> {
14        /// Initialize Client variable.
15        /// Setting for two cookies connect [Hoyolab](https://www.hoyolab.com/home).
16        /// And another way to set,  you can use [`Client::set_cookies`]
17        let mut client = Client::new().set_from_env(None)?;
18
19        /// Getting [`crate::components::models::hoyolab::record::Account`] as elements in Vector.
20        let accounts = client.get_game_account(Some(Game::StarRail), None).await?;
21
22        /// Extract UID from account.
23        let uid = accounts.get(0).unwrap().get_uid();
24
25        /// Extract StarRail UID from [Hoyolab](https://www.hoyolab.com/home).
26        /// getting user accounts as contains in Vector and then filtered by user level.
27        let account_id = client.get_game_accounts(Some(Languages::JaJp)).await?
28            .into_iter().filter(|account| account.level == 70).next().unwrap().get_uid();
29
30        /// This [`crate::components::chronicle::starrail::StarRailClient::get_preview_data`] is only β.
31        /// Getting as [`crate::components::models::starrail::mihomo::Mihomo`].
32        /// --About lang argument, Here's [corresponding string list](https://github.com/Mar-7th/mihomo.py/blob/master/mihomo/model.py#L8)--
33        /// I will create a enum of Language.
34        let user_data = client.starrail.get_preview_data(account_id, Some("jp")).await.unwrap();
35        dbg!(&user_data);
36
37        Ok(())
38    }
39}