Skip to main content

esi_openapi/groups/
calendar.rs

1#![allow(unused)]
2
3use crate::prelude::*;
4
5/// Endpoints for Calendar
6pub struct CalendarGroup<'a> {
7    pub(crate) esi: &'a Esi,
8}
9
10#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
11/// The response of a character to a calendar event.
12pub enum EventResponse {
13    /// The character declined.
14    #[serde(rename = "declined")]
15    Declined,
16    /// The character has not responded yet.
17    #[serde(rename = "not_responded")]
18    NotResponded,
19    /// The character accepted.
20    #[serde(rename = "accepted")]
21    Accepted,
22    /// The character is tentative.
23    #[serde(rename = "tentative")]
24    Tentative,
25    /// A value not known to this version of the crate.
26    #[serde(other)]
27    Unrecognized,
28}
29
30#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
31/// The response a character can send to an event. Unlike [`EventResponse`],
32/// "not responded" cannot be sent.
33pub enum EventReply {
34    /// Accept the event.
35    #[serde(rename = "accepted")]
36    Accepted,
37    /// Decline the event.
38    #[serde(rename = "declined")]
39    Declined,
40    /// Mark the event as tentative.
41    #[serde(rename = "tentative")]
42    Tentative,
43}
44
45#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
46/// The kind of entity that owns a calendar event.
47pub enum EventOwnerType {
48    /// The game server.
49    #[serde(rename = "eve_server")]
50    EveServer,
51    /// A corporation.
52    #[serde(rename = "corporation")]
53    Corporation,
54    /// A faction.
55    #[serde(rename = "faction")]
56    Faction,
57    /// A character.
58    #[serde(rename = "character")]
59    Character,
60    /// An alliance.
61    #[serde(rename = "alliance")]
62    Alliance,
63    /// A value not known to this version of the crate.
64    #[serde(other)]
65    Unrecognized,
66}
67
68#[derive(Debug, Deserialize, Serialize, Clone)]
69/// A calendar event summary, as returned by the event list.
70pub struct CalendarEventSummary {
71    /// Date and time of the event.
72    pub event_date: Option<String>,
73    /// ID of the event.
74    pub event_id: Option<i64>,
75    /// Response of the character to the event.
76    pub event_response: Option<EventResponse>,
77    /// Importance of the event.
78    pub importance: Option<i64>,
79    /// Title of the event.
80    pub title: Option<String>,
81}
82
83#[derive(Debug, Deserialize, Serialize, Clone)]
84/// The details of a calendar event.
85pub struct CalendarEvent {
86    /// Date and time of the event.
87    pub date: String,
88    /// Duration of the event in minutes.
89    pub duration: i64,
90    /// ID of the event.
91    pub event_id: i64,
92    /// Importance of the event.
93    pub importance: i64,
94    /// ID of the owner of the event.
95    pub owner_id: i64,
96    /// Name of the owner of the event.
97    pub owner_name: String,
98    /// Kind of the owner of the event.
99    pub owner_type: EventOwnerType,
100    /// Response of the character to the event.
101    pub response: String,
102    /// Description of the event.
103    pub text: String,
104    /// Title of the event.
105    pub title: String,
106}
107
108#[derive(Debug, Deserialize, Serialize, Clone)]
109/// An attendee of a calendar event.
110pub struct EventAttendee {
111    /// ID of the attendee.
112    pub character_id: Option<i64>,
113    /// Response of the attendee.
114    pub event_response: Option<EventResponse>,
115}
116
117#[derive(Debug, Serialize, Clone, Copy)]
118/// The body of a request to respond to an event.
119pub struct EventResponseRequest {
120    /// The response to send.
121    pub response: EventReply,
122}
123
124impl CalendarGroup<'_> {
125    api_get!(
126        /// Return up to 50 events from a character's calendar, starting at
127        /// `from_event` when given.
128        get_character_events,
129        "GetCharactersCharacterIdCalendar",
130        RequestType::Authenticated,
131        Vec<CalendarEventSummary>,
132        (character_id: i64) => "{character_id}";
133        Optional(from_event: i64) => "from_event"
134    );
135
136    api_get!(
137        /// Return the details of a calendar event.
138        get_character_event,
139        "GetCharactersCharacterIdCalendarEventId",
140        RequestType::Authenticated,
141        CalendarEvent,
142        (character_id: i64) => "{character_id}",
143        (event_id: i64) => "{event_id}"
144    );
145
146    api_put!(
147        /// Respond to a calendar event.
148        respond_to_character_event,
149        "PutCharactersCharacterIdCalendarEventId",
150        RequestType::Authenticated,
151        (),
152        (character_id: i64) => "{character_id}",
153        (event_id: i64) => "{event_id}",
154        response: &EventResponseRequest,
155    );
156
157    api_get!(
158        /// Return the attendees of a calendar event.
159        get_character_event_attendees,
160        "GetCharactersCharacterIdCalendarEventIdAttendees",
161        RequestType::Authenticated,
162        Vec<EventAttendee>,
163        (character_id: i64) => "{character_id}",
164        (event_id: i64) => "{event_id}"
165    );
166}
167
168#[cfg(test)]
169mod calendar_tests {
170    use super::*;
171
172    #[test]
173    fn test_parse_events() {
174        let json = r#"[{"event_date": "2026-10-01T00:00:00Z", "event_id": 3000000000,
175            "event_response": "not_responded", "importance": 1, "title": "t"},
176            {"event_id": 1, "event_response": "maybe"}]"#;
177        let ev: Vec<CalendarEventSummary> = serde_json::from_str(json).unwrap();
178        assert_eq!(ev[0].event_id, Some(3_000_000_000));
179        assert_eq!(ev[0].event_response, Some(EventResponse::NotResponded));
180        assert_eq!(ev[1].event_response, Some(EventResponse::Unrecognized));
181    }
182
183    #[test]
184    fn test_parse_event_and_serialize_reply() {
185        let json = r#"{"date": "d", "duration": 60, "event_id": 1, "importance": 0, "owner_id": 5,
186            "owner_name": "n", "owner_type": "eve_server", "response": "accepted", "text": "x", "title": "t"}"#;
187        let e: CalendarEvent = serde_json::from_str(json).unwrap();
188        assert_eq!(e.owner_type, EventOwnerType::EveServer);
189        let body = EventResponseRequest {
190            response: EventReply::Tentative,
191        };
192        assert_eq!(
193            serde_json::to_string(&body).unwrap(),
194            r#"{"response":"tentative"}"#
195        );
196    }
197}