sharry::api::Uri handling
This commit is contained in:
parent
fd79455de4
commit
f8a748ec07
2 changed files with 10 additions and 16 deletions
|
|
@ -8,7 +8,7 @@ use super::api::Uri;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
||||||
pub struct Alias {
|
pub struct Alias {
|
||||||
pub(super) api_uri: String,
|
pub(super) uri: Uri,
|
||||||
pub(super) id: String,
|
pub(super) id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,15 +23,12 @@ impl<B> SharryAlias for RequestBuilder<B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Alias {
|
impl Alias {
|
||||||
pub fn new(api_uri: Uri, id: impl Into<String>) -> Self {
|
pub fn new(uri: Uri, id: impl Into<String>) -> Self {
|
||||||
Self {
|
Self { uri, id: id.into() }
|
||||||
api_uri: api_uri.into(),
|
|
||||||
id: id.into(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String {
|
pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String {
|
||||||
let uri = format!("{}/{}", self.api_uri, endpoint);
|
let uri = format!("{}/{}", self.uri.to_string(), endpoint);
|
||||||
debug!("endpoint uri: {uri:?}");
|
debug!("endpoint uri: {uri:?}");
|
||||||
|
|
||||||
uri
|
uri
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
||||||
pub struct Uri {
|
pub struct Uri {
|
||||||
protocol: String,
|
protocol: String,
|
||||||
base_url: String,
|
base_url: String,
|
||||||
|
|
@ -14,15 +17,9 @@ impl Uri {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for Uri {
|
impl Display for Uri {
|
||||||
fn from(value: &str) -> Self {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
Self::with_protocol("https", value)
|
write!(f, "{}://{}/api/v2", self.protocol, self.base_url)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Uri> for String {
|
|
||||||
fn from(val: Uri) -> Self {
|
|
||||||
format!("{}://{}/api/v2", val.protocol, val.base_url)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue