diff --git a/Cargo.toml b/Cargo.toml index c5980d8..f0d4988 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radiobrowser" -version = "0.3.0" +version = "0.4.0" authors = ["segler_alex "] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ repository = "https://gitlab.com/radiobrowser/radiobrowser-lib-rust" [dependencies] async-std = { version = "1.11.0", features = ["attributes", "tokio1"] } async-std-resolver = "0.21.2" -chrono = { version = "0.4.19", features = ["serde"] } +chrono = { version = "0.4.19", features = ["serde"], optional = true } futures = { version = "0.3.21" } log = { version = "0.4.17" } rand = { version = "0.8.5" } @@ -22,7 +22,7 @@ reqwest = { version = "0.11.10", features = ["json"] } serde = { version = "1.0.137", features = ["derive"] } [features] -default = [] +default = ["chrono", "blocking"] blocking = [] [[bin]] diff --git a/README.md b/README.md index 6de5f9f..88eb961 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ Client library for radio-browser.info and other radio-browser-rust servers - [x] Station actions: click, vote - [ ] Add streams +## Crate features +* "blocking" - support for non-async (blocking) mode +* "chrono" - return DateTime objects instead of strings + ## Getting started (Blocking) ### Example: It needs to have the feature "blocking" enabled. diff --git a/src/bin/test-async.rs b/src/bin/test-async.rs index 2346b93..64e8f89 100644 --- a/src/bin/test-async.rs +++ b/src/bin/test-async.rs @@ -29,7 +29,8 @@ async fn main() -> Result<(), Box> { println!("{:?}", tags); let stations = stations?; println!("Stations found: {}", stations.len()); - + println!("First found station: {:#?}", stations[0]); + println!("First found station: {:#?}", stations[0].clicktimestamp_iso8601); let vote_result = api.station_vote(&stations[0].stationuuid).await?; println!("Stations voted result: {:?}", vote_result); let click_result = api.station_click(&stations[0].stationuuid).await?; diff --git a/src/bin/test.rs b/src/bin/test.rs index 8ab82f1..19336a1 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -11,8 +11,10 @@ fn main() -> Result<(), Box> { println!("Config: {:#?}", config); let countries = api.get_countries().send()?; println!("Countries: {:?}", countries.len()); - let stations = api.get_stations().name("jazz").send()?; - println!("Stations with name containing 'jazz': {:?}", stations.len()); + 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); let vote_result = api.station_vote(&stations[0].stationuuid)?; println!("Stations voted result: {:?}", vote_result); let click_result = api.station_click(&stations[0].stationuuid)?; diff --git a/src/blocking/stationsearchbuilder.rs b/src/blocking/stationsearchbuilder.rs index 75a137f..584d78b 100644 --- a/src/blocking/stationsearchbuilder.rs +++ b/src/blocking/stationsearchbuilder.rs @@ -79,9 +79,11 @@ impl StationSearchBuilder { } } - /* - tagList STRING, STRING, ... OPTIONAL. , a comma-separated list of tag. It can also be an array of string in JSON HTTP POST parameters. All tags in list have to match. - */ + pub fn tag_list(self, tags: Vec<&str>) -> Self { + StationSearchBuilder { + builder: self.builder.tag_list(tags), + } + } pub fn codec>(self, codec: P) -> Self { StationSearchBuilder { @@ -89,12 +91,13 @@ impl StationSearchBuilder { } } - pub fn bitrate_min>(self, bitrate_min: P) -> Self { + pub fn bitrate_min(self, bitrate_min: u16) -> Self { StationSearchBuilder { builder: self.builder.bitrate_min(bitrate_min), } } - pub fn bitrate_max>(self, bitrate_max: P) -> Self { + + pub fn bitrate_max(self, bitrate_max: u16) -> Self { StationSearchBuilder { builder: self.builder.bitrate_max(bitrate_max), } diff --git a/src/stationsearchbuilder.rs b/src/stationsearchbuilder.rs index 3d14c2d..a3dcb9b 100644 --- a/src/stationsearchbuilder.rs +++ b/src/stationsearchbuilder.rs @@ -133,9 +133,11 @@ impl StationSearchBuilder { self } - /* - tagList STRING, STRING, ... OPTIONAL. , a comma-separated list of tag. It can also be an array of string in JSON HTTP POST parameters. All tags in list have to match. - */ + pub fn tag_list(mut self, tags: Vec<&str>) -> Self { + self.map + .insert(String::from("tagList"), tags.join(",")); + self + } pub fn codec>(mut self, codec: P) -> Self { self.map @@ -143,14 +145,15 @@ impl StationSearchBuilder { self } - pub fn bitrate_min>(mut self, bitrate_min: P) -> Self { + pub fn bitrate_min(mut self, bitrate_min: u16) -> Self { self.map - .insert(String::from("bitrateMin"), bitrate_min.as_ref().to_string()); + .insert(String::from("bitrateMin"), bitrate_min.to_string()); self } - pub fn bitrate_max>(mut self, bitrate_max: P) -> Self { + + pub fn bitrate_max(mut self, bitrate_max: u16) -> Self { self.map - .insert(String::from("bitrateMax"), bitrate_max.as_ref().to_string()); + .insert(String::from("bitrateMax"), bitrate_max.to_string()); self } diff --git a/src/structs.rs b/src/structs.rs index 240b34c..e0c31f5 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,4 +1,6 @@ +#[cfg(feature = "chrono")] use chrono::DateTime; +#[cfg(feature = "chrono")] use chrono::Utc; use serde::Deserialize; @@ -61,20 +63,30 @@ pub struct ApiStation { pub language: String, pub languagecodes: Option, pub votes: i32, - pub lastchangetime: String, + #[cfg(feature = "chrono")] pub lastchangetime_iso8601: Option>, + #[cfg(not(feature = "chrono"))] + pub lastchangetime_iso8601: Option, pub codec: String, pub bitrate: u32, pub hls: i8, pub lastcheckok: i8, - pub lastchecktime: String, + #[cfg(feature = "chrono")] pub lastchecktime_iso8601: Option>, - pub lastcheckoktime: String, + #[cfg(feature = "chrono")] pub lastcheckoktime_iso8601: Option>, - pub lastlocalchecktime: String, + #[cfg(feature = "chrono")] pub lastlocalchecktime_iso8601: Option>, - pub clicktimestamp: String, + #[cfg(feature = "chrono")] pub clicktimestamp_iso8601: Option>, + #[cfg(not(feature = "chrono"))] + pub lastchecktime_iso8601: Option, + #[cfg(not(feature = "chrono"))] + pub lastcheckoktime_iso8601: Option, + #[cfg(not(feature = "chrono"))] + pub lastlocalchecktime_iso8601: Option, + #[cfg(not(feature = "chrono"))] + pub clicktimestamp_iso8601: Option, pub clickcount: u32, pub clicktrend: i32, pub ssl_error: Option, @@ -99,8 +111,10 @@ pub struct ApiStationHistory { pub language: String, pub languagecodes: Option, pub votes: i32, - pub lastchangetime: String, + #[cfg(feature = "chrono")] pub lastchangetime_iso8601: Option>, + #[cfg(not(feature = "chrono"))] + pub lastchangetime_iso8601: Option, pub geo_lat: Option, pub geo_long: Option, } @@ -110,8 +124,10 @@ pub struct ApiStationHistory { pub struct ApiStationClick { pub stationuuid: String, pub clickuuid: String, + #[cfg(feature = "chrono")] pub clicktimestamp_iso8601: Option>, - pub clicktimestamp: String, + #[cfg(not(feature = "chrono"))] + pub clicktimestamp_iso8601: Option, } /// A single step of a check action for a station @@ -124,7 +140,10 @@ pub struct ApiStationCheckStep { pub url: String, pub urltype: Option, pub error: Option, + #[cfg(feature = "chrono")] pub creation_iso8601: DateTime, + #[cfg(not(feature = "chrono"))] + pub creation_iso8601: String, } /// A single country