From 59491fc56f7840763d8309f6c0f539775072173a Mon Sep 17 00:00:00 2001 From: Koen Bolhuis Date: Wed, 13 Jan 2021 13:46:29 +0100 Subject: [PATCH] Implement StatsUserRecordings --- src/client.rs | 25 ++++++++++++++++++++++++- src/endpoint.rs | 4 ++-- src/models/response.rs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index 9837c4c..bcd01ba 100644 --- a/src/client.rs +++ b/src/client.rs @@ -211,7 +211,30 @@ impl Client { request.call()?.into_json().map_err(Error::ResponseJson) } - // /// Endpoint: `stats/user/{user_name}/recordings` + /// Endpoint: `stats/user/{user_name}/recordings` + pub fn stats_user_recordings( + &mut self, + user_name: &str, + count: Option, + offset: Option, + range: Option<&str>, + ) -> Result { + let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatsUserRecordings(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: `stats/user/{user_name}/artist-map` diff --git a/src/endpoint.rs b/src/endpoint.rs index e82110b..86c6531 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -12,7 +12,7 @@ pub enum Endpoint<'a> { StatsSitewideArtists, StatsUserListeningActivity(&'a str), StatsUserDailyActivity(&'a str), - // StatsUserRecordings(&'a str), + StatsUserRecordings(&'a str), // StatsUserArtistMap(&'a str), // StatsUserReleases(&'a str), // StatsUserArtists(&'a str), @@ -36,7 +36,7 @@ impl<'a> fmt::Display for Endpoint<'a> { Self::StatsSitewideArtists => "stats/sitewide/artists", 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::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), diff --git a/src/models/response.rs b/src/models/response.rs index 5149055..1d8a4aa 100644 --- a/src/models/response.rs +++ b/src/models/response.rs @@ -256,6 +256,7 @@ pub struct StatsUserDailyActivityPayload { pub daily_activity: StatsUserDailyActivityDailyActivity, pub from_ts: i64, pub to_ts: i64, + pub last_updated: i64, pub stats_range: String, } @@ -272,6 +273,42 @@ pub struct StatsUserDailyActivityHour { pub listen_count: u64, } +// --------- stats/user/{user_name}/recordings + +/// Response type of [`Client::stats_user_recordings`](crate::Client::stats_user_recordings). +#[derive(Debug, Deserialize)] +pub struct StatsUserRecordingsResponse { + pub payload: StatsUserRecordingsPayload, +} + +/// Type of the [`StatsUserRecordingsResponse::payload`] field. +#[derive(Debug, Deserialize)] +pub struct StatsUserRecordingsPayload { + pub recordings: Vec, + pub count: u64, + pub total_recording_count: u64, + pub user_id: String, + pub from_ts: i64, + pub to_ts: i64, + pub last_updated: i64, + pub range: String, +} + +/// Type of the [`StatsUserRecordingsPayload::recordings`] field. +#[derive(Debug, Deserialize)] +pub struct StatsUserRecordingsRecording { + pub artist_mbids: Option>, + pub artist_msid: Option, + pub artist_name: String, + pub listen_count: u64, + pub recording_mbid: Option, + pub recording_msid: Option, + pub release_mbid: Option, + pub release_msid: Option, + pub release_name: Option, + pub track_name: Option, +} + // --------- status/get-dump-info /// Response type for [`Client::status_get_dump_info`](crate::Client::status_get_dump_info).