run rustfmt

parent ee288994
use restson::{RestClient, Error};
use restson::{Error, RestClient};
use {Codec, Country, Language, State, Station, Stats, Tag};
use {CodecResponse, CountryResponse, LanguageResponse, StateResponse, StationResponse, TagResponse};
use {PlayableStationUrl, StationSearch};
pub struct Client {
rest_client: RestClient,
}
impl Client {
pub fn new(base_url: &str) -> Client {
let rest_client = match RestClient::new(base_url){
let rest_client = match RestClient::new(base_url) {
Ok(rc) => rc,
Err(_) => panic!("Could not create rest_client!")
Err(_) => panic!("Could not create rest_client!"),
};
Client { rest_client }
}
pub fn get_station_by_id(&mut self, id: u32) -> Result<Option<Station>, Error>{
pub fn get_station_by_id(&mut self, id: u32) -> Result<Option<Station>, Error> {
match self.rest_client.get(id)? {
StationResponse::Station(station) => Ok(Some(station)),
StationResponse::Stations(mut stations) => Ok(stations.pop()),
}
}
pub fn get_all_stations(&mut self) -> Result<Vec<Station>, Error>{
pub fn get_all_stations(&mut self) -> Result<Vec<Station>, Error> {
match self.rest_client.get(())? {
StationResponse::Stations(stations) => Ok(stations),
_ => Err(Error::InvalidValue),
}
}
pub fn get_all_codecs(&mut self) -> Result<Vec<Codec>, Error>{
pub fn get_all_codecs(&mut self) -> Result<Vec<Codec>, Error> {
match self.rest_client.get(())? {
CodecResponse::Codecs(codecs) => Ok(codecs),
_ => Err(Error::InvalidValue),
}
}
pub fn get_all_countries(&mut self) -> Result<Vec<Country>, Error>{
pub fn get_all_countries(&mut self) -> Result<Vec<Country>, Error> {
match self.rest_client.get(())? {
CountryResponse::Countries(countries) => Ok(countries),
_ => Err(Error::InvalidValue),
}
}
pub fn get_all_languages(&mut self) -> Result<Vec<Language>, Error>{
pub fn get_all_languages(&mut self) -> Result<Vec<Language>, Error> {
match self.rest_client.get(())? {
LanguageResponse::Languages(languages) => Ok(languages),
_ => Err(Error::InvalidValue),
}
}
pub fn get_all_states(&mut self) -> Result<Vec<State>, Error>{
pub fn get_all_states(&mut self) -> Result<Vec<State>, Error> {
match self.rest_client.get(())? {
StateResponse::States(states) => Ok(states),
_ => Err(Error::InvalidValue),
}
}
pub fn get_all_tags(&mut self) -> Result<Vec<Tag>, Error>{
pub fn get_all_tags(&mut self) -> Result<Vec<Tag>, Error> {
match self.rest_client.get(())? {
TagResponse::Tags(tags) => Ok(tags),
_ => Err(Error::InvalidValue),
}
}
pub fn get_stats(&mut self) -> Result<Stats, Error>{
pub fn get_stats(&mut self) -> Result<Stats, Error> {
self.rest_client.get(())
}
pub fn get_playable_station_url(&mut self, station: Station) -> Result<String, Error>{
pub fn get_playable_station_url(&mut self, station: Station) -> Result<String, Error> {
let result: PlayableStationUrl = self.rest_client.get(station)?;
Ok(result.url)
}
pub fn search(&mut self, data: StationSearch) -> Result<Vec<Station>, Error>{
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),
......
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Codec {
......@@ -14,7 +14,7 @@ pub enum CodecResponse {
}
impl RestPath<()> for CodecResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/codecs"))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Country {
......@@ -14,7 +14,7 @@ pub enum CountryResponse {
}
impl RestPath<()> for CountryResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/countries"))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Language {
......@@ -14,7 +14,7 @@ pub enum LanguageResponse {
}
impl RestPath<()> for LanguageResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/languages"))
}
}
#[macro_use] extern crate serde_derive;
#[macro_use]
extern crate serde_derive;
extern crate log;
extern crate serde;
extern crate restson;
extern crate serde;
mod station;
mod country;
mod client;
mod codec;
mod state;
mod country;
mod language;
mod tag;
mod stats;
mod search;
mod client;
mod state;
mod station;
mod stats;
mod tag;
pub use station::Station as Station;
use station::PlayableStationUrl as PlayableStationUrl;
pub use country::Country as Country;
pub use codec::Codec as Codec;
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;
pub use client::Client;
pub use codec::Codec;
pub use country::Country;
pub use language::Language;
pub use search::StationSearch;
pub use state::State;
use station::PlayableStationUrl;
pub use station::Station;
pub use stats::Stats;
pub use tag::Tag;
use station::StationResponse as StationResponse;
use country::CountryResponse as CountryResponse;
use codec::CodecResponse as CodecResponse;
use state::StateResponse as StateResponse;
use language::LanguageResponse as LanguageResponse;
use tag::TagResponse as TagResponse;
use codec::CodecResponse;
use country::CountryResponse;
use language::LanguageResponse;
use state::StateResponse;
use station::StationResponse;
use tag::TagResponse;
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct StationSearch {
......@@ -20,8 +20,8 @@ pub struct StationSearch {
pub limit: u32,
}
impl StationSearch{
pub fn new() -> Self{
impl StationSearch {
pub fn new() -> Self {
StationSearch {
name: "".to_string(),
name_exact: false,
......@@ -42,7 +42,7 @@ impl StationSearch{
}
}
pub fn search_for_name(name: String, exact: bool, limit: u32) -> Self{
pub fn search_for_name(name: String, exact: bool, limit: u32) -> Self {
let mut search = Self::new();
search.name = name;
search.name_exact = exact;
......@@ -52,7 +52,7 @@ impl StationSearch{
}
impl RestPath<()> for StationSearch {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(String::from("webservice/json/stations/search"))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct State {
......@@ -15,7 +15,7 @@ pub enum StateResponse {
}
impl RestPath<()> for StateResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/states"))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone, Eq, Hash)]
pub struct Station {
......@@ -44,18 +44,17 @@ pub enum StationResponse {
}
impl RestPath<()> for StationResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/stations"))
}
}
impl RestPath<u32> for StationResponse {
fn get_path(param: u32) -> Result<String,Error> {
fn get_path(param: u32) -> Result<String, Error> {
Ok(format!("webservice/json/stations/byid/{}", param))
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct PlayableStationUrl {
pub name: String,
......@@ -63,7 +62,7 @@ pub struct PlayableStationUrl {
}
impl RestPath<Station> for PlayableStationUrl {
fn get_path(param: Station) -> Result<String,Error> {
fn get_path(param: Station) -> Result<String, Error> {
Ok(format!("webservice/v2/json/url/{}", param.id))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Stats {
......@@ -12,7 +12,7 @@ pub struct Stats {
}
impl RestPath<()> for Stats {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/stats"))
}
}
use restson::{RestPath,Error};
use restson::{Error, RestPath};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Tag {
......@@ -14,7 +14,7 @@ pub enum TagResponse {
}
impl RestPath<()> for TagResponse {
fn get_path(_: ()) -> Result<String,Error> {
fn get_path(_: ()) -> Result<String, Error> {
Ok(format!("webservice/json/tags"))
}
}
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