Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
671 changes: 491 additions & 180 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "3"
members = [
"datafeed-cache-client",
"datafeed-cache-server",
Expand Down
7 changes: 5 additions & 2 deletions datafeed-cache-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[package]
name = "datafeed-cache-client"
edition = "2024"
version = "1.3.2"
version = "1.3.3"

[dependencies]
reqwest = { version = "0.12.15", features = ["json"] }
reqwest = { version = "0.13.1", features = ["json"] }
serde = { version = "1.0.219", features = ["derive"] }
dotenv = { version = "0.15.0" }
datafeed-cache-shared = { path = "../datafeed-cache-shared" }
env_logger = "0.11.7"
log = "0.4.27"

[features]
blocking = ["reqwest/blocking"]

[lib]
name = "datafeed_cache_client"
path = "src/lib.rs"
87 changes: 34 additions & 53 deletions datafeed-cache-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,74 @@ use datafeed_cache_shared::datafeed::{
DatafeedAtis, DatafeedController, DatafeedMilitaryRating, DatafeedPilot, DatafeedPilotRating,
DatafeedServer,
};
use datafeed_cache_shared::response::{
DatafeedGeneralResponse, DatafeedListResponse, DatafeedResponse,
};
use log::info;
use reqwest::Client;
use datafeed_cache_shared::response::{DatafeedGeneralResponse, DatafeedGerStatsResponse, DatafeedListResponse, DatafeedResponse};
use serde::de::DeserializeOwned;

pub struct DatafeedClient {
client: Client,
base_url: String,
}

const BASE_DEFAULT: &'static str = "https://df.vatsim-germany.org";
use crate::DatafeedClient;

type Error = reqwest::Error;

#[allow(dead_code)]
impl DatafeedClient {
pub fn new() -> Self {
let _ = env_logger::try_init();
let _ = dotenv::dotenv();

let base_url: String = dotenv::var("BASE_URL").unwrap_or(BASE_DEFAULT.to_string());
info!("Selected BASE_URL: {}", base_url);

DatafeedClient {
client: Client::default(),
base_url,
}
}

async fn make_request<T>(&self, path: &str) -> Result<T, Error>
fn make_request<T>(&self, path: &str) -> Result<T, Error>
where
T: DeserializeOwned,
{
let req = self.client.get(self.base_url.to_owned() + path).build()?;
let response = self.client.execute(req).await?;
response.json::<T>().await
let response = self.client.execute(req)?;
response.json::<T>()
}

pub async fn get(&self) -> Result<DatafeedResponse, Error> {
self.make_request("/datafeed").await
pub fn get(&self) -> Result<DatafeedResponse<'_>, Error> {
self.make_request("/datafeed")
}

pub async fn get_general(&self) -> Result<DatafeedGeneralResponse, Error> {
self.make_request("/datafeed/general").await
pub fn get_general(&self) -> Result<DatafeedGeneralResponse<'_>, Error> {
self.make_request("/datafeed/general")
}

pub async fn get_controllers(&self) -> Result<DatafeedListResponse<DatafeedController>, Error> {
self.make_request("/datafeed/controllers").await
pub fn get_controllers(&self) -> Result<DatafeedListResponse<'_, DatafeedController>, Error> {
self.make_request("/datafeed/controllers")
}

pub async fn get_pilots(&self) -> Result<DatafeedListResponse<DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots").await
pub fn get_pilots(&self) -> Result<DatafeedListResponse<'_, DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots")
}

pub async fn get_atis(&self) -> Result<DatafeedListResponse<DatafeedAtis>, Error> {
self.make_request("/datafeed/atis").await
pub fn get_atis(&self) -> Result<DatafeedListResponse<'_, DatafeedAtis>, Error> {
self.make_request("/datafeed/atis")
}

pub async fn get_servers(&self) -> Result<DatafeedListResponse<DatafeedServer>, Error> {
self.make_request("/datafeed/servers").await
pub fn get_servers(&self) -> Result<DatafeedListResponse<'_, DatafeedServer>, Error> {
self.make_request("/datafeed/servers")
}

pub async fn get_pilot_ratings(
pub fn get_pilot_ratings(
&self,
) -> Result<DatafeedListResponse<DatafeedPilotRating>, Error> {
self.make_request("/datafeed/pilot_ratings").await
) -> Result<DatafeedListResponse<'_, DatafeedPilotRating>, Error> {
self.make_request("/datafeed/pilot_ratings")
}

pub async fn get_military_ratings(
pub fn get_military_ratings(
&self,
) -> Result<DatafeedListResponse<DatafeedMilitaryRating>, Error> {
self.make_request("/datafeed/military_ratings").await
) -> Result<DatafeedListResponse<'_, DatafeedMilitaryRating>, Error> {
self.make_request("/datafeed/military_ratings")
}

pub async fn get_ger_controllers(
pub fn get_ger_controllers(
&self,
) -> Result<DatafeedListResponse<DatafeedController>, Error> {
self.make_request("/datafeed/controllers/ger").await
) -> Result<DatafeedListResponse<'_, DatafeedController>, Error> {
self.make_request("/datafeed/controllers/ger")
}

pub fn get_ger_pilots(&self) -> Result<DatafeedListResponse<'_, DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots/ger")
}

