mirror of
https://gitlab.com/hladislav/radiobrowser-lib-rust.git
synced 2025-04-29 23:34:12 +00:00
Merge branch 'dev-serialize' into 'main'
add serialize to structs returned by api See merge request radiobrowser/radiobrowser-lib-rust!2
This commit is contained in:
commit
5270f8277b
4 changed files with 32 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
|
.vscode/settings.json
|
||||||
|
|
|
@ -19,6 +19,7 @@ log = { version = "0.4.20" }
|
||||||
rand = { version = "0.8.5" }
|
rand = { version = "0.8.5" }
|
||||||
reqwest = { version = "0.11.22", default-features = false, features = ["json"] }
|
reqwest = { version = "0.11.22", default-features = false, features = ["json"] }
|
||||||
serde = { version = "1.0.189", features = ["derive"] }
|
serde = { version = "1.0.189", features = ["derive"] }
|
||||||
|
serde_json = "1.0.108"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = { version = "0.3.28" }
|
futures = { version = "0.3.28" }
|
||||||
|
@ -58,4 +59,4 @@ required-features = ["blocking"]
|
||||||
# the crate that the author does not want to fix).
|
# 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
|
# - `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.
|
# their intentions, potential crate users will need to investigate on their own.
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
|
@ -10,15 +10,25 @@ fn main() -> Result<(), RbError> {
|
||||||
println!("Config: {:#?}", config);
|
println!("Config: {:#?}", config);
|
||||||
let countries = api.get_countries().send()?;
|
let countries = api.get_countries().send()?;
|
||||||
println!("Countries: {:?}", countries.len());
|
println!("Countries: {:?}", countries.len());
|
||||||
let tags = vec!["jazz","classical"];
|
let tags = vec!["jazz", "classical"];
|
||||||
let stations = api.get_stations().tag_list(tags).send()?;
|
let stations = api.get_stations().tag_list(tags).send()?;
|
||||||
println!("Stations with tags containing 'jazz' and 'classical': {:?}", stations.len());
|
println!(
|
||||||
println!("First found station: {:#?}", stations[0].clicktimestamp_iso8601);
|
"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)?;
|
let vote_result = api.station_vote(&stations[0].stationuuid)?;
|
||||||
println!("Stations voted result: {:?}", vote_result);
|
println!("Stations voted result: {:?}", vote_result);
|
||||||
let click_result = api.station_click(&stations[0].stationuuid)?;
|
let click_result = api.station_click(&stations[0].stationuuid)?;
|
||||||
println!("Stations clicked result: {:?}", click_result);
|
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);
|
println!("Station changes result: {:#?}", station_changes);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ use chrono::DateTime;
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
/// Radiobrowser status and statistical information of single server.
|
/// 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 struct ApiStatus {
|
||||||
pub supported_version: u32,
|
pub supported_version: u32,
|
||||||
pub software_version: Option<String>,
|
pub software_version: Option<String>,
|
||||||
|
@ -19,33 +20,33 @@ pub struct ApiStatus {
|
||||||
pub countries: u64,
|
pub countries: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStationAddResult {
|
pub struct ApiStationAddResult {
|
||||||
pub ok: bool,
|
pub ok: bool,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStationVoteResult {
|
pub struct ApiStationVoteResult {
|
||||||
pub ok: bool,
|
pub ok: bool,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStationClickResult {
|
pub struct ApiStationClickResult {
|
||||||
pub ok: bool,
|
pub ok: bool,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiCodec {
|
pub struct ApiCodec {
|
||||||
name: String,
|
name: String,
|
||||||
stationcount: u64,
|
stationcount: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single station entry
|
/// A single station entry
|
||||||
#[derive(PartialEq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStation {
|
pub struct ApiStation {
|
||||||
pub changeuuid: String,
|
pub changeuuid: String,
|
||||||
pub stationuuid: String,
|
pub stationuuid: String,
|
||||||
|
@ -96,7 +97,7 @@ pub struct ApiStation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single historical entry for a station
|
/// A single historical entry for a station
|
||||||
#[derive(PartialEq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStationHistory {
|
pub struct ApiStationHistory {
|
||||||
pub changeuuid: String,
|
pub changeuuid: String,
|
||||||
pub stationuuid: String,
|
pub stationuuid: String,
|
||||||
|
@ -120,7 +121,7 @@ pub struct ApiStationHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A click event for a station
|
/// A click event for a station
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStationClick {
|
pub struct ApiStationClick {
|
||||||
pub stationuuid: String,
|
pub stationuuid: String,
|
||||||
pub clickuuid: String,
|
pub clickuuid: String,
|
||||||
|
@ -131,7 +132,7 @@ pub struct ApiStationClick {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single step of a check action for a station
|
/// 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 struct ApiStationCheckStep {
|
||||||
pub stepuuid: String,
|
pub stepuuid: String,
|
||||||
pub parent_stepuuid: Option<String>,
|
pub parent_stepuuid: Option<String>,
|
||||||
|
@ -147,7 +148,7 @@ pub struct ApiStationCheckStep {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single country
|
/// A single country
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiCountry {
|
pub struct ApiCountry {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub iso_3166_1: String,
|
pub iso_3166_1: String,
|
||||||
|
@ -155,7 +156,7 @@ pub struct ApiCountry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single language
|
/// A single language
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiLanguage {
|
pub struct ApiLanguage {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub iso_639: Option<String>,
|
pub iso_639: Option<String>,
|
||||||
|
@ -163,13 +164,13 @@ pub struct ApiLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single tag
|
/// A single tag
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiTag {
|
pub struct ApiTag {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub stationcount: u32,
|
pub stationcount: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiStreamingServer {
|
pub struct ApiStreamingServer {
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
@ -178,7 +179,7 @@ pub struct ApiStreamingServer {
|
||||||
pub error: Option<String>,
|
pub error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct ApiConfig {
|
pub struct ApiConfig {
|
||||||
pub check_enabled: bool,
|
pub check_enabled: bool,
|
||||||
pub prometheus_exporter_enabled: bool,
|
pub prometheus_exporter_enabled: bool,
|
||||||
|
|
Loading…
Reference in a new issue