Commit ce146c82 authored by Felix Häcker's avatar Felix Häcker

implement station search

parent 09ae58b9
......@@ -5,11 +5,12 @@ use std::sync::mpsc::channel;
use std::thread;
use std::rc::Rc;
use std::cell::RefCell;
use restson::{RestClient, Error};
use restson::{RestClient, RestPath, Error};
use {Codec, Country, Language, State, Station, Stats, Tag};
use {CodecResponse, CountryResponse, LanguageResponse, StateResponse, StationResponse, TagResponse};
use PlayableStationUrl;
use {PlayableStationUrl, StationSearch};
pub struct Client {
rest_client: RestClient,
......@@ -82,4 +83,11 @@ impl Client {
let result: PlayableStationUrl = self.rest_client.get(id)?;
Ok(result.url)
}
pub fn search(&mut self, data: StationSearch) -> Result<Vec<Station>, Error>{
match self.rest_client.post_capture((), &data)? {
StationResponse::Stations(stations) => Ok(stations),
_ => Err(Error::InvalidValue),
}
}
}
......@@ -11,6 +11,7 @@ mod state;
mod language;
mod tag;
mod stats;
mod search;
mod client;
pub use station::Station as Station;
......@@ -21,6 +22,7 @@ pub use state::State as State;
pub use language::Language as Language;
pub use tag::Tag as Tag;
pub use stats::Stats as Stats;
pub use search::StationSearch as StationSearch;
pub use client::Client as Client;
use station::StationResponse as StationResponse;
......
use restson::{RestClient,RestPath,Error};
#[derive(Serialize, Deserialize, Debug)]
pub struct StationSearch {
pub name: String,
pub name_exact: bool,
pub country: String,
pub country_excat: bool,
pub state: String,
pub state_exact: bool,
pub language: String,
pub language_exact: bool,
pub tag: String,
pub tag_exact: bool,
pub bitrate_min: u32,
pub bitrate_max: u32,
pub order: String,
pub reverse: bool,
pub offset: u32,
pub limit: u32,
}
impl StationSearch{
pub fn new() -> Self{
StationSearch {
name: "".to_string(),
name_exact: false,
country: "".to_string(),
country_excat: false,
state: "".to_string(),
state_exact: false,
language: "".to_string(),
language_exact: false,
tag: "".to_string(),
tag_exact: false,
bitrate_min: 0,
bitrate_max: 99000,
order: "".to_string(),
reverse: false,
offset: 0,
limit: 100,
}
}
pub fn search_for_name(name: String, exact: bool, limit: u32) -> Self{
let mut search = Self::new();
search.name = name;
search.name_exact = exact;
search.limit = limit;
search
}
}
impl RestPath<()> for StationSearch {
fn get_path(_: ()) -> Result<String,Error> {
Ok(String::from("webservice/json/stations/search"))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment