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
use crate::groups::Page;
use crate::prelude::*;
use uuid::Uuid;

/// Endpoints for Corporation Projects
pub struct CorporationProjectsGroup<'a> {
    pub(crate) esi: &'a Esi,
}

/// Which projects to list.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProjectStateFilter {
    /// All projects.
    All,
    /// Only active projects.
    Active,
}

impl std::fmt::Display for ProjectStateFilter {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            ProjectStateFilter::All => "All",
            ProjectStateFilter::Active => "Active",
        })
    }
}

/// The state of a corporation project.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum ProjectState {
    /// Not specified.
    Unspecified,
    /// Open.
    Active,
    /// Closed.
    Closed,
    /// Completed.
    Completed,
    /// Expired.
    Expired,
    /// Deleted.
    Deleted,
    /// A value this version of the crate does not know about.
    #[serde(other)]
    Unrecognized,
}

/// Progress of a project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectProgress {
    /// Current progress.
    pub current: i64,
    /// Progress needed to complete the project.
    pub desired: i64,
}

/// Reward of a project, in ISK.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ProjectReward {
    /// Initial reward.
    pub initial: f64,
    /// Reward left.
    pub remaining: f64,
}

/// A project in the project listing.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ProjectSummary {
    /// ID of the project.
    pub id: Uuid,
    /// When the project was last modified.
    pub last_modified: String,
    /// Name of the project.
    pub name: String,
    /// Progress of the project.
    pub progress: ProjectProgress,
    /// Reward of the project.
    pub reward: Option<ProjectReward>,
    /// State of the project.
    pub state: ProjectState,
}

/// A place a project refers to. Exactly one of the fields is set.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectLocation {
    /// A solar system.
    pub solar_system_id: Option<i64>,
    /// A constellation.
    pub constellation_id: Option<i64>,
    /// A region.
    pub region_id: Option<i64>,
}

/// An entity a project refers to. Exactly one of the fields is set.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectIdentity {
    /// A character.
    pub character_id: Option<i64>,
    /// A corporation.
    pub corporation_id: Option<i64>,
    /// An alliance.
    pub alliance_id: Option<i64>,
    /// A faction.
    pub faction_id: Option<i64>,
}

/// A type or a group of types. Exactly one of the fields is set.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct TypeOrGroup {
    /// A type.
    pub type_id: Option<i64>,
    /// A group of types.
    pub group_id: Option<i64>,
}

/// A place to dock. Exactly one of the fields is set.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DockingLocation {
    /// A structure.
    pub structure_id: Option<i64>,
    /// A station.
    pub station_id: Option<i64>,
}

/// An archetype of a faction warfare complex.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectArchetype {
    /// ID of the archetype.
    pub archetype_id: Option<i64>,
}

/// A faction a project refers to.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectFaction {
    /// ID of the faction.
    pub faction_id: Option<i64>,
}

/// A signature type a project refers to.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectSignature {
    /// ID of the signature type.
    pub signature_type_id: Option<i64>,
}

/// A corporation a project refers to.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectCorporation {
    /// ID of the corporation.
    pub corporation_id: Option<i64>,
}

/// Configuration of the faction warfare complex projects.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct FwComplexConfig {
    /// Archetypes of the complexes.
    #[serde(default)]
    pub archetypes: Vec<ProjectArchetype>,
    /// Factions involved.
    #[serde(default)]
    pub factions: Vec<ProjectFaction>,
    /// Where the complexes are.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
}

/// Configuration of projects that involve ships and other pilots.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ShipActivityConfig {
    /// Entities involved.
    #[serde(default)]
    pub identities: Vec<ProjectIdentity>,
    /// Where it happens.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
    /// Ships involved.
    #[serde(default)]
    pub ships: Vec<TypeOrGroup>,
}

/// Configuration of projects that only refer to locations.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct LocationsConfig {
    /// Where it happens.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
}

