Skip to main content

esi_openapi/groups/
faction_warfare.rs

1use crate::prelude::*;
2
3/// Endpoints for FactionWarfare
4pub struct FactionWarfareGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8#[derive(Debug, Deserialize)]
9#[allow(missing_docs)]
10pub struct FactionLeaderboardItem {
11    pub amount: Option<i64>,
12    pub faction_id: Option<i64>,
13}
14
15#[derive(Debug, Deserialize)]
16#[allow(missing_docs)]
17pub struct FactionLeaderboardListing {
18    pub active_total: Vec<FactionLeaderboardItem>,
19    pub last_week: Vec<FactionLeaderboardItem>,
20    pub yesterday: Vec<FactionLeaderboardItem>,
21}
22
23#[derive(Debug, Deserialize)]
24#[allow(missing_docs)]
25pub struct FWLeaderboards {
26    pub kills: FactionLeaderboardListing,
27    pub victory_points: FactionLeaderboardListing,
28}
29
30#[derive(Debug, Deserialize)]
31#[allow(missing_docs)]
32pub struct CharacterLeaderboardItem {
33    pub amount: i64,
34    pub character_id: i64,
35}
36
37#[derive(Debug, Deserialize)]
38#[allow(missing_docs)]
39pub struct CharacterLeaderboardListing {
40    pub active_total: Vec<CharacterLeaderboardItem>,
41    pub last_week: Vec<CharacterLeaderboardItem>,
42    pub yesterday: Vec<CharacterLeaderboardItem>,
43}
44
45#[derive(Debug, Deserialize)]
46#[allow(missing_docs)]
47pub struct FWCharacterLeaderboards {
48    pub kills: CharacterLeaderboardListing,
49    pub victory_points: CharacterLeaderboardListing,
50}
51
52#[derive(Debug, Deserialize)]
53#[allow(missing_docs)]
54pub struct CorporationLeaderboardItem {
55    pub amount: i64,
56    pub corporation_id: i64,
57}
58
59#[derive(Debug, Deserialize)]
60#[allow(missing_docs)]
61pub struct CorporationLeaderboardListing {
62    pub active_total: Vec<CorporationLeaderboardItem>,
63    pub last_week: Vec<CorporationLeaderboardItem>,
64    pub yesterday: Vec<CorporationLeaderboardItem>,
65}
66
67#[derive(Debug, Deserialize)]
68#[allow(missing_docs)]
69pub struct FWCorporationLeaderboards {
70    pub kills: CorporationLeaderboardListing,
71    pub victory_points: CorporationLeaderboardListing,
72}
73
74#[derive(Debug, Deserialize)]
75#[allow(missing_docs)]
76pub struct FWStatsItemRange {
77    pub total: i64,
78    pub last_week: i64,
79    pub yesterday: i64,
80}
81
82#[derive(Debug, Deserialize)]
83#[allow(missing_docs)]
84pub struct FWStatsItem {
85    pub faction_id: i64,
86    pub kills: FWStatsItemRange,
87    pub pilots: i64,
88    pub systems_controlled: i64,
89    pub victory_points: FWStatsItemRange,
90}
91
92#[derive(Debug, Deserialize)]
93#[allow(missing_docs)]
94pub struct FWSystem {
95    pub contested: String,
96    pub occupier_faction_id: i64,
97    pub owner_faction_id: i64,
98    pub solar_system_id: i64,
99    pub victory_points: i64,
100    pub victory_points_threshold: i64,
101}
102
103#[derive(Debug, Deserialize)]
104#[allow(missing_docs)]
105pub struct FWWar {
106    pub faction_id: i64,
107    pub against_id: i64,
108}
109
110impl FactionWarfareGroup<'_> {
111    api_get!(
112        /// Get the top 4 leaderboards of factions for total, last week, and yesterday.
113        leaderboards,
114        "GetFwLeaderboards",
115        RequestType::Public,
116        FWLeaderboards,
117    );
118
119    api_get!(
120        /// Get top 100 characters for total, last week, and yesterday.
121        leaderboard_characters,
122        "GetFwLeaderboardsCharacters",
123        RequestType::Public,
124        FWCharacterLeaderboards,
125    );
126
127    api_get!(
128        /// Get top 10 corporations for total, last week, and yesterday.
129        leaderboard_corporations,
130        "GetFwLeaderboardsCorporations",
131        RequestType::Public,
132        FWCorporationLeaderboards,
133    );
134
135    api_get!(
136        /// Get FW overview stats.
137        stats,
138        "GetFwStats",
139        RequestType::Public,
140        Vec<FWStatsItem>,
141    );
142
143    api_get!(
144        /// Get FW system ownership.
145        systems,
146        "GetFwSystems",
147        RequestType::Public,
148        Vec<FWSystem>,
149    );
150
151    api_get!(
152        /// Get FW faction information.
153        wars,
154        "GetFwWars",
155        RequestType::Public,
156        Vec<FWWar>,
157    );
158
159    // more endpoints ...
160}
161
162/// Faction warfare statistics of a character.
163#[derive(Debug, Deserialize)]
164#[allow(missing_docs)]
165pub struct CharacterFwStats {
166    pub current_rank: Option<i64>,
167    pub enlisted_on: Option<String>,
168    pub faction_id: Option<i64>,
169    pub highest_rank: Option<i64>,
170    pub kills: FWStatsItemRange,
171    pub victory_points: FWStatsItemRange,
172}
173
174impl FactionWarfareGroup<'_> {
175    api_get!(
176        /// Get the faction warfare statistics of a character.
177        get_character_stats,
178        "GetCharactersCharacterIdFwStats",
179        RequestType::Authenticated,
180        CharacterFwStats,
181        (character_id: i64) => "{character_id}"
182    );
183}
184
185#[cfg(test)]
186mod character_basic_tests {
187    use super::CharacterFwStats;
188
189    #[test]
190    fn test_parse_stats_of_unenlisted_character() {
191        let json = r#"{"kills": {"last_week": 0, "total": 3, "yesterday": 0},
192            "victory_points": {"last_week": 0, "total": 10, "yesterday": 0}}"#;
193        let stats: CharacterFwStats = serde_json::from_str(json).unwrap();
194        assert!(stats.faction_id.is_none());
195        assert_eq!(stats.kills.total, 3);
196    }
197}
198
199/// Faction warfare statistics of a corporation.
200#[derive(Debug, Deserialize)]
201#[allow(missing_docs)]
202pub struct CorporationFwStats {
203    pub enlisted_on: Option<String>,
204    pub faction_id: Option<i64>,
205    pub kills: FWStatsItemRange,
206    pub pilots: Option<i64>,
207    pub victory_points: FWStatsItemRange,
208}
209
210impl FactionWarfareGroup<'_> {
211    api_get!(
212        /// Get the faction warfare statistics of a corporation.
213        get_corporation_stats,
214        "GetCorporationsCorporationIdFwStats",
215        RequestType::Authenticated,
216        CorporationFwStats,
217        (corporation_id: i64) => "{corporation_id}"
218    );
219}