mirror of
https://github.com/MedzikUser/imgurs
synced 2024-08-15 00:03:19 +00:00
33 lines
792 B
Rust
33 lines
792 B
Rust
use super::ImgurClient;
|
|
|
|
use anyhow::Error;
|
|
use reqwest::Method;
|
|
use std::collections::HashMap;
|
|
|
|
pub async fn send_api_request(
|
|
config: &ImgurClient,
|
|
method: Method,
|
|
uri: String,
|
|
form: Option<HashMap<&str, String>>,
|
|
) -> Result<reqwest::Response, Error> {
|
|
let client = &config.client;
|
|
|
|
let mut req = client.request(method, uri.as_str());
|
|
|
|
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
|
|
|
|
req = req
|
|
.header("Authorization", format!("Client-ID {}", config.client_id))
|
|
.header(
|
|
"User-Agent",
|
|
format!("Imgur/{:?}", VERSION.unwrap_or("unknown")),
|
|
);
|
|
|
|
if form != None {
|
|
req = req.form(&form.unwrap())
|
|
}
|
|
|
|
let req = req.build()?;
|
|
|
|
client.execute(req).await.map_err(Error::from)
|
|
}
|