Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the UserListensResponse models to add MBID mapping (No Doc) #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
shymega marked this conversation as resolved.
Show resolved Hide resolved
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);
}

shymega marked this conversation as resolved.
Show resolved Hide resolved
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,
shymega marked this conversation as resolved.
Show resolved Hide resolved
}

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