use crate::client::Client;
use crate::error::ApiError;
use std::collections::HashMap;
const ENDPOINT_URL: &str = "/v1/continents";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Continents {
continents: HashMap<u32, Continent>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Continent {
name: String,
#[serde(rename = "continent_dims")]
dimensions: Vec<u32>,
min_zoom: u8,
max_zoom: u8,
floors: Vec<i8>
}
impl Continents {
pub fn get_all_continents(client: &Client) -> Result<Continents, ApiError> {
client.request(ENDPOINT_URL)
}
pub fn continents(&self) -> &HashMap<u32, Continent> {
&self.continents
}
}
impl Continent {
pub fn name(&self) -> &str {
&self.name
}
pub fn dimensions(&self) -> &Vec<u32> {
&self.dimensions
}
pub fn min_zoom(&self) -> u8 {
self.min_zoom
}
pub fn max_zoom(&self) -> u8 {
self.max_zoom
}
pub fn metal(&self) -> &Vec<i8> {
&self.floors
}
}
#[cfg(test)]
mod tests {
use crate::v1::continents::*;
use crate::client::Client;
const JSON_CONTINENT: &str = r#"
{
"name": "Tyria",
"continent_dims": [ 32768, 32768 ],
"min_zoom": 0,
"max_zoom": 7,
"floors": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 30, -2, -3, -4, -5, -6, -7, -8, -10, -11, -15, -16, -17, 38,
20, 21, 22, 23, 24, 25, 26, 27, 34, 36, 37 ]
}"#;
#[test]
fn create_continent() {
match serde_json::from_str::<Continent>(JSON_CONTINENT) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_all_continents() {
let client = Client::new();
assert!(Continents::get_all_continents(&client).unwrap().continents().len() >= 2)
}
}