From bd263af24433bc63270016a20dc4b2fc208561e4 Mon Sep 17 00:00:00 2001 From: Koen Bolhuis Date: Wed, 13 Jan 2021 14:02:23 +0100 Subject: [PATCH] Implement StatsUserArtistMap --- src/client.rs | 21 ++++++++++++++++++++- src/endpoint.rs | 4 ++-- src/models/response.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index bcd01ba..d02a346 100644 --- a/src/client.rs +++ b/src/client.rs @@ -236,7 +236,26 @@ impl Client { request.call()?.into_json().map_err(Error::ResponseJson) } - // /// Endpoint: `stats/user/{user_name}/artist-map` + /// Endpoint: `stats/user/{user_name}/artist-map` + pub fn stats_user_artist_map( + &mut self, + user_name: &str, + range: Option<&str>, + force_recalculate: Option, + ) -> Result { + let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatsUserArtistMap(user_name)); + + let mut request = self.agent.get(&endpoint); + + if let Some(range) = range { + request = request.query("range", range); + } + if let Some(force_recalculate) = force_recalculate { + request = request.query("force_recalculate", &force_recalculate.to_string()); + } + + request.call()?.into_json().map_err(Error::ResponseJson) + } // /// Endpoint: `stats/user/{user_name}/releases` diff --git a/src/endpoint.rs b/src/endpoint.rs index 86c6531..2efdd5d 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -13,7 +13,7 @@ pub enum Endpoint<'a> { StatsUserListeningActivity(&'a str), StatsUserDailyActivity(&'a str), StatsUserRecordings(&'a str), - // StatsUserArtistMap(&'a str), + StatsUserArtistMap(&'a str), // StatsUserReleases(&'a str), // StatsUserArtists(&'a str), StatusGetDumpInfo, @@ -37,7 +37,7 @@ impl<'a> fmt::Display for Endpoint<'a> { Self::StatsUserListeningActivity(user) => return write!(f, "stats/user/{}/listening-activity", user), Self::StatsUserDailyActivity(user) => return write!(f, "stats/user/{}/daily-activity", user), Self::StatsUserRecordings(user) => return write!(f, "stats/user/{}/recordings", user), - // Self::StatsUserArtistMap(user) => return write!(f, "stats/user/{}/artist-map", 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::StatusGetDumpInfo => "status/get-dump-info", diff --git a/src/models/response.rs b/src/models/response.rs index 1d8a4aa..734f8eb 100644 --- a/src/models/response.rs +++ b/src/models/response.rs @@ -309,6 +309,32 @@ pub struct StatsUserRecordingsRecording { pub track_name: Option, } +// --------- stats/user/{user_name}/artist-map + +/// Response type of [`Client::stats_user_artist_map`](crate::Client::stats_user_artist_map). +#[derive(Debug, Deserialize)] +pub struct StatsUserArtistMapResponse { + pub payload: StatsUserArtistMapPayload, +} + +/// Type of the [`StatsUserArtistMapResponse::payload`] field. +#[derive(Debug, Deserialize)] +pub struct StatsUserArtistMapPayload { + pub artist_map: Vec, + pub user_id: String, + pub from_ts: i64, + pub to_ts: i64, + pub last_updated: i64, + pub range: String, +} + +/// Type of the [`StatsUserArtistMapPayload::artist_map`] field. +#[derive(Debug, Deserialize)] +pub struct StatsUserArtistMapCountry { + pub country: String, + pub artist_count: u64, +} + // --------- status/get-dump-info /// Response type for [`Client::status_get_dump_info`](crate::Client::status_get_dump_info).