Skip to main content

splatoon3_rs/endpoints/stages/
x.rs

1use reqwest::StatusCode;
2
3use crate::{
4    client::SplaClient,
5    models::stages::{Schedule, StagesResponse},
6};
7
8const X_SCHEDULE_ENDPOINT: &str = "x/schedule";
9
10impl SplaClient {
11    pub async fn get_x_schedule(&self) -> Result<Vec<Schedule>, Box<dyn std::error::Error>> {
12        let base_url = &self.base_url;
13
14        let response = self
15            .client
16            .get(format!("{base_url}/{X_SCHEDULE_ENDPOINT}"))
17            .send()
18            .await?;
19
20        match response.status() {
21            StatusCode::OK => {
22                let x_schedule: StagesResponse = response.json().await?;
23                Ok(x_schedule.results)
24            }
25            status_code => {
26                Err(format!("API request failed with status code: {}", status_code).into())
27            }
28        }
29    }
30}