add serialize to structs returned by api

This commit is contained in:
kaesluder 2024-12-04 21:06:17 +00:00 committed by segler_alex
parent 3703d731d1
commit 08d27fc792
4 changed files with 32 additions and 19 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/Cargo.lock
.vscode/settings.json

View file

@ -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" }
maintenance = { status = "actively-developed" }

View file

@ -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(())
}

View file

@ -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<String>,
@ -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<String>,
@ -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<String>,
@ -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<String>,
}
#[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,