2025-05-24 00:22:24 +00:00
|
|
|
use std::fmt::{Debug, Display};
|
|
|
|
|
|
2025-05-23 22:13:17 +00:00
|
|
|
use log::debug;
|
2025-05-24 00:22:24 +00:00
|
|
|
use ureq::RequestBuilder;
|
2025-05-23 22:13:17 +00:00
|
|
|
|
2025-05-26 23:56:31 +00:00
|
|
|
use super::api::Uri;
|
2025-05-23 22:13:17 +00:00
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Alias {
|
2025-05-24 00:22:24 +00:00
|
|
|
pub(super) api_uri: String,
|
2025-05-23 22:13:17 +00:00
|
|
|
pub(super) id: String,
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-24 00:22:24 +00:00
|
|
|
pub(super) trait SharryAlias {
|
|
|
|
|
fn sharry_header(self, alias: &Alias) -> Self;
|
|
|
|
|
}
|
2025-05-23 22:13:17 +00:00
|
|
|
|
2025-05-24 00:22:24 +00:00
|
|
|
impl<B> SharryAlias for RequestBuilder<B> {
|
|
|
|
|
fn sharry_header(self, alias: &Alias) -> Self {
|
|
|
|
|
self.header("Sharry-Alias", &alias.id)
|
2025-05-23 22:13:17 +00:00
|
|
|
}
|
2025-05-24 00:22:24 +00:00
|
|
|
}
|
2025-05-23 22:13:17 +00:00
|
|
|
|
2025-05-24 00:22:24 +00:00
|
|
|
impl Alias {
|
2025-05-26 23:56:31 +00:00
|
|
|
pub fn new(api_uri: Uri, id: impl Into<String>) -> Self {
|
2025-05-24 00:22:24 +00:00
|
|
|
Self {
|
|
|
|
|
api_uri: api_uri.into(),
|
|
|
|
|
id: id.into(),
|
2025-05-23 22:13:17 +00:00
|
|
|
}
|
2025-05-24 00:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String {
|
|
|
|
|
let uri = format!("{}/{}", self.api_uri, endpoint);
|
2025-05-26 23:56:31 +00:00
|
|
|
debug!("endpoint uri: {uri:?}");
|
2025-05-23 22:13:17 +00:00
|
|
|
|
2025-05-24 00:22:24 +00:00
|
|
|
uri
|
2025-05-23 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
}
|