Skip to main content

esi_openapi/groups/
user_interface.rs

1use crate::prelude::*;
2
3/// Endpoints for UserInterface
4pub struct UserInterfaceGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8impl UserInterfaceGroup<'_> {
9    /// Open the market details window.
10    pub async fn open_market_details_window(&self, type_id: i64) -> EsiResult<()> {
11        // not using the macro since it doesn't like no body;
12        // `type_id` is a query parameter, not part of the path
13        let path = self
14            .esi
15            .get_endpoint_for_op_id("PostUiOpenwindowMarketdetails")?;
16        let type_id = type_id.to_string();
17        self.esi
18            .query(
19                "POST",
20                RequestType::Authenticated,
21                &path,
22                Some(&[("type_id", type_id.as_str())]),
23                None,
24            )
25            .await
26    }
27}
28
29/// A new mail to pre-fill in the in-game mail window.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
31pub struct NewMailWindow {
32    /// Body of the mail.
33    pub body: String,
34    /// Character IDs of the recipients.
35    pub recipients: Vec<i64>,
36    /// Subject of the mail.
37    pub subject: String,
38    /// Corporation or alliance ID to send the mail to.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub to_corp_or_alliance_id: Option<i64>,
41    /// Mailing list ID to send the mail to.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub to_mailing_list_id: Option<i64>,
44}
45
46impl UserInterfaceGroup<'_> {
47    /// Set a solar system, station or structure as an autopilot waypoint in the client.
48    pub async fn set_autopilot_waypoint(
49        &self,
50        destination_id: i64,
51        add_to_beginning: bool,
52        clear_other_waypoints: bool,
53    ) -> EsiResult<()> {
54        let path = self.esi.get_endpoint_for_op_id("PostUiAutopilotWaypoint")?;
55        let destination_id = destination_id.to_string();
56        let add_to_beginning = add_to_beginning.to_string();
57        let clear_other_waypoints = clear_other_waypoints.to_string();
58        self.esi
59            .query(
60                "POST",
61                RequestType::Authenticated,
62                &path,
63                Some(&[
64                    ("add_to_beginning", add_to_beginning.as_str()),
65                    ("clear_other_waypoints", clear_other_waypoints.as_str()),
66                    ("destination_id", destination_id.as_str()),
67                ]),
68                None,
69            )
70            .await
71    }
72
73    /// Open the contract window in the client.
74    pub async fn open_contract_window(&self, contract_id: i64) -> EsiResult<()> {
75        let path = self
76            .esi
77            .get_endpoint_for_op_id("PostUiOpenwindowContract")?;
78        let contract_id = contract_id.to_string();
79        self.esi
80            .query(
81                "POST",
82                RequestType::Authenticated,
83                &path,
84                Some(&[("contract_id", contract_id.as_str())]),
85                None,
86            )
87            .await
88    }
89
90    /// Open the information window of a character, corporation or alliance in the client.
91    pub async fn open_information_window(&self, target_id: i64) -> EsiResult<()> {
92        let path = self
93            .esi
94            .get_endpoint_for_op_id("PostUiOpenwindowInformation")?;
95        let target_id = target_id.to_string();
96        self.esi
97            .query(
98                "POST",
99                RequestType::Authenticated,
100                &path,
101                Some(&[("target_id", target_id.as_str())]),
102                None,
103            )
104            .await
105    }
106
107    /// Open the new mail window in the client with the given content.
108    pub async fn open_new_mail_window(&self, mail: &NewMailWindow) -> EsiResult<()> {
109        let path = self.esi.get_endpoint_for_op_id("PostUiOpenwindowNewmail")?;
110        let body = serde_json::to_string(mail)?;
111        self.esi
112            .query("POST", RequestType::Authenticated, &path, None, Some(&body))
113            .await
114    }
115}
116
117#[cfg(test)]
118mod new_mail_tests {
119    use super::*;
120
121    #[test]
122    fn test_serialize_new_mail_window() {
123        let mail = NewMailWindow {
124            body: "b".into(),
125            recipients: vec![1, 2],
126            subject: "s".into(),
127            to_corp_or_alliance_id: None,
128            to_mailing_list_id: Some(5),
129        };
130        let json = serde_json::to_string(&mail).unwrap();
131        assert!(json.contains("\"to_mailing_list_id\":5"));
132        assert!(!json.contains("to_corp_or_alliance_id"));
133    }
134}