impl from_api_url

This commit is contained in:
bitfl0wer 2023-12-03 13:16:34 +01:00
parent 0e1f52edba
commit dc263dbd5a
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
1 changed files with 18 additions and 2 deletions

View File

@ -215,13 +215,29 @@ impl UrlBundle {
{
Ok(response_api)
} else {
Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and if the instance is reachable.".to_string() } )
Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and make sure the instance is reachable.".to_string() } )
}
}
}
async fn from_api_url(url: &str) -> ChorusResult<UrlBundle> {
todo!()
let client = reqwest::Client::new();
let request = client
.get(url)
.header(http::header::ACCEPT, "application/json")
.build()?;
let response = client.execute(request).await?;
if let Ok(body) = response
.json::<types::types::domains_configuration::Domains>()
.await
{
Ok(UrlBundle::new(body.api_endpoint, body.gateway, body.cdn))
} else {
Err(ChorusError::RequestFailed {
url: url.to_string(),
error: "Could not retrieve a UrlBundle from the given url. Check the provided url and make sure the instance is reachable.".to_string(),
})
}
}
}