Skip to content

Commit

Permalink
feat: Implement a authenticate_all for scrobble
Browse files Browse the repository at this point in the history
  • Loading branch information
Losses committed Dec 19, 2024
1 parent 3771378 commit c6bcd4d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scrobbling/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct ScrobblingManager {
retry_delay: Duration,
}

pub struct Credentials {
pub service: ScrobblingService,
pub username: String,
pub password: String,
pub api_key: Option<String>,
pub api_secret: Option<String>,
}

impl ScrobblingManager {
pub fn new(max_retries: u32, retry_delay: Duration) -> Self {
Self {
Expand Down Expand Up @@ -86,6 +94,29 @@ impl ScrobblingManager {
Ok(())
}

pub async fn authenticate_all(
&mut self,
credentials_list: Vec<Credentials>,
) -> HashMap<ScrobblingService, Result<()>> {
let mut results = HashMap::new();

for credentials in credentials_list {
let result = self
.authenticate(
&credentials.service,
&credentials.username,
&credentials.password,
credentials.api_key.clone(),
credentials.api_secret.clone(),
)
.await;

results.insert(credentials.service, result);
}

results
}

pub fn restore_session(
&mut self,
service: &ScrobblingService,
Expand Down

0 comments on commit c6bcd4d

Please sign in to comment.