gyazo_api/delete.rs
1use super::Gyazo;
2
3#[derive(serde::Deserialize, Debug)]
4/// Response returned after deleting an image.
5pub struct DeleteResponse {
6 /// ID of the deleted image.
7 pub image_id: String,
8 /// Type of the response.
9 pub r#type: String,
10}
11
12impl Gyazo {
13 /// Deletes an image from Gyazo.
14 ///
15 /// # Arguments
16 ///
17 /// * `image_id` - The ID of the image to delete.
18 ///
19 /// # Returns
20 ///
21 /// A `Result` containing `DeleteResponse` on success or a `reqwest::Error` on failure.
22 // TODO: test
23 pub async fn delete(&self, image_id: &str) -> Result<DeleteResponse, reqwest::Error> {
24 let url = format!("https://api.gyazo.com/api/images/{}", image_id);
25 let res = self
26 .client
27 .delete(&url)
28 .query(&[("access_token", &self.access_token)])
29 .send()
30 .await?
31 .error_for_status()?
32 .json::<DeleteResponse>()
33 .await?;
34
35 Ok(res)
36 }
37}