Skip to main content

esi_openapi/groups/
activities.rs

1use crate::prelude::*;
2use uuid::Uuid;
3
4/// Endpoints for Activities
5pub struct ActivitiesGroup<'a> {
6    pub(crate) esi: &'a Esi,
7}
8
9/// A mercenary tactical operation of a character, as listed.
10#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
11pub struct TacticalOperationSummary {
12    /// ID of the operation.
13    pub id: Uuid,
14    /// ID of the mercenary den that hosts the operation.
15    pub mercenary_den_id: i64,
16}
17
18#[derive(Debug, Deserialize)]
19struct TacticalOperations {
20    operations: Vec<TacticalOperationSummary>,
21}
22
23/// State of a mercenary tactical operation.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
25pub enum TacticalOperationState {
26    /// No state specified.
27    Unspecified,
28    /// Available to start.
29    Available,
30    /// Started.
31    Started,
32    /// Completed.
33    Completed,
34    /// Expired.
35    Expired,
36    /// Removed.
37    Removed,
38    /// A state this version of the crate does not know about.
39    #[serde(other)]
40    Unrecognized,
41}
42
43/// A mercenary tactical operation of a character.
44#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
45#[allow(missing_docs)]
46pub struct TacticalOperation {
47    pub dungeon_type_id: i64,
48    pub expires: String,
49    pub id: Uuid,
50    pub mercenary_den_id: i64,
51    pub state: TacticalOperationState,
52}
53
54/// The window in which a skyhook can be raided.
55#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
56pub struct TheftVulnerability {
57    /// When the window closes.
58    pub end: String,
59    /// When the window opens.
60    pub start: String,
61}
62
63/// A skyhook that can currently be raided.
64#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
65#[allow(missing_docs)]
66pub struct RaidableSkyhook {
67    pub planet_id: i64,
68    pub solar_system_id: i64,
69    pub theft_vulnerability: TheftVulnerability,
70}
71
72#[derive(Debug, Deserialize)]
73struct RaidableSkyhooks {
74    skyhooks: Vec<RaidableSkyhook>,
75}
76
77impl ActivitiesGroup<'_> {
78    /// List the mercenary tactical operations of a character.
79    pub async fn get_character_tactical_operations(
80        &self,
81        character_id: i64,
82    ) -> EsiResult<Vec<TacticalOperationSummary>> {
83        let path = self
84            .esi
85            .get_endpoint_for_op_id("GetCharactersMercenaryTacticalOperationsListing")?
86            .replace("{character_id}", &character_id.to_string());
87        let wrapper: TacticalOperations = self
88            .esi
89            .query("GET", RequestType::Authenticated, &path, None, None)
90            .await?;
91        Ok(wrapper.operations)
92    }
93
94    api_get!(
95        /// Get a mercenary tactical operation of a character.
96        get_character_tactical_operation,
97        "GetCharactersMercenaryTacticalOperationsDetail",
98        RequestType::Authenticated,
99        TacticalOperation,
100        (character_id: i64) => "{character_id}",
101        (operation_id: Uuid) => "{operation_id}"
102    );
103
104    /// List the skyhooks that are currently vulnerable to theft.
105    pub async fn get_raidable_skyhooks(&self) -> EsiResult<Vec<RaidableSkyhook>> {
106        let path = self.esi.get_endpoint_for_op_id("GetSkyhooksRaidable")?;
107        let wrapper: RaidableSkyhooks = self
108            .esi
109            .query("GET", RequestType::Public, &path, None, None)
110            .await?;
111        Ok(wrapper.skyhooks)
112    }
113}
114
115#[cfg(test)]
116mod tests {
117    use super::*;
118
119    #[test]
120    fn test_parse_operation_and_skyhook() {
121        let op: TacticalOperation = serde_json::from_str(
122            r#"{"dungeon_type_id":1,"expires":"x","id":"67e6b7a0-6f58-4b5b-a2c4-4f3a1f0f2b11",
123            "mercenary_den_id":2,"state":"Weird"}"#,
124        )
125        .unwrap();
126        assert_eq!(op.state, TacticalOperationState::Unrecognized);
127        let hooks: RaidableSkyhooks = serde_json::from_str(
128            r#"{"skyhooks":[{"planet_id":1,"solar_system_id":2,
129            "theft_vulnerability":{"start":"a","end":"b"}}]}"#,
130        )
131        .unwrap();
132        assert_eq!(hooks.skyhooks[0].solar_system_id, 2);
133    }
134}