/// Configuration of an item delivery project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DeliverItemConfig {
    /// Where the items can be delivered.
    #[serde(default)]
    pub docking_locations: Vec<DockingLocation>,
    /// Items to deliver.
    #[serde(default)]
    pub items: Vec<TypeOrGroup>,
    /// Office to deliver to.
    pub office_id: Option<i64>,
}

/// Configuration of a loyalty point project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EarnLoyaltyPointConfig {
    /// Corporations whose loyalty points count.
    #[serde(default)]
    pub corporations: Vec<ProjectCorporation>,
}

/// Who must own the items of a manufacturing project.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum ManufactureOwner {
    /// Anyone.
    Any,
    /// A corporation.
    Corporation,
    /// A character.
    Character,
    /// A value this version of the crate does not know about.
    #[serde(other)]
    Unrecognized,
}

/// Configuration of a manufacturing project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ManufactureItemConfig {
    /// Where the items can be delivered.
    #[serde(default)]
    pub docking_locations: Vec<DockingLocation>,
    /// Items to manufacture.
    #[serde(default)]
    pub items: Vec<TypeOrGroup>,
    /// Who must own the items.
    pub owner: ManufactureOwner,
}

/// Configuration of a mining project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct MineMaterialConfig {
    /// Where to mine.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
    /// Materials to mine.
    #[serde(default)]
    pub materials: Vec<TypeOrGroup>,
}

/// Configuration of a signature scanning project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ScanSignatureConfig {
    /// Where to scan.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
    /// Signature types to scan.
    #[serde(default)]
    pub signatures: Vec<ProjectSignature>,
}

/// The kind of conflict a ship insurance project covers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum ConflictType {
    /// Any conflict.
    Any,
    /// Player versus player.
    Pvp,
    /// Player versus environment.
    Pve,
    /// A value this version of the crate does not know about.
    #[serde(other)]
    Unrecognized,
}

/// Configuration of a ship insurance project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ShipInsuranceConfig {
    /// Kind of conflict covered.
    pub conflict_type: ConflictType,
    /// Entities involved.
    #[serde(default)]
    pub identities: Vec<ProjectIdentity>,
    /// Where it applies.
    #[serde(default)]
    pub locations: Vec<ProjectLocation>,
    /// Whether implants are reimbursed.
    pub reimburse_implants: bool,
    /// Ships covered.
    #[serde(default)]
    pub ships: Vec<TypeOrGroup>,
}

/// A project type this version of the crate does not know about.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct UnknownProjectConfig {
    /// Raw data of the configuration.
    pub data: Option<serde_json::Value>,
    /// Name of the project type.
    #[serde(rename = "type")]
    pub config_type: String,
}

/// The configuration of a project. Exactly one of the fields is set, depending
/// on the project type; the fields that are not set are `None`.
#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
pub struct ProjectConfiguration {
    /// Capture a faction warfare complex.
    pub capture_fw_complex: Option<FwComplexConfig>,
    /// Damage ships.
    pub damage_ship: Option<ShipActivityConfig>,
    /// Defend a faction warfare complex.
    pub defend_fw_complex: Option<FwComplexConfig>,
    /// Deliver items.
    pub deliver_item: Option<DeliverItemConfig>,
    /// Destroy NPCs.
    pub destroy_npc: Option<LocationsConfig>,
    /// Destroy ships.
    pub destroy_ship: Option<ShipActivityConfig>,
    /// Earn loyalty points.
    pub earn_loyalty_point: Option<EarnLoyaltyPointConfig>,
    /// Lose ships.
    pub lost_ship: Option<ShipActivityConfig>,
    /// Manually tracked project (no data).
    pub manual: Option<serde_json::Value>,
    /// Manufacture items.
    pub manufacture_item: Option<ManufactureItemConfig>,
    /// Mine materials.
    pub mine_material: Option<MineMaterialConfig>,
    /// Remote boost shields.
    pub remote_boost_shield: Option<ShipActivityConfig>,
    /// Remote repair armor.
    pub remote_repair_armor: Option<ShipActivityConfig>,
    /// Salvage wrecks.
    pub salvage_wreck: Option<LocationsConfig>,
    /// Scan signatures.
    pub scan_signature: Option<ScanSignatureConfig>,
    /// Insure ships.
    pub ship_insurance: Option<ShipInsuranceConfig>,
    /// A project type this version of the crate does not know about.
    pub unknown: Option<UnknownProjectConfig>,
}

