imgurs/src/api/requests/delete_image.rs

24 lines
639 B
Rust
Raw Normal View History

use reqwest::Method;
2022-01-22 21:02:51 +00:00
2022-06-12 15:41:50 +00:00
use crate::{api_url, send_api_request, Error, ImgurClient, Result};
2022-06-12 15:28:25 +00:00
pub async fn delete_image(client: &ImgurClient, delete_hash: &str) -> Result<()> {
// get imgur api url
let uri = api_url!(format!("image/{delete_hash}"));
2022-01-22 21:02:51 +00:00
// send request to imgur api
let res = send_api_request(client, Method::DELETE, uri, None).await?;
// get response http code
2022-01-22 21:02:51 +00:00
let status = res.status();
// check if an error has occurred
2022-01-22 21:02:51 +00:00
if status.is_client_error() || status.is_server_error() {
2022-06-12 15:28:25 +00:00
let body = res.text().await?;
2022-06-12 15:28:25 +00:00
Err(Error::ApiError(status.as_u16(), body))?;
2022-01-22 21:02:51 +00:00
}
Ok(())
2022-01-22 21:02:51 +00:00
}