pub async fn get_ger_pilots(&self) -> Result<DatafeedListResponse<DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots/ger").await
pub fn get_ger_atis(&self) -> Result<DatafeedListResponse<'_, DatafeedAtis>, Error> {
self.make_request("/datafeed/atis/ger")
}

pub async fn get_ger_atis(&self) -> Result<DatafeedListResponse<DatafeedAtis>, Error> {
self.make_request("/datafeed/atis/ger").await
pub fn get_ger_stats(&self) -> Result<DatafeedGerStatsResponse, Error> {
self.make_request("/datafeed/stats")
}
}
74 changes: 74 additions & 0 deletions datafeed-cache-client/src/client_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use datafeed_cache_shared::datafeed::{
DatafeedAtis, DatafeedController, DatafeedMilitaryRating, DatafeedPilot, DatafeedPilotRating,
DatafeedServer,
};
use datafeed_cache_shared::response::{DatafeedGeneralResponse, DatafeedGerStatsResponse, DatafeedListResponse, DatafeedResponse};
use serde::de::DeserializeOwned;
use crate::DatafeedClient;

type Error = reqwest::Error;

impl DatafeedClient {
async fn make_request<T>(&self, path: &str) -> Result<T, Error>
where
T: DeserializeOwned,
{
let req = self.client.get(self.base_url.to_owned() + path).build()?;
let response = self.client.execute(req).await?;
response.json::<T>().await
}

pub async fn get(&self) -> Result<DatafeedResponse<'_>, Error> {
self.make_request("/datafeed").await
}

pub async fn get_general(&self) -> Result<DatafeedGeneralResponse<'_>, Error> {
self.make_request("/datafeed/general").await
}

pub async fn get_controllers(&self) -> Result<DatafeedListResponse<'_, DatafeedController>, Error> {
self.make_request("/datafeed/controllers").await
}

pub async fn get_pilots(&self) -> Result<DatafeedListResponse<'_, DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots").await
}

pub async fn get_atis(&self) -> Result<DatafeedListResponse<'_,DatafeedAtis>, Error> {
self.make_request("/datafeed/atis").await
}

pub async fn get_servers(&self) -> Result<DatafeedListResponse<'_,DatafeedServer>, Error> {
self.make_request("/datafeed/servers").await
}

pub async fn get_pilot_ratings(
&self,
) -> Result<DatafeedListResponse<'_,DatafeedPilotRating>, Error> {
self.make_request("/datafeed/pilot_ratings").await
}

pub async fn get_military_ratings(
&self,
) -> Result<DatafeedListResponse<'_,DatafeedMilitaryRating>, Error> {
self.make_request("/datafeed/military_ratings").await
}

pub async fn get_ger_controllers(
&self,
) -> Result<DatafeedListResponse<'_,DatafeedController>, Error> {
self.make_request("/datafeed/controllers/ger").await
}

pub async fn get_ger_pilots(&self) -> Result<DatafeedListResponse<'_,DatafeedPilot>, Error> {
self.make_request("/datafeed/pilots/ger").await
}

pub async fn get_ger_atis(&self) -> Result<DatafeedListResponse<'_,DatafeedAtis>, Error> {
self.make_request("/datafeed/atis/ger").await
}

pub async fn get_ger_stats(&self) -> Result<DatafeedGerStatsResponse, Error> {
self.make_request("/datafeed/stats").await
}
}
35 changes: 33 additions & 2 deletions datafeed-cache-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
use log::info;

#[cfg(feature = "blocking")]
pub mod client;

#[cfg(feature = "blocking")]
use reqwest::blocking::Client;

#[cfg(not(feature = "blocking"))]
pub mod client_async;

#[cfg(not(feature = "blocking"))]
use reqwest::Client;

pub mod shared {
pub use datafeed_cache_shared::*;
}

// TODO: Add Tests here which force the functions to work, even if the datafeed-cache has been
// TODO: modified
pub struct DatafeedClient {
client: Client,
base_url: String,
}

const BASE_DEFAULT: &'static str = "https://df.vatsim-germany.org";

impl DatafeedClient {
pub fn new() -> Self {
let _ = env_logger::try_init();
let _ = dotenv::dotenv();

let base_url: String = dotenv::var("BASE_URL").unwrap_or(BASE_DEFAULT.to_string());
info!("Selected BASE_URL: {}", base_url);

DatafeedClient {
client: Client::default(),
base_url,
}
}
}
7 changes: 4 additions & 3 deletions datafeed-cache-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[package]
name = "datafeed-cache-server"
edition = "2024"
version = "1.3.2"
version = "1.3.3"

[dependencies]
tokio = { version = "1.44.1", features = ["macros", "rt-multi-thread", "time"] }
actix-web = { version = "4.10.2" }
reqwest = { version = "0.12.15", features = ["json"] }
reqwest = { version = "0.13.1", features = ["json"] }
serde = { version = "1.0.219", features = ["derive"] }
rand = "0.9.0"
env_logger = "0.11.7"
log = "0.4.27"
geo = { version = "0.31.0" }
geo = { version = "0.32.0" }
chrono = { version = "0.4.40", features = ["serde"] }
datafeed-cache-shared = { path = "../datafeed-cache-shared" }
once_cell = "1.21.3"

[[bin]]
name = "datafeed_cache_server"
Expand Down
Loading