Skip to main content

esi_openapi/groups/
loyalty.rs

1use crate::prelude::*;
2
3/// Endpoints for Loyalty
4pub struct LoyaltyGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8/// An item required, besides LP and ISK, to take an offer.
9#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
10#[allow(missing_docs)]
11pub struct RequiredItem {
12    pub quantity: i64,
13    pub type_id: i64,
14}
15
16/// An offer in a loyalty points store.
17#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
18#[allow(missing_docs)]
19pub struct LoyaltyOffer {
20    pub ak_cost: Option<i64>,
21    pub isk_cost: i64,
22    pub lp_cost: i64,
23    pub offer_id: i64,
24    pub quantity: i64,
25    pub required_items: Vec<RequiredItem>,
26    pub type_id: i64,
27}
28
29/// A character's loyalty points with a corporation.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
31#[allow(missing_docs)]
32pub struct LoyaltyPoints {
33    pub corporation_id: i64,
34    pub loyalty_points: i64,
35}
36
37impl LoyaltyGroup<'_> {
38    api_get!(
39        /// List a character's loyalty points per corporation.
40        get_character_points,
41        "GetCharactersCharacterIdLoyaltyPoints",
42        RequestType::Authenticated,
43        Vec<LoyaltyPoints>,
44        (character_id: i64) => "{character_id}"
45    );
46
47    api_get!(
48        /// List the offers of a corporation's loyalty points store.
49        get_store_offers,
50        "GetLoyaltyStoresCorporationIdOffers",
51        RequestType::Public,
52        Vec<LoyaltyOffer>,
53        (corporation_id: i64) => "{corporation_id}"
54    );
55}
56
57#[cfg(test)]
58mod tests {
59    use super::LoyaltyOffer;
60
61    #[test]
62    fn test_parse_offer() {
63        let json = r#"[{
64            "isk_cost": 5000000000, "lp_cost": 1000, "offer_id": 3751,
65            "quantity": 1, "required_items": [{"quantity": 2, "type_id": 34}], "type_id": 23
66        }]"#;
67        let offers: Vec<LoyaltyOffer> = serde_json::from_str(json).unwrap();
68        assert_eq!(offers[0].isk_cost, 5_000_000_000);
69        assert!(offers[0].ak_cost.is_none());
70    }
71}