added constant for API endpoint for easy updating.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
LordMZTE 2021-04-14 20:15:31 +02:00
parent 929c38bfed
commit 010f6fef15

View file

@ -17,12 +17,14 @@ macro_rules! init_once_cell {
}
pub mod consts {
pub const API_ENDPOINT: &str = "https://data.tilera.xyz/api/jensmemes";
pub const NO_SUCH_CATEGORY_ERROR: &str = "The given Category does not exist!";
pub const NO_SUCH_USER_ERROR: &str = "The given User does not exist!";
}
/// ways to communicyte with the JM API
pub mod api {
use super::consts;
use crate::api::{Category, CatsResp, Meme, MemesResp, User, UsersResp};
use anyhow::Result;
use lazy_static::lazy_static;
@ -57,7 +59,7 @@ pub mod api {
Ok(init_once_cell!(CATS, {
info!("Requesting categories from server");
let res = http
.get("https://data.tilera.xyz/api/jensmemes/categories")
.get(&format!("{}/categories", consts::API_ENDPOINT))
.send()
.await?;
let cats = try_deserialize_api_reponse::<CatsResp>(&res.bytes().await?)?;
@ -75,7 +77,7 @@ pub mod api {
return Ok(m.clone());
}
let mut url = Url::options().parse("https://data.tilera.xyz/api/jensmemes/memes")?;
let mut url = Url::options().parse(&format!("{}/memes", consts::API_ENDPOINT))?;
let mut pairs = url.query_pairs_mut();
if let Some(cat) = filters.0.as_ref() {
@ -105,7 +107,7 @@ pub mod api {
Ok(init_once_cell!(USERS, {
info!("Requesting users from server");
let res = http
.get("https://data.tilera.xyz/api/jensmemes/users")
.get(&format!("{}/users", consts::API_ENDPOINT))
.send()
.await?;
let users = try_deserialize_api_reponse::<UsersResp>(&res.bytes().await?)?;