/// Limits and rewards for contributions to a project.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ContributionRules {
    /// Maximum number of participants.
    pub participation_limit: Option<i64>,
    /// ISK paid per contribution.
    pub reward_per_contribution: Option<f64>,
    /// Maximum number of submissions per participant.
    pub submission_limit: Option<i64>,
    /// Multiplier applied to submissions.
    pub submission_multiplier: Option<f64>,
}

/// The character that created a project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectCreator {
    /// Character ID of the creator.
    pub id: i64,
    /// Name of the creator.
    pub name: String,
}

/// The career a project belongs to.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub enum ProjectCareer {
    /// Not specified.
    Unspecified,
    /// Explorer.
    Explorer,
    /// Industrialist.
    Industrialist,
    /// Enforcer.
    Enforcer,
    /// Soldier of Fortune.
    #[serde(rename = "Soldier of Fortune")]
    SoldierOfFortune,
    /// A value this version of the crate does not know about.
    #[serde(other)]
    Unrecognized,
}

/// General details of a project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectDetails {
    /// Career of the project.
    pub career: ProjectCareer,
    /// When the project was created.
    pub created: String,
    /// Description of the project.
    pub description: String,
    /// When the project expires.
    pub expires: Option<String>,
    /// When the project finished.
    pub finished: Option<String>,
}

/// A corporation project.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Project {
    /// Configuration of the project.
    pub configuration: ProjectConfiguration,
    /// Contribution rules.
    pub contribution: Option<ContributionRules>,
    /// Creator of the project.
    pub creator: ProjectCreator,
    /// General details.
    pub details: ProjectDetails,
    /// ID of the project.
    pub id: Uuid,
    /// When the project was last modified.
    pub last_modified: String,
    /// Name of the project.
    pub name: String,
    /// Progress of the project.
    pub progress: ProjectProgress,
    /// Reward of the project.
    pub reward: Option<ProjectReward>,
    /// State of the project.
    pub state: ProjectState,
}

/// What a character contributed to a project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectContribution {
    /// Amount contributed.
    pub contributed: i64,
    /// When the contribution was last modified.
    pub last_modified: Option<String>,
}

/// A contributor to a project.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProjectContributor {
    /// Amount contributed.
    pub contributed: i64,
    /// Character ID of the contributor.
    pub id: i64,
    /// Name of the contributor.
    pub name: String,
}

