Skip to content

Commit

Permalink
Added MBID Mapping information to the user listens endpoint and removed
Browse files Browse the repository at this point in the history
unused timerange parameter
  • Loading branch information
RustyNova016 committed Mar 8, 2024
1 parent 853817f commit 6b35a7c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
Cargo.lock
Cargo.lock
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 6b35a7c

Please sign in to comment.