Dynamically resolve runelite api version rather than hardcoding it
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
4a8812299b
commit
7dd317512d
2 changed files with 25 additions and 2 deletions
|
@ -1,9 +1,31 @@
|
||||||
pub mod player_count;
|
pub mod player_count;
|
||||||
pub mod stats;
|
pub mod stats;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
pub trait PromMetric {
|
pub trait PromMetric {
|
||||||
fn to_metric_string(self: &Self) -> String;
|
fn to_metric_string(self: &Self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const USER_AGENT: &str = "osrs-prometheus-exporter";
|
pub const USER_AGENT: &str = "osrs-prometheus-exporter";
|
||||||
pub const RUNELITE_API_VERSION: &str = "runelite-1.9.13";
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct GithubTag {
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_runelite_version() -> eyre::Result<String> {
|
||||||
|
let resp = reqwest::Client::new()
|
||||||
|
.get("https://api.github.com/repos/runelite/runelite/tags")
|
||||||
|
.header("User-Agent", USER_AGENT)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.json::<Vec<GithubTag>>()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Some(latest) = resp.first() {
|
||||||
|
Ok(latest.name.replace("parent-", ""))
|
||||||
|
} else {
|
||||||
|
Err(eyre::eyre!("Failed to get github tags for runelite version"))
|
||||||
|
}
|
||||||
|
}
|
|
@ -122,7 +122,8 @@ impl World {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_player_count() -> eyre::Result<Vec<World>> {
|
pub async fn get_player_count() -> eyre::Result<Vec<World>> {
|
||||||
let req_url = format!("https://api.runelite.net/{}/worlds.js", super::RUNELITE_API_VERSION);
|
let runelite_version = super::get_runelite_version().await?;
|
||||||
|
let req_url = format!("https://api.runelite.net/{}/worlds.js", runelite_version);
|
||||||
let resp = reqwest::Client::new()
|
let resp = reqwest::Client::new()
|
||||||
.get(req_url)
|
.get(req_url)
|
||||||
.header("User-Agent", super::USER_AGENT)
|
.header("User-Agent", super::USER_AGENT)
|
||||||
|
|
Loading…
Reference in a new issue