From 6c0eff415eb03a305d8ac617cc4c22ad014e7d7a Mon Sep 17 00:00:00 2001 From: Koen Bolhuis Date: Wed, 13 Jan 2021 14:15:32 +0100 Subject: [PATCH] Implement StatsUserArtists --- src/client.rs | 25 ++++++++++++++++++++++++- src/endpoint.rs | 4 ++-- src/models/response.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index 3f8389f..8fe4f8e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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, + offset: Option, + range: Option<&str>, + ) -> Result { + 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( diff --git a/src/endpoint.rs b/src/endpoint.rs index 87ab9e5..c5bd4a4 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -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) diff --git a/src/models/response.rs b/src/models/response.rs index 2c91dea..45dead7 100644 --- a/src/models/response.rs +++ b/src/models/response.rs @@ -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, + 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>, + pub artist_msid: Option, + 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).