diff --git a/.gitignore b/.gitignore index 4fffb2f..50ed0c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +.vscode/settings.json diff --git a/Cargo.toml b/Cargo.toml index 4bae624..fc929ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ log = { version = "0.4.20" } rand = { version = "0.8.5" } reqwest = { version = "0.11.22", default-features = false, features = ["json"] } serde = { version = "1.0.189", features = ["derive"] } +serde_json = "1.0.108" [dev-dependencies] futures = { version = "0.3.28" } @@ -58,4 +59,4 @@ required-features = ["blocking"] # the crate that the author does not want to fix). # - `none`: Displays no badge on crates.io, since the maintainer has not chosen to specify # their intentions, potential crate users will need to investigate on their own. -maintenance = { status = "actively-developed" } \ No newline at end of file +maintenance = { status = "actively-developed" } diff --git a/examples/test.rs b/examples/test.rs index 367728a..e2250d6 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -10,15 +10,25 @@ fn main() -> Result<(), RbError> { println!("Config: {:#?}", config); let countries = api.get_countries().send()?; println!("Countries: {:?}", countries.len()); - let tags = vec!["jazz","classical"]; + let tags = vec!["jazz", "classical"]; let stations = api.get_stations().tag_list(tags).send()?; - println!("Stations with tags containing 'jazz' and 'classical': {:?}", stations.len()); - println!("First found station: {:#?}", stations[0].clicktimestamp_iso8601); + println!( + "Stations with tags containing 'jazz' and 'classical': {:?}", + stations.len() + ); + println!( + "First found station: {:#?}", + stations[0].clicktimestamp_iso8601 + ); + println!( + "First station JSON: {}", + serde_json::to_string(&stations[0]).expect("Failure") + ); let vote_result = api.station_vote(&stations[0].stationuuid)?; println!("Stations voted result: {:?}", vote_result); let click_result = api.station_click(&stations[0].stationuuid)?; println!("Stations clicked result: {:?}", click_result); - let station_changes = api.get_station_changes(1,None)?; + let station_changes = api.get_station_changes(1, None)?; println!("Station changes result: {:#?}", station_changes); Ok(()) } diff --git a/src/structs.rs b/src/structs.rs index c9ebcbc..192a2e9 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -3,9 +3,10 @@ use chrono::DateTime; #[cfg(feature = "chrono")] use chrono::Utc; use serde::Deserialize; +use serde::Serialize; /// Radiobrowser status and statistical information of single server. -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStatus { pub supported_version: u32, pub software_version: Option, @@ -19,33 +20,33 @@ pub struct ApiStatus { pub countries: u64, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationAddResult { pub ok: bool, pub message: String, pub uuid: String, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationVoteResult { pub ok: bool, pub message: String, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationClickResult { pub ok: bool, pub message: String, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiCodec { name: String, stationcount: u64, } /// A single station entry -#[derive(PartialEq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStation { pub changeuuid: String, pub stationuuid: String, @@ -96,7 +97,7 @@ pub struct ApiStation { } /// A single historical entry for a station -#[derive(PartialEq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationHistory { pub changeuuid: String, pub stationuuid: String, @@ -120,7 +121,7 @@ pub struct ApiStationHistory { } /// A click event for a station -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationClick { pub stationuuid: String, pub clickuuid: String, @@ -131,7 +132,7 @@ pub struct ApiStationClick { } /// A single step of a check action for a station -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStationCheckStep { pub stepuuid: String, pub parent_stepuuid: Option, @@ -147,7 +148,7 @@ pub struct ApiStationCheckStep { } /// A single country -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiCountry { pub name: String, pub iso_3166_1: String, @@ -155,7 +156,7 @@ pub struct ApiCountry { } /// A single language -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiLanguage { pub name: String, pub iso_639: Option, @@ -163,13 +164,13 @@ pub struct ApiLanguage { } /// A single tag -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiTag { pub name: String, pub stationcount: u32, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiStreamingServer { pub uuid: String, pub url: String, @@ -178,7 +179,7 @@ pub struct ApiStreamingServer { pub error: Option, } -#[derive(PartialEq, Eq, Deserialize, Debug, Clone)] +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] pub struct ApiConfig { pub check_enabled: bool, pub prometheus_exporter_enabled: bool,