Skip to content

Commit

Permalink
Merge pull request #24 from RustyNova016/updates/UserListens-nodocs
Browse files Browse the repository at this point in the history
Update to the UserListensResponse models to add MBID mapping (No Doc)
  • Loading branch information
InputUsername authored Apr 2, 2024
2 parents 77e01fe + bcb8469 commit 0ca6c9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/user_listens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
let result = client.user_playing_now(&user_name);
println!("Playing now: {:#?}", result);

let result = client.user_listens(&user_name, None, None, Some(5), None);
let result = client.user_listens(&user_name, None, None, Some(5));
println!("Recent listens: {:#?}", result);
}
6 changes: 1 addition & 5 deletions src/raw/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,13 @@ impl Client {
self.get(Endpoint::UserPlayingNow(user_name))
}

/// Endpoint: [`user/{user_name}/listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listens)
/// Endpoint: [`user/{user_name}/listens`](https://listenbrainz.readthedocs.io/en/latest/users/api/core.html#get--1-user-(user_name)-listens)
pub fn user_listens(
&self,
user_name: &str,
min_ts: Option<i64>,
max_ts: Option<i64>,
count: Option<u64>,
time_range: Option<u64>,
) -> Result<UserListensResponse, Error> {
let endpoint = format!("{}{}", self.api_root_url, Endpoint::UserListens(user_name));

Expand All @@ -163,9 +162,6 @@ impl Client {
if let Some(count) = count {
request = request.param("count", count);
}
if let Some(time_range) = time_range {
request = request.param("time_range", time_range);
}

let response = request.send()?;

Expand Down
19 changes: 19 additions & 0 deletions src/raw/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ response_type! {
pub struct UserListensPayload {
pub count: u64,
pub latest_listen_ts: i64,
pub oldest_listen_ts: i64,
pub user_id: String,
pub listens: Vec<UserListensListen>,
}
Expand All @@ -228,6 +229,24 @@ pub struct UserListensTrackMetadata {
pub track_name: String,
pub release_name: Option<String>,
pub additional_info: HashMap<String, serde_json::Value>,
pub mbid_mapping: Option<UserListensMBIDMapping>,
}

/// Type of the [`UserListensTrackMetadata::mbid_mapping`] field.
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct UserListensMBIDMapping {
pub artist_mbids: Option<Vec<String>>,
pub artists: Option<Vec<UserListensMappingArtist>>,
pub recording_mbid: String,
pub recording_name: Option<String>,
}

/// Type of the [`UserListensMBIDMapping::artists`] field.
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct UserListensMappingArtist {
pub artist_mbid: String,
pub artist_credit_name: String,
pub join_phrase: String,
}

// --------- latest-import (GET)
Expand Down

0 comments on commit 0ca6c9f

Please sign in to comment.