impl CorporationProjectsGroup<'_> {
    api_get!(
        /// List the projects of a corporation. Use the cursor of the returned
        /// page as `after` or `before` to walk through the list.
        list,
        "GetCorporationsProjectsListing",
        RequestType::Authenticated,
        Page<ProjectSummary>,
        (corporation_id: i64) => "{corporation_id}";
        Optional(after: String) => "after",
        Optional(before: String) => "before",
        Optional(limit: i64) => "limit",
        Optional(state: ProjectStateFilter) => "state"
    );

    api_get!(
        /// Get the details of a project of a corporation.
        get_project,
        "GetCorporationsProjectsDetail",
        RequestType::Authenticated,
        Project,
        (corporation_id: i64) => "{corporation_id}",
        (project_id: Uuid) => "{project_id}"
    );

    api_get!(
        /// Get what a character contributed to a project.
        get_contribution,
        "GetCorporationsProjectsContribution",
        RequestType::Authenticated,
        ProjectContribution,
        (corporation_id: i64) => "{corporation_id}",
        (project_id: Uuid) => "{project_id}",
        (character_id: i64) => "{character_id}"
    );

    api_get!(
        /// List the contributors to a project. Use the cursor of the returned
        /// page as `after` or `before` to walk through the list.
        ///
        /// Requires the Project Manager role.
        list_contributors,
        "GetCorporationsProjectsContributors",
        RequestType::Authenticated,
        Page<ProjectContributor>,
        (corporation_id: i64) => "{corporation_id}",
        (project_id: Uuid) => "{project_id}";
        Optional(after: String) => "after",
        Optional(before: String) => "before",
        Optional(limit: i64) => "limit"
    );
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_project_listing() {
        let json = r#"{"cursor": {"after": "abc"}, "projects": [
            {"id": "6f1d8a5e-0b7c-4d3e-9a2f-1c5b7e9d0a11", "last_modified": "t", "name": "n",
             "progress": {"current": 5000000000, "desired": 9000000000},
             "reward": {"initial": 1000.5, "remaining": 10.0}, "state": "Active"},
            {"id": "6f1d8a5e-0b7c-4d3e-9a2f-1c5b7e9d0a12", "last_modified": "t", "name": "m",
             "progress": {"current": 0, "desired": 1}, "state": "Archived"}]}"#;
        let page: Page<ProjectSummary> = serde_json::from_str(json).unwrap();
        assert_eq!(page.items[0].progress.current, 5_000_000_000);
        assert_eq!(page.items[0].state, ProjectState::Active);
        assert_eq!(page.items[1].state, ProjectState::Unrecognized);
        assert_eq!(page.cursor.unwrap().after.as_deref(), Some("abc"));
    }

    #[test]
    fn test_parse_project_with_each_configuration_shape() {
        let base = |config: &str| {
            format!(
                r#"{{"configuration": {config},
                "creator": {{"id": 2124758468, "name": "c"}},
                "details": {{"career": "Soldier of Fortune", "created": "t", "description": "d"}},
                "id": "6f1d8a5e-0b7c-4d3e-9a2f-1c5b7e9d0a11", "last_modified": "t", "name": "n",
                "progress": {{"current": 1, "desired": 2}}, "state": "Closed"}}"#
            )
        };
        let mining: Project = serde_json::from_str(&base(
            r#"{"mine_material": {"locations": [{"region_id": 10000002}],
                "materials": [{"group_id": 450}]}}"#,
        ))
        .unwrap();
        assert_eq!(mining.details.career, ProjectCareer::SoldierOfFortune);
        let cfg = mining.configuration.mine_material.unwrap();
        assert_eq!(cfg.locations[0].region_id, Some(10000002));
        assert_eq!(cfg.materials[0].group_id, Some(450));

        let insurance: Project = serde_json::from_str(&base(
            r#"{"ship_insurance": {"conflict_type": "Pvp", "reimburse_implants": true}}"#,
        ))
        .unwrap();
        assert_eq!(
            insurance
                .configuration
                .ship_insurance
                .unwrap()
                .conflict_type,
            ConflictType::Pvp
        );

        let manual: Project = serde_json::from_str(&base(r#"{"manual": {}}"#)).unwrap();
        assert!(manual.configuration.manual.is_some());
        assert!(manual.configuration.mine_material.is_none());

        let future: Project = serde_json::from_str(&base(r#"{"teleport_cat": {"x": 1}}"#)).unwrap();
        assert_eq!(future.configuration, ProjectConfiguration::default());
    }

    #[test]
    fn test_parse_contribution_and_contributors() {
        let c: ProjectContribution = serde_json::from_str(r#"{"contributed": 7}"#).unwrap();
        assert_eq!(c.last_modified, None);
        let page: Page<ProjectContributor> = serde_json::from_str(
            r#"{"contributors": [{"contributed": 3000000000, "id": 1, "name": "x"}]}"#,
        )
        .unwrap();
        assert_eq!(page.items[0].contributed, 3_000_000_000);
        assert!(page.cursor.is_none());
    }

    #[test]
    fn test_state_filter_display() {
        assert_eq!(ProjectStateFilter::Active.to_string(), "Active");
        assert_eq!(ProjectStateFilter::All.to_string(), "All");
    }
}