esi-openapi 0.2.0

Rust API for EVE Online's ESI, based on the OpenAPI specification (fork of rfesi)
Documentation
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#![allow(unused)]

use crate::prelude::*;

/// Endpoints for Universe
pub struct UniverseGroup<'a> {
    pub(crate) esi: &'a Esi,
}

/// A position in space, in meters.
#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
#[allow(missing_docs)]
pub struct Position {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Constellation {
    pub constellation_id: i64,
    pub name: String,
    pub position: Position,
    pub region_id: i64,
    pub systems: Vec<i64>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Region {
    pub constellations: Vec<i64>,
    pub description: Option<String>,
    pub name: String,
    pub region_id: i64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct SystemPlanet {
    pub asteroid_belts: Option<Vec<i64>>,
    pub moons: Option<Vec<i64>>,
    pub planet_id: i64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct System {
    pub constellation_id: i64,
    pub name: String,
    pub planets: Option<Vec<SystemPlanet>>,
    pub position: Position,
    pub security_class: Option<String>,
    pub security_status: f64,
    pub star_id: Option<i64>,
    pub stargates: Option<Vec<i64>>,
    pub stations: Option<Vec<i64>>,
    pub system_id: i64,
}

#[derive(Debug, Deserialize)]
#[allow(missing_docs)]
pub struct Ids {
    pub characters: Option<Vec<Category>>,
    pub alliances: Option<Vec<Category>>,
    pub constellations: Option<Vec<Category>>,
    pub agents: Option<Vec<Category>>,
    pub regions: Option<Vec<Category>>,
    pub systems: Option<Vec<Category>>,
    pub stations: Option<Vec<Category>>,
}

#[derive(Debug, Deserialize)]
#[allow(missing_docs)]
pub struct Category {
    pub id: i64,
    pub name: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct TypeDogmaAttribute {
    pub attribute_id: i64,
    pub value: f64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct TypeDogmaEffect {
    pub effect_id: i64,
    pub is_default: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Type {
    pub capacity: Option<f64>,
    pub description: String,
    pub dogma_attributes: Option<Vec<TypeDogmaAttribute>>,
    pub dogma_effects: Option<Vec<TypeDogmaEffect>>,
    pub graphic_id: Option<i64>,
    pub group_id: i64,
    pub icon_id: Option<i64>,
    pub market_group_id: Option<i64>,
    pub mass: Option<f64>,
    pub name: String,
    pub packaged_volume: Option<f64>,
    pub portion_size: Option<i64>,
    pub published: bool,
    pub radius: Option<f64>,
    pub type_id: i64,
    pub volume: Option<f64>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Station {
    pub max_dockable_ship_volume: f64,
    pub name: String,
    pub office_rental_cost: f64,
    pub owner: Option<i64>,
    pub position: Position,
    pub race_id: Option<i64>,
    pub reprocessing_efficiency: f64,
    pub reprocessing_stations_take: f64,
    pub services: Vec<String>,
    pub station_id: i64,
    pub system_id: i64,
    pub type_id: i64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Structure {
    pub name: String,
    pub owner_id: i64,
    pub position: Option<Position>,
    pub solar_system_id: i64,
    pub type_id: Option<i64>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct CategoriesCategory {
    pub category_id: i64,
    pub groups: Vec<i64>,
    pub name: String,
    pub published: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct Group {
    pub category_id: i64,
    pub group_id: i64,
    pub name: String,
    pub published: bool,
    pub types: Vec<i64>,
}

impl UniverseGroup<'_> {
    api_get!(
        /// Get information on a category
        get_universe_categories_category,
        "GetUniverseCategoriesCategoryId",
        RequestType::Public,
        CategoriesCategory,
        (category_id: i64) => "{category_id}"
    );

    api_get!(
        /// Get information on a group
        get_universe_groups_group,
        "GetUniverseGroupsGroupId",
        RequestType::Public,
        Group,
        (group_id: i64) => "{group_id}"
    );

    api_get!(
        /// Get information on a type
        get_universe_types_type,
        "GetUniverseTypesTypeId",
        RequestType::Public,
        Type,
        (type_id: i64) => "{type_id}"
    );

    api_get!(
        /// Get a list of constellation ids
        get_constellation_ids,
        "GetUniverseConstellations",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// Get information on a constellation
        get_constellation,
        "GetUniverseConstellationsConstellationId",
        RequestType::Public,
        Constellation,
        (constellation_id: i64) => "{constellation_id}"
    );

    api_get!(
        /// Get a list of region ids
        get_region_ids,
        "GetUniverseRegions",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// Get information on a region
        get_region,
        "GetUniverseRegionsRegionId",
        RequestType::Public,
        Region,
        (region_id: i64) => "{region_id}"
    );

    api_get!(
        /// Get a list of system ids
        get_system_ids,
        "GetUniverseSystems",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// Get information on a system
        get_system,
        "GetUniverseSystemsSystemId",
        RequestType::Public,
        System,
        (system_id: i64) => "{system_id}"
    );

    api_get!(
        /// Get a list of type ids
        get_type_ids,
        "GetUniverseTypes",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// Get information on a type
        get_type,
        "GetUniverseTypesTypeId",
        RequestType::Public,
        Type,
        (type_id: i64) => "{type_id}"
    );

    api_get!(
        /// Information about a station
        get_station,
        "GetUniverseStationsStationId",
        RequestType::Public,
        Station,
        (station_id: i64) => "{station_id}"
    );

    api_get!(
        /// Returns information on requested structure if you are on the ACL. Otherwise, returns “Forbidden” for all inputs.
        get_structure,
        "GetUniverseStructuresStructureId",
        RequestType::Authenticated,
        Structure,
        (structure_id: i64) => "{structure_id}"
    );

    api_post!(
        /// Get IDs from a list of names
        get_ids,
        "PostUniverseIds",
        RequestType::Public,
        Ids,
        ,
        names: &[&str],
    );
}

/// A character ancestry.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct Ancestry {
    pub bloodline_id: i64,
    pub description: String,
    pub icon_id: Option<i64>,
    pub id: i64,
    pub name: String,
    pub short_description: Option<String>,
}

/// An asteroid belt.
#[derive(Debug, Clone, Deserialize)]
#[allow(missing_docs)]
pub struct AsteroidBelt {
    pub name: String,
    pub position: Position,
    pub system_id: i64,
}

/// A character bloodline.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct Bloodline {
    pub bloodline_id: i64,
    pub charisma: i64,
    pub corporation_id: i64,
    pub description: String,
    pub intelligence: i64,
    pub memory: i64,
    pub name: String,
    pub perception: i64,
    pub race_id: i64,
    pub ship_type_id: i64,
    pub willpower: i64,
}

/// An NPC faction.
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[allow(missing_docs)]
pub struct UniverseFaction {
    pub corporation_id: Option<i64>,
    pub description: String,
    pub faction_id: i64,
    pub is_unique: bool,
    pub militia_corporation_id: Option<i64>,
    pub name: String,
    pub size_factor: f64,
    pub solar_system_id: Option<i64>,
    pub station_count: i64,
    pub station_system_count: i64,
}

/// Rendering information of a graphic.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct Graphic {
    pub collision_file: Option<String>,
    pub graphic_file: Option<String>,
    pub graphic_id: i64,
    pub icon_folder: Option<String>,
    pub sof_dna: Option<String>,
    /// Named `sof_fation_name` (sic) in the ESI spec.
    pub sof_fation_name: Option<String>,
    pub sof_hull_name: Option<String>,
    pub sof_race_name: Option<String>,
}

/// A moon.
#[derive(Debug, Clone, Deserialize)]
#[allow(missing_docs)]
pub struct Moon {
    pub moon_id: i64,
    pub name: String,
    pub position: Position,
    pub system_id: i64,
}

/// A planet.
#[derive(Debug, Clone, Deserialize)]
#[allow(missing_docs)]
pub struct PlanetInfo {
    pub name: String,
    pub planet_id: i64,
    pub position: Position,
    pub system_id: i64,
    pub type_id: i64,
}

/// A playable race.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct Race {
    pub alliance_id: i64,
    pub description: String,
    pub name: String,
    pub race_id: i64,
}

/// The other end of a stargate.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct StargateDestination {
    pub stargate_id: i64,
    pub system_id: i64,
}

/// A stargate.
#[derive(Debug, Clone, Deserialize)]
#[allow(missing_docs)]
pub struct Stargate {
    pub destination: StargateDestination,
    pub name: String,
    pub position: Position,
    pub stargate_id: i64,
    pub system_id: i64,
    pub type_id: i64,
}

/// A star.
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[allow(missing_docs)]
pub struct Star {
    pub age: i64,
    pub luminosity: f64,
    pub name: String,
    pub radius: i64,
    pub solar_system_id: i64,
    /// Spectral class such as `K2 V`, as published by ESI.
    pub spectral_class: String,
    pub temperature: i64,
    pub type_id: i64,
}

/// Jumps through a system in the last hour.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct SystemJumps {
    pub ship_jumps: i64,
    pub system_id: i64,
}

/// Kills in a system in the last hour.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct SystemKills {
    pub npc_kills: i64,
    pub pod_kills: i64,
    pub ship_kills: i64,
    pub system_id: i64,
}

/// Which public structures to list.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StructureFilter {
    /// Structures with a market.
    Market,
    /// Structures with basic manufacturing.
    ManufacturingBasic,
}

impl std::fmt::Display for StructureFilter {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            StructureFilter::Market => "market",
            StructureFilter::ManufacturingBasic => "manufacturing_basic",
        })
    }
}

