esi_openapi/groups/
contacts.rs1#![allow(unused)]
2
3use crate::prelude::*;
4
5pub struct ContactsGroup<'a> {
7 pub(crate) esi: &'a Esi,
8}
9
10#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
11pub enum ContactType {
13 #[serde(rename = "character")]
15 Character,
16 #[serde(rename = "corporation")]
18 Corporation,
19 #[serde(rename = "alliance")]
21 Alliance,
22 #[serde(rename = "faction")]
24 Faction,
25 #[serde(other)]
27 Unrecognized,
28}
29
30#[derive(Debug, Deserialize, Serialize, Clone)]
31pub struct Contact {
33 pub contact_id: i64,
35 pub contact_type: ContactType,
37 #[serde(default)]
39 pub is_blocked: Option<bool>,
40 #[serde(default)]
42 pub is_watched: Option<bool>,
43 #[serde(default)]
45 pub label_ids: Vec<i64>,
46 pub standing: f64,
48}
49
50#[derive(Debug, Deserialize, Serialize, Clone)]
51pub struct ContactLabel {
53 pub label_id: i64,
55 pub label_name: String,
57}
58
59impl ContactsGroup<'_> {
60 api_get!(
61 get_alliance_contacts,
63 "GetAlliancesAllianceIdContacts",
64 RequestType::Authenticated,
65 Vec<Contact>,
66 (alliance_id: i64) => "{alliance_id}";
67 Optional(page: i32) => "page"
68 );
69
70 api_get!(
71 get_alliance_contact_labels,
73 "GetAlliancesAllianceIdContactsLabels",
74 RequestType::Authenticated,
75 Vec<ContactLabel>,
76 (alliance_id: i64) => "{alliance_id}"
77 );
78
79 api_delete!(
80 delete_character_contacts,
82 "DeleteCharactersCharacterIdContacts",
83 RequestType::Authenticated,
84 (),
85 (character_id: i64) => "{character_id}";
86 Many(contact_ids: &[i64]) => "contact_ids"
87 );
88
89 api_get!(
90 get_character_contacts,
92 "GetCharactersCharacterIdContacts",
93 RequestType::Authenticated,
94 Vec<Contact>,
95 (character_id: i64) => "{character_id}";
96 Optional(page: i32) => "page"
97 );
98
99 api_post!(
100 add_character_contacts,
102 "PostCharactersCharacterIdContacts",
103 RequestType::Authenticated,
104 Vec<i64>,
105 (character_id: i64) => "{character_id}";
106 Required(standing: f64) => "standing",
107 OptionalMany(label_ids: &[i64]) => "label_ids",
108 Optional(watched: bool) => "watched";
109 contact_ids: &[i64]
110 );
111
112 api_put!(
113 update_character_contacts,
115 "PutCharactersCharacterIdContacts",
116 RequestType::Authenticated,
117 (),
118 (character_id: i64) => "{character_id}";
119 Required(standing: f64) => "standing",
120 OptionalMany(label_ids: &[i64]) => "label_ids",
121 Optional(watched: bool) => "watched";
122 contact_ids: &[i64]
123 );
124
125 api_get!(
126 get_character_contact_labels,
128 "GetCharactersCharacterIdContactsLabels",
129 RequestType::Authenticated,
130 Vec<ContactLabel>,
131 (character_id: i64) => "{character_id}"
132 );
133
134 api_get!(
135 get_corporation_contacts,
137 "GetCorporationsCorporationIdContacts",
138 RequestType::Authenticated,
139 Vec<Contact>,
140 (corporation_id: i64) => "{corporation_id}";
141 Optional(page: i32) => "page"
142 );
143
144 api_get!(
145 get_corporation_contact_labels,
147 "GetCorporationsCorporationIdContactsLabels",
148 RequestType::Authenticated,
149 Vec<ContactLabel>,
150 (corporation_id: i64) => "{corporation_id}"
151 );
152}
153
154#[cfg(test)]
155mod contacts_tests {
156 use super::*;
157
158 #[test]
159 fn test_parse_contacts() {
160 let json = r#"[{"contact_id": 2112625428, "contact_type": "character", "standing": 10.0,
161 "is_blocked": false, "label_ids": [1]},
162 {"contact_id": 1, "contact_type": "other", "standing": -5.5}]"#;
163 let contacts: Vec<Contact> = serde_json::from_str(json).unwrap();
164 assert_eq!(contacts[0].contact_type, ContactType::Character);
165 assert_eq!(contacts[1].contact_type, ContactType::Unrecognized);
166 assert!(contacts[1].label_ids.is_empty());
167 }
168
169 #[test]
170 fn test_parse_labels() {
171 let l: Vec<ContactLabel> =
172 serde_json::from_str(r#"[{"label_id": 5000000000, "label_name": "Friends"}]"#).unwrap();
173 assert_eq!(l[0].label_id, 5_000_000_000);
174 }
175}