1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::{auth::NadeoClient, client::NadeoApiClient, live::NadeoError};
5
6pub trait MeetApiClient: NadeoApiClient {
8 async fn get_cup_of_the_day(&self) -> Result<Option<CupOfTheDay>, NadeoError> {
12 let (rb, permit) = self.meet_get("api/cup-of-the-day/current").await;
13 let resp = rb.send().await?;
14 if resp.status().as_u16() == 204 {
15 return Ok(None);
16 }
17 let j = resp.json().await?;
18 drop(permit);
19 Ok(Some(serde_json::from_value(j)?))
20 }
21}
22
23impl MeetApiClient for NadeoClient {}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[allow(non_camel_case_types, non_snake_case)]
27pub struct CupOfTheDay {
28 pub id: i64,
29 pub edition: i64,
30 pub competition: Competition,
31 pub challenge: Challenge,
32 pub startDate: i64,
33 pub endDate: i64,
34 pub deletedOn: Option<i64>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[allow(non_camel_case_types, non_snake_case)]
39pub struct Competition {
40 pub id: i64,
41 pub liveId: String,
42 pub creator: String,
43 pub name: String,
44 pub participantType: String,
45 pub description: Option<String>,
46 pub registrationStart: Option<i64>,
47 pub registrationEnd: Option<i64>,
48 pub startDate: i64,
49 pub endDate: i64,
50 pub matchesGenerationDate: i64,
51 pub nbPlayers: i64,
52 pub spotStructure: String,
53 pub leaderboardId: i64,
54 pub manialink: Option<String>,
55 pub rulesUrl: Option<String>,
56 pub streamUrl: Option<String>,
57 pub websiteUrl: Option<String>,
58 pub logoUrl: Option<String>,
59 pub verticalUrl: Option<String>,
60 pub allowedZones: Vec<Value>,
61 pub deletedOn: Option<i64>,
62 pub autoNormalizeSeeds: bool,
63 pub region: String,
64 pub autoGetParticipantSkillLevel: String,
65 pub matchAutoMode: String,
66 pub partition: String,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[allow(non_camel_case_types, non_snake_case)]
71pub struct Challenge {
72 pub id: i64,
73 pub uid: String,
74 pub name: String,
75 pub scoreDirection: String,
76 pub startDate: i64,
77 pub endDate: i64,
78 pub status: String,
79 pub resultsVisibility: String,
80 pub creator: String,
81 pub admins: Vec<String>,
82 pub nbServers: i64,
83 pub autoScale: bool,
84 pub nbMaps: i64,
85 pub leaderboardId: i64,
86 pub deletedOn: Option<i64>,
87 pub leaderboardType: String,
88 pub completeTimeout: i64,
89}
90
91#[cfg(test)]
92mod tests {
93 use crate::{
94 auth::{NadeoClient, UserAgentDetails},
95 meet::MeetApiClient,
96 test_helpers::get_test_creds,
97 user_agent_auto,
98 };
99
100 #[ignore]
101 #[tokio::test]
102 async fn test_get_cup_of_the_day() {
103 let creds = get_test_creds();
104 let email = std::env::var("NADEO_TEST_UA_EMAIL").unwrap();
105 let client = NadeoClient::create(creds, user_agent_auto!(&email), 10)
106 .await
107 .unwrap();
108 let cup = client.get_cup_of_the_day().await.unwrap();
116 println!("{:?}", cup);
117 match cup {
118 Some(c) => {
119 assert!(c.id > 0);
120 println!("Cup of the Day: {}", c.competition.name);
121 }
122 None => {
123 println!("No Cup of the Day");
124 }
125 }
126 }
127}