From 010f6fef158f0d2aba185605578d93105edc51c7 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Wed, 14 Apr 2021 20:15:31 +0200 Subject: [PATCH] added constant for API endpoint for easy updating. --- jm_client_core/src/util.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jm_client_core/src/util.rs b/jm_client_core/src/util.rs index b689047..299143a 100644 --- a/jm_client_core/src/util.rs +++ b/jm_client_core/src/util.rs @@ -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::(&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::(&res.bytes().await?)?;