use std::{future::Future, str::FromStr};
use serde::de::DeserializeOwned;
use crate::errors::OapiError;
pub trait Delete {
fn build_url(&self, base_url: &str) -> Result<String, OapiError>;
}
pub trait DeleteNoStream: Delete + Send + Sync {
type Response: DeserializeOwned + FromStr<Err = OapiError> + Send + Sync;
fn get_response_string(
&self,
client: &reqwest::Client,
base_url: &str,
key: &str,
) -> impl Future<Output = Result<String, OapiError>> + Send + Sync {
async move {
let url = self.build_url(base_url)?;
let response = client
.delete(url)
.header("Accept", "application/json")
.bearer_auth(key)
.send()
.await?;
crate::rest::response_text_checked(response).await
}
}
fn get_response(
&self,
client: &reqwest::Client,
base_url: &str,
key: &str,
) -> impl Future<Output = Result<Self::Response, OapiError>> + Send + Sync {
async move {
let text = self.get_response_string(client, base_url, key).await?;
let result = Self::Response::from_str(&text)?;
Ok(result)
}
}
}