1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::io;
use anyhow::Error;
use reqwest::Method;
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
pub async fn get_image(client: &ImgurClient, image: String) -> Result<ImageInfo, Error> {
let uri = api_url!(format!("image/{image}"));
let res = send_api_request(client, Method::GET, uri, None).await?;
let status = res.status();
if status.is_client_error() || status.is_server_error() {
let err = io::Error::new(
io::ErrorKind::Other,
format!("server returned non-successful status code = {status}"),
);
Err(err.into())
} else {
let content: ImageInfo = res.json().await?;
Ok(content)
}
}