mirror of
https://gitlab.com/hladislav/radiobrowser-lib-rust.git
synced 2025-04-29 23:34:12 +00:00
added feature chrono
This commit is contained in:
parent
adf4c5a49f
commit
7e4a60c28a
7 changed files with 57 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "radiobrowser"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
authors = ["segler_alex <segler_alex@web.de>"]
|
||||
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]]
|
||||
|
|
|
@ -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<UTC> objects instead of strings
|
||||
|
||||
## Getting started (Blocking)
|
||||
### Example:
|
||||
It needs to have the feature "blocking" enabled.
|
||||
|
|
|
@ -29,7 +29,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
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?;
|
||||
|
|
|
@ -11,8 +11,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
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)?;
|
||||
|
|
|
@ -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<P: AsRef<str>>(self, codec: P) -> Self {
|
||||
StationSearchBuilder {
|
||||
|
@ -89,12 +91,13 @@ impl StationSearchBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn bitrate_min<P: AsRef<str>>(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<P: AsRef<str>>(self, bitrate_max: P) -> Self {
|
||||
|
||||
pub fn bitrate_max(self, bitrate_max: u16) -> Self {
|
||||
StationSearchBuilder {
|
||||
builder: self.builder.bitrate_max(bitrate_max),
|
||||
}
|
||||
|
|
|
@ -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<P: AsRef<str>>(mut self, codec: P) -> Self {
|
||||
self.map
|
||||
|
@ -143,14 +145,15 @@ impl StationSearchBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn bitrate_min<P: AsRef<str>>(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<P: AsRef<str>>(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
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String>,
|
||||
pub votes: i32,
|
||||
pub lastchangetime: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub lastchangetime_iso8601: Option<DateTime<Utc>>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub lastchangetime_iso8601: Option<String>,
|
||||
pub codec: String,
|
||||
pub bitrate: u32,
|
||||
pub hls: i8,
|
||||
pub lastcheckok: i8,
|
||||
pub lastchecktime: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub lastchecktime_iso8601: Option<DateTime<Utc>>,
|
||||
pub lastcheckoktime: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub lastcheckoktime_iso8601: Option<DateTime<Utc>>,
|
||||
pub lastlocalchecktime: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub lastlocalchecktime_iso8601: Option<DateTime<Utc>>,
|
||||
pub clicktimestamp: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub clicktimestamp_iso8601: Option<DateTime<Utc>>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub lastchecktime_iso8601: Option<String>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub lastcheckoktime_iso8601: Option<String>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub lastlocalchecktime_iso8601: Option<String>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub clicktimestamp_iso8601: Option<String>,
|
||||
pub clickcount: u32,
|
||||
pub clicktrend: i32,
|
||||
pub ssl_error: Option<u8>,
|
||||
|
@ -99,8 +111,10 @@ pub struct ApiStationHistory {
|
|||
pub language: String,
|
||||
pub languagecodes: Option<String>,
|
||||
pub votes: i32,
|
||||
pub lastchangetime: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub lastchangetime_iso8601: Option<DateTime<Utc>>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub lastchangetime_iso8601: Option<String>,
|
||||
pub geo_lat: Option<f64>,
|
||||
pub geo_long: Option<f64>,
|
||||
}
|
||||
|
@ -110,8 +124,10 @@ pub struct ApiStationHistory {
|
|||
pub struct ApiStationClick {
|
||||
pub stationuuid: String,
|
||||
pub clickuuid: String,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub clicktimestamp_iso8601: Option<DateTime<Utc>>,
|
||||
pub clicktimestamp: String,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub clicktimestamp_iso8601: Option<String>,
|
||||
}
|
||||
|
||||
/// A single step of a check action for a station
|
||||
|
@ -124,7 +140,10 @@ pub struct ApiStationCheckStep {
|
|||
pub url: String,
|
||||
pub urltype: Option<String>,
|
||||
pub error: Option<String>,
|
||||
#[cfg(feature = "chrono")]
|
||||
pub creation_iso8601: DateTime<Utc>,
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
pub creation_iso8601: String,
|
||||
}
|
||||
|
||||
/// A single country
|
||||
|
|
Loading…
Reference in a new issue