added constant for API endpoint for easy updating.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
929c38bfed
commit
010f6fef15
1 changed files with 5 additions and 3 deletions
|
@ -17,12 +17,14 @@ macro_rules! init_once_cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod consts {
|
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_CATEGORY_ERROR: &str = "The given Category does not exist!";
|
||||||
pub const NO_SUCH_USER_ERROR: &str = "The given User does not exist!";
|
pub const NO_SUCH_USER_ERROR: &str = "The given User does not exist!";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ways to communicyte with the JM API
|
/// ways to communicyte with the JM API
|
||||||
pub mod api {
|
pub mod api {
|
||||||
|
use super::consts;
|
||||||
use crate::api::{Category, CatsResp, Meme, MemesResp, User, UsersResp};
|
use crate::api::{Category, CatsResp, Meme, MemesResp, User, UsersResp};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -57,7 +59,7 @@ pub mod api {
|
||||||
Ok(init_once_cell!(CATS, {
|
Ok(init_once_cell!(CATS, {
|
||||||
info!("Requesting categories from server");
|
info!("Requesting categories from server");
|
||||||
let res = http
|
let res = http
|
||||||
.get("https://data.tilera.xyz/api/jensmemes/categories")
|
.get(&format!("{}/categories", consts::API_ENDPOINT))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
let cats = try_deserialize_api_reponse::<CatsResp>(&res.bytes().await?)?;
|
let cats = try_deserialize_api_reponse::<CatsResp>(&res.bytes().await?)?;
|
||||||
|
@ -75,7 +77,7 @@ pub mod api {
|
||||||
return Ok(m.clone());
|
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();
|
let mut pairs = url.query_pairs_mut();
|
||||||
|
|
||||||
if let Some(cat) = filters.0.as_ref() {
|
if let Some(cat) = filters.0.as_ref() {
|
||||||
|
@ -105,7 +107,7 @@ pub mod api {
|
||||||
Ok(init_once_cell!(USERS, {
|
Ok(init_once_cell!(USERS, {
|
||||||
info!("Requesting users from server");
|
info!("Requesting users from server");
|
||||||
let res = http
|
let res = http
|
||||||
.get("https://data.tilera.xyz/api/jensmemes/users")
|
.get(&format!("{}/users", consts::API_ENDPOINT))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
let users = try_deserialize_api_reponse::<UsersResp>(&res.bytes().await?)?;
|
let users = try_deserialize_api_reponse::<UsersResp>(&res.bytes().await?)?;
|
||||||
|
|
Loading…
Reference in a new issue