#![allow(unused)]
use crate::prelude::*;
pub struct ContactsGroup<'a> {
pub(crate) esi: &'a Esi,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
pub enum ContactType {
#[serde(rename = "character")]
Character,
#[serde(rename = "corporation")]
Corporation,
#[serde(rename = "alliance")]
Alliance,
#[serde(rename = "faction")]
Faction,
#[serde(other)]
Unrecognized,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Contact {
pub contact_id: i64,
pub contact_type: ContactType,
#[serde(default)]
pub is_blocked: Option<bool>,
#[serde(default)]
pub is_watched: Option<bool>,
#[serde(default)]
pub label_ids: Vec<i64>,
pub standing: f64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ContactLabel {
pub label_id: i64,
pub label_name: String,
}
impl ContactsGroup<'_> {
api_get!(
get_alliance_contacts,
"GetAlliancesAllianceIdContacts",
RequestType::Authenticated,
Vec<Contact>,
(alliance_id: i64) => "{alliance_id}";
Optional(page: i32) => "page"
);
api_get!(
get_alliance_contact_labels,
"GetAlliancesAllianceIdContactsLabels",
RequestType::Authenticated,
Vec<ContactLabel>,
(alliance_id: i64) => "{alliance_id}"
);
api_delete!(
delete_character_contacts,
"DeleteCharactersCharacterIdContacts",
RequestType::Authenticated,
(),
(character_id: i64) => "{character_id}";
Many(contact_ids: &[i64]) => "contact_ids"
);
api_get!(
get_character_contacts,
"GetCharactersCharacterIdContacts",
RequestType::Authenticated,
Vec<Contact>,
(character_id: i64) => "{character_id}";
Optional(page: i32) => "page"
);
api_post!(
add_character_contacts,
"PostCharactersCharacterIdContacts",
RequestType::Authenticated,
Vec<i64>,
(character_id: i64) => "{character_id}";
Required(standing: f64) => "standing",
OptionalMany(label_ids: &[i64]) => "label_ids",
Optional(watched: bool) => "watched";
contact_ids: &[i64]
);
api_put!(
update_character_contacts,
"PutCharactersCharacterIdContacts",
RequestType::Authenticated,
(),
(character_id: i64) => "{character_id}";
Required(standing: f64) => "standing",
OptionalMany(label_ids: &[i64]) => "label_ids",
Optional(watched: bool) => "watched";
contact_ids: &[i64]
);
api_get!(
get_character_contact_labels,
"GetCharactersCharacterIdContactsLabels",
RequestType::Authenticated,
Vec<ContactLabel>,
(character_id: i64) => "{character_id}"
);
api_get!(
get_corporation_contacts,
"GetCorporationsCorporationIdContacts",
RequestType::Authenticated,
Vec<Contact>,
(corporation_id: i64) => "{corporation_id}";
Optional(page: i32) => "page"
);
api_get!(
get_corporation_contact_labels,
"GetCorporationsCorporationIdContactsLabels",
RequestType::Authenticated,
Vec<ContactLabel>,
(corporation_id: i64) => "{corporation_id}"
);
}
#[cfg(test)]
mod contacts_tests {
use super::*;
#[test]
fn test_parse_contacts() {
let json = r#"[{"contact_id": 2112625428, "contact_type": "character", "standing": 10.0,
"is_blocked": false, "label_ids": [1]},
{"contact_id": 1, "contact_type": "other", "standing": -5.5}]"#;
let contacts: Vec<Contact> = serde_json::from_str(json).unwrap();
assert_eq!(contacts[0].contact_type, ContactType::Character);
assert_eq!(contacts[1].contact_type, ContactType::Unrecognized);
assert!(contacts[1].label_ids.is_empty());
}
#[test]
fn test_parse_labels() {
let l: Vec<ContactLabel> =
serde_json::from_str(r#"[{"label_id": 5000000000, "label_name": "Friends"}]"#).unwrap();
assert_eq!(l[0].label_id, 5_000_000_000);
}
}