Implement StatsSitewideArtists endpoint
This commit is contained in:
parent
727ba956b7
commit
22b04846b2
|
@ -9,7 +9,7 @@ pub enum Endpoint<'a> {
|
|||
UserPlayingNow(&'a str),
|
||||
UserListens(&'a str),
|
||||
LatestImport,
|
||||
// StatsSitewideArtists,
|
||||
StatsSitewideArtists,
|
||||
// StatsUserListeningActivity(&'a str),
|
||||
// StatsUserDailyActivity(&'a str),
|
||||
// StatsUserRecordings(&'a str),
|
||||
|
@ -33,7 +33,7 @@ impl<'a> fmt::Display for Endpoint<'a> {
|
|||
Self::UserPlayingNow(user) => return write!(f, "user/{}/playing-now", user),
|
||||
Self::UserListens(user) => return write!(f, "user/{}/listens", user),
|
||||
Self::LatestImport => "latest-import",
|
||||
// Self::StatsSitewideArtists => "stats/sitewide/artists",
|
||||
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),
|
||||
|
|
43
src/lib.rs
43
src/lib.rs
|
@ -102,7 +102,6 @@ impl Client {
|
|||
self.get(Endpoint::UserListenCount(user_name))
|
||||
}
|
||||
|
||||
// UserPlayingNow(&'a str),
|
||||
/// Endpoint: `user/{user_name}/playing-now`
|
||||
pub fn user_playing_now(&mut self, user_name: &str) -> Result<UserPlayingNowResponse, Error> {
|
||||
self.get(Endpoint::UserPlayingNow(user_name))
|
||||
|
@ -157,13 +156,41 @@ impl Client {
|
|||
self.post(Endpoint::LatestImport, token, data)
|
||||
}
|
||||
|
||||
// StatsSitewideArtists,
|
||||
// StatsUserListeningActivity(&'a str),
|
||||
// StatsUserDailyActivity(&'a str),
|
||||
// StatsUserRecordings(&'a str),
|
||||
// StatsUserArtistMap(&'a str),
|
||||
// StatsUserReleases(&'a str),
|
||||
// StatsUserArtists(&'a str),
|
||||
/// Endpoint: `stats/sitewide/artists`
|
||||
pub fn stats_sitewide_artists(
|
||||
&mut self,
|
||||
count: Option<u64>,
|
||||
offset: Option<u64>,
|
||||
range: Option<&str>
|
||||
) -> Result<StatsSitewideArtistsResponse, Error> {
|
||||
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatsSitewideArtists);
|
||||
|
||||
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}/listening-activity`
|
||||
|
||||
// /// Endpoint: `stats/user/{user_name}/daily-activity`
|
||||
|
||||
// /// Endpoint: `stats/user/{user_name}/recordings`
|
||||
|
||||
// /// Endpoint: `stats/user/{user_name}/artist-map`
|
||||
|
||||
// /// Endpoint: `stats/user/{user_name}/releases`
|
||||
|
||||
// /// Endpoint: `stats/user/{user_name}/artists`
|
||||
|
||||
/// Endpoint: `status/get-dump-info`
|
||||
pub fn status_get_dump_info(
|
||||
|
|
|
@ -176,6 +176,44 @@ pub struct UpdateLatestImportResponse {
|
|||
pub status: String,
|
||||
}
|
||||
|
||||
// --------- stats/sitewide/artists
|
||||
|
||||
/// Response type for [`Client::stats_sitewide_artists`](crate::Client::stats_sitewide_artists).
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StatsSitewideArtistsResponse {
|
||||
pub payload: StatsSitewideArtistsPayload,
|
||||
}
|
||||
|
||||
/// Type of the [`StatsSitewideArtistsResponse::payload`] field.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StatsSitewideArtistsPayload {
|
||||
pub time_ranges: Vec<StatsSitewideArtistsTimeRange>,
|
||||
pub offset: u64,
|
||||
pub count: u64,
|
||||
pub range: String,
|
||||
pub last_updated: i64,
|
||||
pub from_ts: i64,
|
||||
pub to_ts: i64,
|
||||
}
|
||||
|
||||
/// Type of the [`StatsSitewideArtistsPayload::time_ranges`] field.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StatsSitewideArtistsTimeRange {
|
||||
pub time_range: String,
|
||||
pub artists: Vec<StatsSitewideArtistsArtist>,
|
||||
pub from_ts: i64,
|
||||
pub to_ts: i64,
|
||||
}
|
||||
|
||||
/// Type of the [`StatsSitewideArtistsTimeRange::artists`] field.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StatsSitewideArtistsArtist {
|
||||
pub artist_mbids: Option<Vec<String>>,
|
||||
pub artist_msid: 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).
|
||||
|
|
Loading…
Reference in New Issue