use query::Query;
use {Album, Artist, Client, Error, Result, Song};
pub trait Annotatable {
fn star(&self, client: &Client) -> Result<()>;
fn unstar(&self, client: &Client) -> Result<()>;
fn set_rating(&self, client: &Client, rating: u8) -> Result<()>;
fn scrobble<'a, B, T>(&self, client: &Client, time: T, now_playing: B) -> Result<()>
where
B: Into<Option<bool>>,
T: Into<Option<&'a str>>;
}
impl Annotatable for Artist {
fn star(&self, client: &Client) -> Result<()> {
client.get("star", Query::with("artistId", self.id))?;
Ok(())
}
fn unstar(&self, client: &Client) -> Result<()> {
client.get("unstar", Query::with("artistId", self.id))?;
Ok(())
}
fn set_rating(&self, client: &Client, rating: u8) -> Result<()> {
if rating > 5 {
return Err(Error::Other("rating must be between 0 and 5 inclusive"));
}
let args = Query::with("id", self.id).arg("rating", rating).build();
client.get("setRating", args)?;
Ok(())
}
fn scrobble<'a, B, T>(&self, client: &Client, time: T, now_playing: B) -> Result<()>
where
B: Into<Option<bool>>,
T: Into<Option<&'a str>>,
{
let args = Query::with("id", self.id)
.arg("time", time.into())
.arg("submission", now_playing.into().map(|b| !b))
.build();
client.get("scrobble", args)?;
Ok(())
}
}
impl Annotatable for Album {
fn star(&self, client: &Client) -> Result<()> {
client.get("star", Query::with("albumId", self.id))?;
Ok(())
}
fn unstar(&self, client: &Client) -> Result<()> {
client.get("unstar", Query::with("albumId", self.id))?;
Ok(())
}
fn set_rating(&self, client: &Client, rating: u8) -> Result<()> {
if rating > 5 {
return Err(Error::Other("rating must be between 0 and 5 inclusive"));
}
let args = Query::with("id", self.id).arg("rating", rating).build();
client.get("setRating", args)?;
Ok(())
}
fn scrobble<'a, B, T>(&self, client: &Client, time: T, now_playing: B) -> Result<()>
where
B: Into<Option<bool>>,
T: Into<Option<&'a str>>,
{
let args = Query::with("id", self.id)
.arg("time", time.into())
.arg("submission", now_playing.into().map(|b| !b))
.build();
client.get("scrobble", args)?;
Ok(())
}
}
impl Annotatable for Song {
fn star(&self, client: &Client) -> Result<()> {
client.get("star", Query::with("id", self.id))?;
Ok(())
}
fn unstar(&self, client: &Client) -> Result<()> {
client.get("unstar", Query::with("id", self.id))?;
Ok(())
}
fn set_rating(&self, client: &Client, rating: u8) -> Result<()> {
if rating > 5 {
return Err(Error::Other("rating must be between 0 and 5 inclusive"));
}
let args = Query::with("id", self.id).arg("rating", rating).build();
client.get("setRating", args)?;
Ok(())
}
fn scrobble<'a, B, T>(&self, client: &Client, time: T, now_playing: B) -> Result<()>
where
B: Into<Option<bool>>,
T: Into<Option<&'a str>>,
{
let args = Query::with("id", self.id)
.arg("time", time.into())
.arg("submission", now_playing.into().map(|b| !b))
.build();
client.get("scrobble", args)?;
Ok(())
}
}