Skip to main content

esi_openapi/groups/
universe.rs

1#![allow(unused)]
2
3use crate::prelude::*;
4
5/// Endpoints for Universe
6pub struct UniverseGroup<'a> {
7    pub(crate) esi: &'a Esi,
8}
9
10/// A position in space, in meters.
11#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
12#[allow(missing_docs)]
13pub struct Position {
14    pub x: f64,
15    pub y: f64,
16    pub z: f64,
17}
18
19#[derive(Debug, Deserialize, Serialize, Clone)]
20#[allow(missing_docs)]
21pub struct Constellation {
22    pub constellation_id: i64,
23    pub name: String,
24    pub position: Position,
25    pub region_id: i64,
26    pub systems: Vec<i64>,
27}
28
29#[derive(Debug, Deserialize, Serialize, Clone)]
30#[allow(missing_docs)]
31pub struct Region {
32    pub constellations: Vec<i64>,
33    pub description: Option<String>,
34    pub name: String,
35    pub region_id: i64,
36}
37
38#[derive(Debug, Deserialize, Serialize, Clone)]
39#[allow(missing_docs)]
40pub struct SystemPlanet {
41    pub asteroid_belts: Option<Vec<i64>>,
42    pub moons: Option<Vec<i64>>,
43    pub planet_id: i64,
44}
45
46#[derive(Debug, Deserialize, Serialize, Clone)]
47#[allow(missing_docs)]
48pub struct System {
49    pub constellation_id: i64,
50    pub name: String,
51    pub planets: Option<Vec<SystemPlanet>>,
52    pub position: Position,
53    pub security_class: Option<String>,
54    pub security_status: f64,
55    pub star_id: Option<i64>,
56    pub stargates: Option<Vec<i64>>,
57    pub stations: Option<Vec<i64>>,
58    pub system_id: i64,
59}
60
61#[derive(Debug, Deserialize)]
62#[allow(missing_docs)]
63pub struct Ids {
64    pub characters: Option<Vec<Category>>,
65    pub alliances: Option<Vec<Category>>,
66    pub constellations: Option<Vec<Category>>,
67    pub agents: Option<Vec<Category>>,
68    pub regions: Option<Vec<Category>>,
69    pub systems: Option<Vec<Category>>,
70    pub stations: Option<Vec<Category>>,
71}
72
73#[derive(Debug, Deserialize)]
74#[allow(missing_docs)]
75pub struct Category {
76    pub id: i64,
77    pub name: String,
78}
79
80#[derive(Debug, Deserialize, Serialize, Clone)]
81#[allow(missing_docs)]
82pub struct TypeDogmaAttribute {
83    pub attribute_id: i64,
84    pub value: f64,
85}
86
87#[derive(Debug, Deserialize, Serialize, Clone)]
88#[allow(missing_docs)]
89pub struct TypeDogmaEffect {
90    pub effect_id: i64,
91    pub is_default: bool,
92}
93
94#[derive(Debug, Deserialize, Serialize, Clone)]
95#[allow(missing_docs)]
96pub struct Type {
97    pub capacity: Option<f64>,
98    pub description: String,
99    pub dogma_attributes: Option<Vec<TypeDogmaAttribute>>,
100    pub dogma_effects: Option<Vec<TypeDogmaEffect>>,
101    pub graphic_id: Option<i64>,
102    pub group_id: i64,
103    pub icon_id: Option<i64>,
104    pub market_group_id: Option<i64>,
105    pub mass: Option<f64>,
106    pub name: String,
107    pub packaged_volume: Option<f64>,
108    pub portion_size: Option<i64>,
109    pub published: bool,
110    pub radius: Option<f64>,
111    pub type_id: i64,
112    pub volume: Option<f64>,
113}
114
115#[derive(Debug, Deserialize, Serialize, Clone)]
116#[allow(missing_docs)]
117pub struct Station {
118    pub max_dockable_ship_volume: f64,
119    pub name: String,
120    pub office_rental_cost: f64,
121    pub owner: Option<i64>,
122    pub position: Position,
123    pub race_id: Option<i64>,
124    pub reprocessing_efficiency: f64,
125    pub reprocessing_stations_take: f64,
126    pub services: Vec<String>,
127    pub station_id: i64,
128    pub system_id: i64,
129    pub type_id: i64,
130}
131
132#[derive(Debug, Deserialize, Serialize, Clone)]
133#[allow(missing_docs)]
134pub struct Structure {
135    pub name: String,
136    pub owner_id: i64,
137    pub position: Option<Position>,
138    pub solar_system_id: i64,
139    pub type_id: Option<i64>,
140}
141
142#[derive(Debug, Deserialize, Serialize, Clone)]
143#[allow(missing_docs)]
144pub struct CategoriesCategory {
145    pub category_id: i64,
146    pub groups: Vec<i64>,
147    pub name: String,
148    pub published: bool,
149}
150
151#[derive(Debug, Deserialize, Serialize, Clone)]
152#[allow(missing_docs)]
153pub struct Group {
154    pub category_id: i64,
155    pub group_id: i64,
156    pub name: String,
157    pub published: bool,
158    pub types: Vec<i64>,
159}
160
161impl UniverseGroup<'_> {
162    api_get!(
163        /// Get information on a category
164        get_universe_categories_category,
165        "GetUniverseCategoriesCategoryId",
166        RequestType::Public,
167        CategoriesCategory,
168        (category_id: i64) => "{category_id}"
169    );
170
171    api_get!(
172        /// Get information on a group
173        get_universe_groups_group,
174        "GetUniverseGroupsGroupId",
175        RequestType::Public,
176        Group,
177        (group_id: i64) => "{group_id}"
178    );
179
180    api_get!(
181        /// Get information on a type
182        get_universe_types_type,
183        "GetUniverseTypesTypeId",
184        RequestType::Public,
185        Type,
186        (type_id: i64) => "{type_id}"
187    );
188
189    api_get!(
190        /// Get a list of constellation ids
191        get_constellation_ids,
192        "GetUniverseConstellations",
193        RequestType::Public,
194        Vec<i64>,
195    );
196
197    api_get!(
198        /// Get information on a constellation
199        get_constellation,
200        "GetUniverseConstellationsConstellationId",
201        RequestType::Public,
202        Constellation,
203        (constellation_id: i64) => "{constellation_id}"
204    );
205
206    api_get!(
207        /// Get a list of region ids
208        get_region_ids,
209        "GetUniverseRegions",
210        RequestType::Public,
211        Vec<i64>,
212    );
213
214    api_get!(
215        /// Get information on a region
216        get_region,
217        "GetUniverseRegionsRegionId",
218        RequestType::Public,
219        Region,
220        (region_id: i64) => "{region_id}"
221    );
222
223    api_get!(
224        /// Get a list of system ids
225        get_system_ids,
226        "GetUniverseSystems",
227        RequestType::Public,
228        Vec<i64>,
229    );
230
231    api_get!(
232        /// Get information on a system
233        get_system,
234        "GetUniverseSystemsSystemId",
235        RequestType::Public,
236        System,
237        (system_id: i64) => "{system_id}"
238    );
239
240    api_get!(
241        /// Get a list of type ids
242        get_type_ids,
243        "GetUniverseTypes",
244        RequestType::Public,
245        Vec<i64>,
246    );
247
248    api_get!(
249        /// Get information on a type
250        get_type,
251        "GetUniverseTypesTypeId",
252        RequestType::Public,
253        Type,
254        (type_id: i64) => "{type_id}"
255    );
256
257    api_get!(
258        /// Information about a station
259        get_station,
260        "GetUniverseStationsStationId",
261        RequestType::Public,
262        Station,
263        (station_id: i64) => "{station_id}"
264    );
265
266    api_get!(
267        /// Returns information on requested structure if you are on the ACL. Otherwise, returns “Forbidden” for all inputs.
268        get_structure,
269        "GetUniverseStructuresStructureId",
270        RequestType::Authenticated,
271        Structure,
272        (structure_id: i64) => "{structure_id}"
273    );
274
275    api_post!(
276        /// Get IDs from a list of names
277        get_ids,
278        "PostUniverseIds",
279        RequestType::Public,
280        Ids,
281        ,
282        names: &[&str],
283    );
284}
285
286/// A character ancestry.
287#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
288#[allow(missing_docs)]
289pub struct Ancestry {
290    pub bloodline_id: i64,
291    pub description: String,
292    pub icon_id: Option<i64>,
293    pub id: i64,
294    pub name: String,
295    pub short_description: Option<String>,
296}
297
298/// An asteroid belt.
299#[derive(Debug, Clone, Deserialize)]
300#[allow(missing_docs)]
301pub struct AsteroidBelt {
302    pub name: String,
303    pub position: Position,
304    pub system_id: i64,
305}
306
307/// A character bloodline.
308#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
309#[allow(missing_docs)]
310pub struct Bloodline {
311    pub bloodline_id: i64,
312    pub charisma: i64,
313    pub corporation_id: i64,
314    pub description: String,
315    pub intelligence: i64,
316    pub memory: i64,
317    pub name: String,
318    pub perception: i64,
319    pub race_id: i64,
320    pub ship_type_id: i64,
321    pub willpower: i64,
322}
323
324/// An NPC faction.
325#[derive(Debug, Clone, PartialEq, Deserialize)]
326#[allow(missing_docs)]
327pub struct UniverseFaction {
328    pub corporation_id: Option<i64>,
329    pub description: String,
330    pub faction_id: i64,
331    pub is_unique: bool,
332    pub militia_corporation_id: Option<i64>,
333    pub name: String,
334    pub size_factor: f64,
335    pub solar_system_id: Option<i64>,
336    pub station_count: i64,
337    pub station_system_count: i64,
338}
339
340/// Rendering information of a graphic.
341#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
342#[allow(missing_docs)]
343pub struct Graphic {
344    pub collision_file: Option<String>,
345    pub graphic_file: Option<String>,
346    pub graphic_id: i64,
347    pub icon_folder: Option<String>,
348    pub sof_dna: Option<String>,
349    /// Named `sof_fation_name` (sic) in the ESI spec.
350    pub sof_fation_name: Option<String>,
351    pub sof_hull_name: Option<String>,
352    pub sof_race_name: Option<String>,
353}
354
355/// A moon.
356#[derive(Debug, Clone, Deserialize)]
357#[allow(missing_docs)]
358pub struct Moon {
359    pub moon_id: i64,
360    pub name: String,
361    pub position: Position,
362    pub system_id: i64,
363}
364
365/// A planet.
366#[derive(Debug, Clone, Deserialize)]
367#[allow(missing_docs)]
368pub struct PlanetInfo {
369    pub name: String,
370    pub planet_id: i64,
371    pub position: Position,
372    pub system_id: i64,
373    pub type_id: i64,
374}
375
376/// A playable race.
377#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
378#[allow(missing_docs)]
379pub struct Race {
380    pub alliance_id: i64,
381    pub description: String,
382    pub name: String,
383    pub race_id: i64,
384}
385
386/// The other end of a stargate.
387#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
388#[allow(missing_docs)]
389pub struct StargateDestination {
390    pub stargate_id: i64,
391    pub system_id: i64,
392}
393
394/// A stargate.
395#[derive(Debug, Clone, Deserialize)]
396#[allow(missing_docs)]
397pub struct Stargate {
398    pub destination: StargateDestination,
399    pub name: String,
400    pub position: Position,
401    pub stargate_id: i64,
402    pub system_id: i64,
403    pub type_id: i64,
404}
405
406/// A star.
407#[derive(Debug, Clone, PartialEq, Deserialize)]
408#[allow(missing_docs)]
409pub struct Star {
410    pub age: i64,
411    pub luminosity: f64,
412    pub name: String,
413    pub radius: i64,
414    pub solar_system_id: i64,
415    /// Spectral class such as `K2 V`, as published by ESI.
416    pub spectral_class: String,
417    pub temperature: i64,
418    pub type_id: i64,
419}
420
421/// Jumps through a system in the last hour.
422#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
423#[allow(missing_docs)]
424pub struct SystemJumps {
425    pub ship_jumps: i64,
426    pub system_id: i64,
427}
428
429/// Kills in a system in the last hour.
430#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
431#[allow(missing_docs)]
432pub struct SystemKills {
433    pub npc_kills: i64,
434    pub pod_kills: i64,
435    pub ship_kills: i64,
436    pub system_id: i64,
437}
438
439/// Which public structures to list.
440#[derive(Debug, Clone, Copy, PartialEq, Eq)]
441pub enum StructureFilter {
442    /// Structures with a market.
443    Market,
444    /// Structures with basic manufacturing.
445    ManufacturingBasic,
446}
447
448impl std::fmt::Display for StructureFilter {
449    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
450        f.write_str(match self {
451            StructureFilter::Market => "market",
452            StructureFilter::ManufacturingBasic => "manufacturing_basic",
453        })
454    }
455}
456
457/// The kind of entity a resolved name belongs to.
458#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
459#[serde(rename_all = "snake_case")]
460pub enum NameCategory {
461    /// An alliance.
462    Alliance,
463    /// A character.
464    Character,
465    /// A constellation.
466    Constellation,
467    /// A corporation.
468    Corporation,
469    /// An inventory type.
470    InventoryType,
471    /// A region.
472    Region,
473    /// A solar system.
474    SolarSystem,
475    /// A station.
476    Station,
477    /// A faction.
478    Faction,
479    /// A category this version of the crate does not know about.
480    #[serde(other)]
481    Unrecognized,
482}
483
484/// A name resolved from an ID.
485#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
486#[allow(missing_docs)]
487pub struct ResolvedName {
488    pub category: NameCategory,
489    pub id: i64,
490    pub name: String,
491}
492
493impl UniverseGroup<'_> {
494    api_get!(
495        /// List the character ancestries.
496        get_ancestries,
497        "GetUniverseAncestries",
498        RequestType::Public,
499        Vec<Ancestry>,
500    );
501
502    api_get!(
503        /// Get information about an asteroid belt.
504        get_asteroid_belt,
505        "GetUniverseAsteroidBeltsAsteroidBeltId",
506        RequestType::Public,
507        AsteroidBelt,
508        (asteroid_belt_id: i64) => "{asteroid_belt_id}"
509    );
510
511    api_get!(
512        /// List the character bloodlines.
513        get_bloodlines,
514        "GetUniverseBloodlines",
515        RequestType::Public,
516        Vec<Bloodline>,
517    );
518
519    api_get!(
520        /// List the IDs of all item categories.
521        get_category_ids,
522        "GetUniverseCategories",
523        RequestType::Public,
524        Vec<i64>,
525    );
526
527    api_get!(
528        /// List the NPC factions.
529        get_factions,
530        "GetUniverseFactions",
531        RequestType::Public,
532        Vec<UniverseFaction>,
533    );
534
535    api_get!(
536        /// List the IDs of all graphics.
537        get_graphic_ids,
538        "GetUniverseGraphics",
539        RequestType::Public,
540        Vec<i64>,
541    );
542
543    api_get!(
544        /// Get information about a graphic.
545        get_graphic,
546        "GetUniverseGraphicsGraphicId",
547        RequestType::Public,
548        Graphic,
549        (graphic_id: i64) => "{graphic_id}"
550    );
551
552    api_get!(
553        /// List the IDs of all item groups.
554        get_group_ids,
555        "GetUniverseGroups",
556        RequestType::Public,
557        Vec<i64>,
558        ;
559        Optional(page: i32) => "page"
560    );
561
562    api_get!(
563        /// Get information about a moon.
564        get_moon,
565        "GetUniverseMoonsMoonId",
566        RequestType::Public,
567        Moon,
568        (moon_id: i64) => "{moon_id}"
569    );
570
571    api_get!(
572        /// Get information about a planet.
573        get_planet,
574        "GetUniversePlanetsPlanetId",
575        RequestType::Public,
576        PlanetInfo,
577        (planet_id: i64) => "{planet_id}"
578    );
579
580    api_get!(
581        /// List the playable races.
582        get_races,
583        "GetUniverseRaces",
584        RequestType::Public,
585        Vec<Race>,
586    );
587
588    api_get!(
589        /// Get information about a stargate.
590        get_stargate,
591        "GetUniverseStargatesStargateId",
592        RequestType::Public,
593        Stargate,
594        (stargate_id: i64) => "{stargate_id}"
595    );
596
597    api_get!(
598        /// Get information about a star.
599        get_star,
600        "GetUniverseStarsStarId",
601        RequestType::Public,
602        Star,
603        (star_id: i64) => "{star_id}"
604    );
605
606    api_get!(
607        /// List the IDs of public structures, optionally filtered.
608        get_structure_ids,
609        "GetUniverseStructures",
610        RequestType::Public,
611        Vec<i64>,
612        ;
613        Optional(filter: StructureFilter) => "filter"
614    );
615
616    api_get!(
617        /// List the number of ship jumps per system in the last hour.
618        get_system_jumps,
619        "GetUniverseSystemJumps",
620        RequestType::Public,
621        Vec<SystemJumps>,
622    );
623
624    api_get!(
625        /// List the number of kills per system in the last hour.
626        get_system_kills,
627        "GetUniverseSystemKills",
628        RequestType::Public,
629        Vec<SystemKills>,
630    );
631
632    api_post!(
633        /// Resolve a list of IDs to names and categories.
634        get_names,
635        "PostUniverseNames",
636        RequestType::Public,
637        Vec<ResolvedName>,
638        ; Chunked(ids: &[i64], 1000)
639    );
640}
641
642#[cfg(test)]
643mod new_endpoint_tests {
644    use super::{NameCategory, ResolvedName, Star, StructureFilter};
645
646    #[test]
647    fn test_parse_star_with_large_values() {
648        let json = r#"{"age": 4500999969, "luminosity": 0.5, "name": "Jita - Star",
649            "radius": 2284000000, "solar_system_id": 30000142,
650            "spectral_class": "K2 V", "temperature": 4567, "type_id": 45041}"#;
651        let star: Star = serde_json::from_str(json).unwrap();
652        assert_eq!(star.radius, 2_284_000_000);
653        assert_eq!(star.spectral_class, "K2 V");
654    }
655
656    #[test]
657    fn test_parse_resolved_names() {
658        let json = r#"[{"category": "inventory_type", "id": 34, "name": "Tritanium"},
659            {"category": "something_new", "id": 1, "name": "?"}]"#;
660        let names: Vec<ResolvedName> = serde_json::from_str(json).unwrap();
661        assert_eq!(names[0].category, NameCategory::InventoryType);
662        assert_eq!(names[1].category, NameCategory::Unrecognized);
663    }
664
665    #[test]
666    fn test_structure_filter_query_value() {
667        assert_eq!(StructureFilter::Market.to_string(), "market");
668        assert_eq!(
669            StructureFilter::ManufacturingBasic.to_string(),
670            "manufacturing_basic"
671        );
672    }
673}