use crate::client::Client;
use crate::error::ApiError;
const ENDPOINT_URL: &str = "/v1/wvw/matches";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Matches {
#[serde(rename = "wvw_matches")]
matches: Vec<Match>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Match {
#[serde(rename = "wvw_match_id")]
match_id: String,
red_world_id: u32,
blue_world_id: u32,
green_world_id: u32,
start_time: String,
end_time: String,
}
impl Matches {
pub fn get_all(client: &Client) -> Result<Matches, ApiError> {
client.request(ENDPOINT_URL)
}
pub fn matches(&self) -> &Vec<Match> {
&self.matches
}
}
impl Match {
pub fn match_id(&self) -> &str {
&self.match_id
}
pub fn red_world_id(&self) -> u32 {
self.red_world_id
}
pub fn blue_world_id(&self) -> u32 {
self.blue_world_id
}
pub fn green_world_id(&self) -> u32 {
self.green_world_id
}
pub fn start_time(&self) -> &str {
&self.start_time
}
pub fn end_time(&self) -> &str {
&self.end_time
}
}
#[cfg(test)]
mod tests {
use crate::v1::wvw::matches::*;
use crate::client::Client;
const JSON_MATCHES: &str = r#"
{
"wvw_matches": [
{
"wvw_match_id": "2-2",
"red_world_id": 2104,
"blue_world_id": 2301,
"green_world_id": 2202,
"start_time": "2013-08-02T18:00:00Z",
"end_time": "2013-08-09T18:00:00Z"
},
{
"wvw_match_id": "1-3",
"red_world_id": 1016,
"blue_world_id": 1021,
"green_world_id": 1014,
"start_time": "2013-08-03T01:00:00Z",
"end_time": "2013-08-10T01:00:00Z"
}
]
}"#;
#[test]
fn create_matches() {
match serde_json::from_str::<Matches>(JSON_MATCHES) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_all_matches() {
let client = Client::new();
assert!(Matches::get_all(&client).unwrap().matches().len() >= 4)
}
}