Implement StatsUserReleases

This commit is contained in:
Koen Bolhuis 2021-01-13 14:09:34 +01:00
parent bd263af244
commit 2bc3291a61
3 changed files with 59 additions and 3 deletions

View File

@ -257,7 +257,30 @@ impl Client {
request.call()?.into_json().map_err(Error::ResponseJson)
}
// /// Endpoint: `stats/user/{user_name}/releases`
/// Endpoint: `stats/user/{user_name}/releases`
pub fn stats_user_releases(
&mut self,
user_name: &str,
count: Option<u64>,
offset: Option<u64>,
range: Option<&str>,
) -> Result<StatsUserReleasesResponse, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatsUserReleases(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}/artists`

View File

@ -14,7 +14,7 @@ pub enum Endpoint<'a> {
StatsUserDailyActivity(&'a str),
StatsUserRecordings(&'a str),
StatsUserArtistMap(&'a str),
// StatsUserReleases(&'a str),
StatsUserReleases(&'a str),
// StatsUserArtists(&'a str),
StatusGetDumpInfo,
}
@ -38,7 +38,7 @@ impl<'a> fmt::Display for Endpoint<'a> {
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::StatsUserReleases(user) => return write!(f, "stats/user/{}/releases", 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",
};

View File

@ -335,6 +335,39 @@ pub struct StatsUserArtistMapCountry {
pub artist_count: u64,
}
// --------- stats/user/{user_name}/releases
/// Response type for [`Client::stats_user_releases`](crate::Client::stats_user_releases).
#[derive(Debug, Deserialize)]
pub struct StatsUserReleasesResponse {
pub payload: StatsUserReleasesPayload,
}
/// Type of the [`StatsUserReleasesResponse::payload`] field.
#[derive(Debug, Deserialize)]
pub struct StatsUserReleasesPayload {
pub releases: Vec<StatsUserReleasesRelease>,
pub count: u64,
pub total_release_count: u64,
pub user_id: String,
pub from_ts: i64,
pub to_ts: i64,
pub last_updated: i64,
pub range: String,
}
/// Type of the [`StatsUserReleasesPayload::releases`] field.
#[derive(Debug, Deserialize)]
pub struct StatsUserReleasesRelease {
pub artist_mbids: Option<Vec<String>>,
pub artist_msid: Option<String>,
pub artist_name: String,
pub listen_count: u64,
pub release_mbid: Option<String>,
pub release_msid: Option<String>,
pub release_name: String,
}
// --------- status/get-dump-info
/// Response type for [`Client::status_get_dump_info`](crate::Client::status_get_dump_info).