use reqwest::Method;
use crate::{APIResult, Client, error::{error_from_response, NoSpecificError}};
const PURGE_METHOD: Method = Method::POST;
#[allow(clippy::module_name_repetitions)]
pub async fn purge_url(client: &Client, url: &str, wait: bool) -> APIResult<(), NoSpecificError> {
let post_url = format!("https://api.bunny.net/purge?async={}&url={}", !wait, urlencoding::encode(url));
let request = client
.get(&post_url)
.header("accept", "application/json")
.build()
.map_err(crate::Error::map_request_err(
PURGE_METHOD,
post_url.clone(),
))?;
let resp = client
.send_logged(request)
.await
.map_err(crate::Error::map_request_err(
PURGE_METHOD,
post_url.clone(),
))?;
error_from_response(resp)
.await
.map(|_| ())
.map_err(crate::Error::map_response_err(
PURGE_METHOD,
post_url,
))
}