imgurs/imgur/requests/
get_image.rs

1use 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    // get imgur api url
7    let uri = api_url!(format!("image/{image}"));
8
9    // send request to imgur api
10    let res = send_api_request(client, Method::GET, uri, None).await?;
11
12    // get response http code
13    let status = res.status();
14
15    // check if an error has occurred
16    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    // return `ImageInfo`
23    Ok(res.json().await?)
24}