imgurs/imgur/requests/
get_image.rs1use reqwest::Method;
2
3use crate::{api_url, send_api_request, Error, ImageInfo, ImgurClient, Result};
4
5pub async fn get_image(client: &ImgurClient, image: &str) -> Result<ImageInfo> {
6 let uri = api_url!(format!("image/{image}"));
8
9 let res = send_api_request(client, Method::GET, uri, None).await?;
11
12 let status = res.status();
14
15 if status.is_client_error() || status.is_server_error() {
17 let body = res.text().await?;
18
19 return Err(Error::ApiError(status.as_u16(), body));
20 }
21
22 Ok(res.json().await?)
24}