-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_async.rs
More file actions
74 lines (60 loc) · 2.56 KB
/
client_async.rs
File metadata and controls
74 lines (60 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
}
}