lastfm_rust/api/
auth.rs

1mod get_session;
2mod get_token;
3
4use crate::Lastfm;
5pub use get_session::AuthGetSession;
6pub use get_token::AuthGetToken;
7
8#[derive(Debug)]
9pub struct Auth<'a> {
10    lastfm: &'a Lastfm,
11    api_key: String,
12}
13
14impl<'a> Auth<'a> {
15    pub(crate) fn new(lastfm: &'a Lastfm) -> Self {
16        Self {
17            lastfm,
18            api_key: lastfm.get_api_key(),
19        }
20    }
21
22    pub fn get_token(&mut self) -> AuthGetToken<'_> {
23        AuthGetToken::new(self.lastfm)
24    }
25
26    pub fn get_session(&mut self) -> AuthGetSession<'_> {
27        AuthGetSession::new(self.lastfm)
28    }
29
30    pub fn get_mobile_session(&mut self) -> AuthGetSession<'_> {
31        //TODO: get mobile session
32        todo!()
33    }
34
35    pub fn pls_authorize(&self, token: String) {
36        println!("{token}");
37        let auth_url = format!(
38            "https://www.last.fm/api/auth?api_key={}&token={}",
39            self.api_key,
40            token.replace("\"", "")
41        );
42
43        println!("Please authorize the application by visiting the following URL:");
44        println!("{}", auth_url);
45        println!("\nOnce you have authorized the app, press Enter to continue...");
46
47        let mut input = String::new();
48        std::io::stdin().read_line(&mut input).unwrap();
49
50        println!("Thank you! Continuing...");
51    }
52}