Skip to content

Commit

Permalink
feat(Cli): add function check anilist status
Browse files Browse the repository at this point in the history
  • Loading branch information
josueBarretogit committed Dec 20, 2024
1 parent d658b61 commit b17056b
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 203 deletions.
105 changes: 69 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ epub-builder = "0.7.4"
http = "1.0"
keyring = { version = "3", features = ["apple-native", "windows-native", "linux-native"] }
log = { version = "0.4", features = ["std", "serde"] }
simple_logger = "5.0.0"
pretty_env_logger = "0.4"

[dev-dependencies]
httpmock = "0.7.0-rc.1"
Expand Down
36 changes: 33 additions & 3 deletions src/backend/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,38 @@ use std::error::Error;
/// Abstraction of the location where secrets will be stored
pub trait SecretStorage {
fn save_secret<T: Into<String>>(&mut self, secret_name: T, value: T) -> Result<(), Box<dyn Error>>;
fn save_multiple_secrets<T: Into<String>>(&mut self, values: HashMap<T, T>) -> Result<(), Box<dyn Error>>;
fn get_secret<T: Into<String>>(&self, _secret_name: T) -> Result<Option<String>, Box<dyn Error>> {
Err("not implemented".into())

fn save_multiple_secrets<T: Into<String>>(&mut self, values: HashMap<T, T>) -> Result<(), Box<dyn Error>> {
for (name, value) in values {
self.save_secret(name, value)?
}
Ok(())
}

fn remove_multiple_secrets<T: AsRef<str>>(&mut self, values: impl Iterator<Item = T>) -> Result<(), Box<dyn Error>> {
for name in values {
self.remove_secret(name)?
}
Ok(())
}

fn get_multiple_secrets<T: Into<String>>(
&self,
secrets_names: impl Iterator<Item = T>,
) -> Result<HashMap<String, String>, Box<dyn Error>> {
let mut secrets_collected: HashMap<String, String> = HashMap::new();

for secrets in secrets_names {
let secret_to_find: String = secrets.into();
if let Some(secret) = self.get_secret(secret_to_find.clone())? {
secrets_collected.insert(secret_to_find, secret);
}
}

Ok(secrets_collected)
}

fn get_secret<T: Into<String>>(&self, _secret_name: T) -> Result<Option<String>, Box<dyn Error>>;

fn remove_secret<T: AsRef<str>>(&mut self, secret_name: T) -> Result<(), Box<dyn Error>>;
}
16 changes: 7 additions & 9 deletions src/backend/secrets/anilist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use keyring::Entry;
use super::SecretStorage;

#[derive(Debug)]
struct AnilistStorage {
pub struct AnilistStorage {
service_name: &'static str,
}

impl AnilistStorage {
fn new() -> Self {
pub fn new() -> Self {
Self {
service_name: crate_name!(),
}
Expand Down Expand Up @@ -37,13 +37,11 @@ impl SecretStorage for AnilistStorage {
}
}

fn save_multiple_secrets<T: Into<String>>(
&mut self,
values: std::collections::HashMap<T, T>,
) -> Result<(), Box<dyn std::error::Error>> {
for (name, value) in values {
self.save_secret(name, value)?
}
fn remove_secret<T: AsRef<str>>(&mut self, secret_name: T) -> Result<(), Box<dyn std::error::Error>> {
let secret = Entry::new(self.service_name, secret_name.as_ref())?;

secret.delete_credential()?;

Ok(())
}
}
Expand Down
Loading

0 comments on commit b17056b

Please sign in to comment.