use reqwest::{Client, Error};
use crate::models::Invite;
const API_BASE: &str = "https://discord.com/api/v7";
fn create_client() -> Client {
debug!("Creating new HTTP client");
Client::builder()
.user_agent("DiscordBot (https://github.com/jos-b/discord, 1.0)")
.build()
.expect("Could not build HTTP client")
}
fn build_route(path: &str) -> String {
debug!("Building route to: {}", path);
format!("{}{}", API_BASE, path)
}
pub async fn get_invite<T: std::fmt::Display>(code: T) -> Result<Invite, Error> {
info!("Starting request to get invite: {}", code);
let invite: Invite = create_client()
.get(&build_route(&format!("/invites/{}", code)))
.send()
.await?
.json()
.await?;
Ok(invite)
}