/// The kind of entity a resolved name belongs to.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum NameCategory {
    /// An alliance.
    Alliance,
    /// A character.
    Character,
    /// A constellation.
    Constellation,
    /// A corporation.
    Corporation,
    /// An inventory type.
    InventoryType,
    /// A region.
    Region,
    /// A solar system.
    SolarSystem,
    /// A station.
    Station,
    /// A faction.
    Faction,
    /// A category this version of the crate does not know about.
    #[serde(other)]
    Unrecognized,
}

/// A name resolved from an ID.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[allow(missing_docs)]
pub struct ResolvedName {
    pub category: NameCategory,
    pub id: i64,
    pub name: String,
}

impl UniverseGroup<'_> {
    api_get!(
        /// List the character ancestries.
        get_ancestries,
        "GetUniverseAncestries",
        RequestType::Public,
        Vec<Ancestry>,
    );

    api_get!(
        /// Get information about an asteroid belt.
        get_asteroid_belt,
        "GetUniverseAsteroidBeltsAsteroidBeltId",
        RequestType::Public,
        AsteroidBelt,
        (asteroid_belt_id: i64) => "{asteroid_belt_id}"
    );

    api_get!(
        /// List the character bloodlines.
        get_bloodlines,
        "GetUniverseBloodlines",
        RequestType::Public,
        Vec<Bloodline>,
    );

    api_get!(
        /// List the IDs of all item categories.
        get_category_ids,
        "GetUniverseCategories",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// List the NPC factions.
        get_factions,
        "GetUniverseFactions",
        RequestType::Public,
        Vec<UniverseFaction>,
    );

    api_get!(
        /// List the IDs of all graphics.
        get_graphic_ids,
        "GetUniverseGraphics",
        RequestType::Public,
        Vec<i64>,
    );

    api_get!(
        /// Get information about a graphic.
        get_graphic,
        "GetUniverseGraphicsGraphicId",
        RequestType::Public,
        Graphic,
        (graphic_id: i64) => "{graphic_id}"
    );

    api_get!(
        /// List the IDs of all item groups.
        get_group_ids,
        "GetUniverseGroups",
        RequestType::Public,
        Vec<i64>,
        ;
        Optional(page: i32) => "page"
    );

    api_get!(
        /// Get information about a moon.
        get_moon,
        "GetUniverseMoonsMoonId",
        RequestType::Public,
        Moon,
        (moon_id: i64) => "{moon_id}"
    );

    api_get!(
        /// Get information about a planet.
        get_planet,
        "GetUniversePlanetsPlanetId",
        RequestType::Public,
        PlanetInfo,
        (planet_id: i64) => "{planet_id}"
    );

    api_get!(
        /// List the playable races.
        get_races,
        "GetUniverseRaces",
        RequestType::Public,
        Vec<Race>,
    );

    api_get!(
        /// Get information about a stargate.
        get_stargate,
        "GetUniverseStargatesStargateId",
        RequestType::Public,
        Stargate,
        (stargate_id: i64) => "{stargate_id}"
    );

    api_get!(
        /// Get information about a star.
        get_star,
        "GetUniverseStarsStarId",
        RequestType::Public,
        Star,
        (star_id: i64) => "{star_id}"
    );

    api_get!(
        /// List the IDs of public structures, optionally filtered.
        get_structure_ids,
        "GetUniverseStructures",
        RequestType::Public,
        Vec<i64>,
        ;
        Optional(filter: StructureFilter) => "filter"
    );

    api_get!(
        /// List the number of ship jumps per system in the last hour.
        get_system_jumps,
        "GetUniverseSystemJumps",
        RequestType::Public,
        Vec<SystemJumps>,
    );

    api_get!(
        /// List the number of kills per system in the last hour.
        get_system_kills,
        "GetUniverseSystemKills",
        RequestType::Public,
        Vec<SystemKills>,
    );

    api_post!(
        /// Resolve a list of IDs to names and categories.
        get_names,
        "PostUniverseNames",
        RequestType::Public,
        Vec<ResolvedName>,
        ; Chunked(ids: &[i64], 1000)
    );
}

