Implement StatsUserArtists

This commit is contained in:
Koen Bolhuis 2021-01-13 14:15:32 +01:00
parent 2bc3291a61
commit 6c0eff415e
3 changed files with 56 additions and 3 deletions

View File

@ -282,7 +282,30 @@ impl Client {
request.call()?.into_json().map_err(Error::ResponseJson)
}
// /// Endpoint: `stats/user/{user_name}/artists`
/// Endpoint: `stats/user/{user_name}/artists`
pub fn stats_user_artists(
&mut self,
user_name: &str,
count: Option<u64>,
offset: Option<u64>,
range: Option<&str>,
) -> Result<StatsUserArtistsResponse, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatsUserArtists(user_name));
let mut request = self.agent.get(&endpoint);
if let Some(count) = count {
request = request.query("count", &count.to_string());
}
if let Some(offset) = offset {
request = request.query("offset", &offset.to_string());
}
if let Some(range) = range {
request = request.query("range", range);
}
request.call()?.into_json().map_err(Error::ResponseJson)
}
/// Endpoint: `status/get-dump-info`
pub fn status_get_dump_info(

View File

@ -15,7 +15,7 @@ pub enum Endpoint<'a> {
StatsUserRecordings(&'a str),
StatsUserArtistMap(&'a str),
StatsUserReleases(&'a str),
// StatsUserArtists(&'a str),
StatsUserArtists(&'a str),
StatusGetDumpInfo,
}
@ -39,7 +39,7 @@ impl<'a> fmt::Display for Endpoint<'a> {
Self::StatsUserRecordings(user) => return write!(f, "stats/user/{}/recordings", user),
Self::StatsUserArtistMap(user) => return write!(f, "stats/user/{}/artist-map", user),
Self::StatsUserReleases(user) => return write!(f, "stats/user/{}/releases", user),
// Self::StatsUserArtists(user) => return write!(f, "stats/user/{}/artists", user),
Self::StatsUserArtists(user) => return write!(f, "stats/user/{}/artists", user),
Self::StatusGetDumpInfo => "status/get-dump-info",
};
write!(f, "{}", s)

View File

@ -368,6 +368,36 @@ pub struct StatsUserReleasesRelease {
pub release_name: String,
}
// --------- stats/user/{user_name}/artists
/// Response type of [`Client::stats_user_artists`](crate::Client::stats_user_artists).
#[derive(Debug, Deserialize)]
pub struct StatsUserArtistsResponse {
pub payload: StatsUserArtistsPayload,
}
/// Type of the [`StatsUserArtistsResponse::payload`] field.
#[derive(Debug, Deserialize)]
pub struct StatsUserArtistsPayload {
pub artists: Vec<StatsUserArtistsArtist>,
pub count: u64,
pub total_artist_count: u64,
pub user_id: String,
pub from_ts: i64,
pub to_ts: i64,
pub last_updated: i64,
pub range: String,
}
/// Type of the [`StatsUserArtistsPayload::artists`] field.
#[derive(Debug, Deserialize)]
pub struct StatsUserArtistsArtist {
pub artist_mbids: Option<Vec<String>>,
pub artist_msid: Option<String>,
pub artist_name: String,
pub listen_count: u64,
}
// --------- status/get-dump-info
/// Response type for [`Client::status_get_dump_info`](crate::Client::status_get_dump_info).