run rustfmt

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