#[cfg(test)]
mod new_endpoint_tests {
    use super::{NameCategory, ResolvedName, Star, StructureFilter};

    #[test]
    fn test_parse_star_with_large_values() {
        let json = r#"{"age": 4500999969, "luminosity": 0.5, "name": "Jita - Star",
            "radius": 2284000000, "solar_system_id": 30000142,
            "spectral_class": "K2 V", "temperature": 4567, "type_id": 45041}"#;
        let star: Star = serde_json::from_str(json).unwrap();
        assert_eq!(star.radius, 2_284_000_000);
        assert_eq!(star.spectral_class, "K2 V");
    }

    #[test]
    fn test_parse_resolved_names() {
        let json = r#"[{"category": "inventory_type", "id": 34, "name": "Tritanium"},
            {"category": "something_new", "id": 1, "name": "?"}]"#;
        let names: Vec<ResolvedName> = serde_json::from_str(json).unwrap();
        assert_eq!(names[0].category, NameCategory::InventoryType);
        assert_eq!(names[1].category, NameCategory::Unrecognized);
    }

    #[test]
    fn test_structure_filter_query_value() {
        assert_eq!(StructureFilter::Market.to_string(), "market");
        assert_eq!(
            StructureFilter::ManufacturingBasic.to_string(),
            "manufacturing_basic"
        );
    }
}