1mod token;
2mod utils;
3mod constant;
4mod config;
5mod auth;
6mod model;
7mod client;
8
9pub mod require {
10 pub use crate::config::{Config, get_config, set_config};
11 pub use crate::client::Client;
12 pub use crate::ClientHandler;
13 pub use rspotify::clients::BaseClient;
14 pub use rspotify::clients::OAuthClient;
15}
16
17pub mod prelude {
18 pub use super::require::*;
19 pub use rspotify::prelude::*;
20 pub use rspotify::model::*;
21}
22
23
24pub struct ClientHandler {
25 config: auth::AuthConfig
26}
27
28impl ClientHandler {
29 pub fn new() -> Self {
30 let auth_config = auth::AuthConfig::default();
31 Self {
32 config: auth_config,
33 }
34 }
35
36 pub async fn client_new(&mut self, configs: &config::Config) -> anyhow::Result<client::Client> {
37 use rspotify::clients::BaseClient as _;
38
39 let auth_config = auth::AuthConfig::new(configs)?;
40 let session = auth::new_session(&auth_config, true).await?;
41 let inner = client::Client::new(session, auth_config.to_owned(), configs.app_config.client_id.to_owned());
42 inner.refresh_token().await?;
43
44 self.config = auth_config;
45
46 Ok(inner)
47 }
48}
49
50
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55 use prelude::*;
56
57 #[tokio::test]
58 async fn it_works() -> anyhow::Result<()> {
59 let config = Config::from_pass("", "");
60 let mut handler = ClientHandler::new();
61 let client = handler.client_new(&config).await?;
62 let track_id = TrackId::from_id("6D6Pybzey0shI8U9ttRAPx")?;
63 let result = client.track(track_id, None).await?;
64
65 dbg!(result);
66
67 Ok(())
68 }
69}