1#![allow(warnings)]
3
4pub mod components;
9use std::sync::Arc;
10
11pub mod models;
13pub use models::*;
14
15pub mod error;
17pub use error::*;
18
19mod utils;
20
21mod config;
22
23mod client;
24use client::Client;
25use components::auth::AuthClient;
26use config::Config;
27use reqwest_cookie_store::{CookieStore, CookieStoreMutex};
28use utils::common::Region;
29
30#[derive(Clone)]
32pub struct Hoyo {
33 config: config::Config,
34 client: Client,
35 cookie_store: Arc<CookieStoreMutex>,
36}
37
38impl Hoyo {
39 pub fn new() -> Self {
41 Self::from_config(Config::default())
42 }
43
44 pub fn from_config(config: Config) -> Self {
46 let cookie_store = Arc::new(CookieStoreMutex::new(CookieStore::new(None)));
47 let client = Client::builder()
48 .cookie_provider(cookie_store.clone())
49 .build()
50 .expect("failed to build Request client");
51 Self {
52 config,
53 client,
54 cookie_store,
55 }
56 }
57
58 pub fn authclient(&self, region: Region) -> AuthClient {
60 AuthClient::new(self.client.clone(), region, self.cookie_store.clone())
61 }
62}