36 lines
819 B
Rust
36 lines
819 B
Rust
use std::fmt::{Debug, Display};
|
|
|
|
use log::debug;
|
|
use serde::{Deserialize, Serialize};
|
|
use ureq::RequestBuilder;
|
|
|
|
use super::api::Uri;
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
|
pub struct Alias {
|
|
pub(super) uri: Uri,
|
|
pub(super) id: String,
|
|
}
|
|
|
|
pub(super) trait SharryAlias {
|
|
fn sharry_header(self, alias: &Alias) -> Self;
|
|
}
|
|
|
|
impl<B> SharryAlias for RequestBuilder<B> {
|
|
fn sharry_header(self, alias: &Alias) -> Self {
|
|
self.header("Sharry-Alias", &alias.id)
|
|
}
|
|
}
|
|
|
|
impl Alias {
|
|
pub fn new(uri: Uri, id: impl Into<String>) -> Self {
|
|
Self { uri, id: id.into() }
|
|
}
|
|
|
|
pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String {
|
|
let uri = format!("{}/{}", self.uri.to_string(), endpoint);
|
|
debug!("endpoint uri: {uri:?}");
|
|
|
|
uri
|
|
}
|
|
}
|