Add utility method to find the service key for a service id

develop
trivernis 11 months ago
parent 1ab5d07ab7
commit 994f45601a
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -1,6 +1,6 @@
use crate::api_core::common::FileIdentifier;
use crate::api_core::common::{FileIdentifier, ServiceIdentifier};
use crate::api_core::endpoints::searching_and_fetching_files::FullMetadata;
use crate::error::Result;
use crate::error::{Error, Result};
use crate::wrapper::address::Address;
use crate::wrapper::builders::delete_files_builder::DeleteFilesBuilder;
use crate::wrapper::builders::import_builder::ImportBuilder;
@ -125,4 +125,25 @@ impl Hydrus {
pub async fn set_user_agent<S: ToString + Debug>(&self, user_agent: S) -> Result<()> {
self.client.set_user_agent(user_agent).await
}
/// Returns the key for a given service identifier
pub async fn get_service_key(&self, service: ServiceIdentifier) -> Result<String> {
let key = match service {
ServiceIdentifier::Name(n) => self
.client
.get_services()
.await?
.other
.values()
.flatten()
.filter(|v| *v.name == n)
.next()
.ok_or_else(|| Error::Hydrus(String::from("Service not found")))?
.service_key
.clone(),
ServiceIdentifier::Key(k) => k,
};
Ok(key)
}
}

Loading…
Cancel
Save