station list changes

This commit is contained in:
Alex 2023-01-27 23:43:42 +01:00
parent 68acb8593b
commit 62b1ca0a96
5 changed files with 22 additions and 4 deletions

View file

@ -14,12 +14,12 @@ repository = "https://gitlab.com/radiobrowser/radiobrowser-lib-rust"
[dependencies] [dependencies]
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] } async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
async-std-resolver = "0.22.0" async-std-resolver = "0.22.0"
chrono = { version = "0.4.22", features = ["serde"], optional = true } chrono = { version = "0.4.23", features = ["serde"], optional = true }
futures = { version = "0.3.24" } futures = { version = "0.3.25" }
log = { version = "0.4.17" } log = { version = "0.4.17" }
rand = { version = "0.8.5" } rand = { version = "0.8.5" }
reqwest = { version = "0.11.11", features = ["json"] } reqwest = { version = "0.11.14", features = ["json"] }
serde = { version = "1.0.144", features = ["derive"] } serde = { version = "1.0.152", features = ["derive"] }
[features] [features]
default = ["chrono", "blocking"] default = ["chrono", "blocking"]

View file

@ -1,4 +1,5 @@
use crate::ApiStationClickResult; use crate::ApiStationClickResult;
use crate::ApiStationHistory;
use crate::ApiStationVoteResult; use crate::ApiStationVoteResult;
use crate::ApiStatus; use crate::ApiStatus;
use crate::external::post_api; use crate::external::post_api;
@ -69,6 +70,14 @@ impl RadioBrowserAPI {
post_api(self.get_current_server(), endpoint.as_ref(), mapjson).await post_api(self.get_current_server(), endpoint.as_ref(), mapjson).await
} }
pub async fn get_station_changes(&mut self, limit: u64, last_change_uuid: Option<String>) -> Result<Vec<ApiStationHistory>, Box<dyn Error>> {
let query = match last_change_uuid {
Some(uuid) => format!("/json/stations/changed?limit={}&lastchangeuuid={}", limit, uuid),
None => format!("/json/stations/changed?limit={}", limit)
};
Ok(self.post_api(query).await?)
}
pub async fn get_server_config(&mut self) -> Result<ApiConfig, Box<dyn Error>> { pub async fn get_server_config(&mut self) -> Result<ApiConfig, Box<dyn Error>> {
Ok(self.post_api("/json/config").await?) Ok(self.post_api("/json/config").await?)
} }

View file

@ -35,5 +35,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Stations voted result: {:?}", vote_result); println!("Stations voted result: {:?}", vote_result);
let click_result = api.station_click(&stations[0].stationuuid).await?; let click_result = api.station_click(&stations[0].stationuuid).await?;
println!("Stations clicked result: {:?}", click_result); println!("Stations clicked result: {:?}", click_result);
let station_changes = api.get_station_changes(1,None).await?;
println!("Station changes result: {:#?}", station_changes);
Ok(()) Ok(())
} }

View file

@ -19,5 +19,7 @@ fn main() -> Result<(), Box<dyn Error>> {
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)?;
println!("Station changes result: {:#?}", station_changes);
Ok(()) Ok(())
} }

View file

@ -1,3 +1,4 @@
use crate::ApiStationHistory;
use crate::blocking::stationsearchbuilder::StationSearchBuilder; use crate::blocking::stationsearchbuilder::StationSearchBuilder;
use crate::blocking::CountrySearchBuilder; use crate::blocking::CountrySearchBuilder;
use crate::blocking::LanguageSearchBuilder; use crate::blocking::LanguageSearchBuilder;
@ -28,6 +29,10 @@ impl RadioBrowserAPI {
task::block_on(async { self.api.get_server_status().await }) task::block_on(async { self.api.get_server_status().await })
} }
pub fn get_station_changes(&mut self, limit: u64, last_change_uuid: Option<String>) -> Result<Vec<ApiStationHistory>, Box<dyn Error>> {
task::block_on(async { self.api.get_station_changes(limit, last_change_uuid).await })
}
pub fn get_server_config(&mut self) -> Result<ApiConfig, Box<dyn Error>> { pub fn get_server_config(&mut self) -> Result<ApiConfig, Box<dyn Error>> {
task::block_on(async { self.api.get_server_config().await }) task::block_on(async { self.api.get_server_config().await })
} }