From 64c20b271fa55b07ce7d01b2db66607ad94f4325 Mon Sep 17 00:00:00 2001 From: Tim Van Holder Date: Fri, 22 Dec 2023 15:41:56 +0100 Subject: [PATCH 1/2] Drop `GetRecentListens[Async]` The corresponding endpoint no longer exists in the ListenBrainz API. --- MetaBrainz.ListenBrainz/ListenBrainz.cs | 103 ------------------ .../MetaBrainz.ListenBrainz.net6.0.cs.md | 20 ---- .../MetaBrainz.ListenBrainz.net8.0.cs.md | 20 ---- 3 files changed, 143 deletions(-) diff --git a/MetaBrainz.ListenBrainz/ListenBrainz.cs b/MetaBrainz.ListenBrainz/ListenBrainz.cs index 0ef7bdd..da506cc 100644 --- a/MetaBrainz.ListenBrainz/ListenBrainz.cs +++ b/MetaBrainz.ListenBrainz/ListenBrainz.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -1441,108 +1440,6 @@ public Task GetPlayingNowAsync(string user, CancellationToken cance #endregion - #region /1/users/xxx/recent-listens - - private static string FormatUserList(IEnumerable userList) => string.Join(",", userList.Select(Uri.EscapeDataString)); - - private static Dictionary OptionsForRecentListens(int limit) - => new() { ["limit"] = limit.ToString(CultureInfo.InvariantCulture) }; - - /// Gets recent listen(s) for a set of users. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public IRecentListens GetRecentListens(IEnumerable users) => AsyncUtils.ResultOf(this.GetRecentListensAsync(users)); - - /// Gets recent listen(s) for a set of users. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public IRecentListens GetRecentListens(params string[] users) => AsyncUtils.ResultOf(this.GetRecentListensAsync(users)); - - /// Gets recent listen(s) for a set of users. - /// The maximum number of listens to return. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public IRecentListens GetRecentListens(int limit, IEnumerable users) - => AsyncUtils.ResultOf(this.GetRecentListensAsync(limit, users)); - - /// Gets recent listen(s) for a set of users. - /// The maximum number of listens to return. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public IRecentListens GetRecentListens(int limit, params string[] users) - => AsyncUtils.ResultOf(this.GetRecentListensAsync(limit, users)); - - /// Gets recent listen(s) for a set of users. - /// The cancellation token to cancel the operation. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(CancellationToken cancellationToken, params string[] users) - => this.GetRecentListensAsync(users, cancellationToken); - - /// Gets recent listen(s) for a set of users. - /// The cancellation token to cancel the operation. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(IEnumerable users, CancellationToken cancellationToken = default) { - var address = $"users/{ListenBrainz.FormatUserList(users)}/recent-listens"; - return this.GetAsync(address, null, cancellationToken); - } - - /// Gets recent listen(s) for a set of users. - /// The maximum number of listens to return. - /// The cancellation token to cancel the operation. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(int limit, CancellationToken cancellationToken, params string[] users) - => this.GetRecentListensAsync(limit, users, cancellationToken); - - /// Gets recent listen(s) for a set of users. - /// The maximum number of listens to return. - /// The MusicBrainz IDs of the users whose data is needed. - /// The cancellation token to cancel the operation. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(int limit, IEnumerable users, - CancellationToken cancellationToken = default) { - var requestUri = $"users/{ListenBrainz.FormatUserList(users)}/recent-listens"; - var options = ListenBrainz.OptionsForRecentListens(limit); - return this.GetAsync(requestUri, options, cancellationToken); - } - - /// Gets recent listen(s) for a set of users. - /// The maximum number of listens to return. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(int limit, params string[] users) - => this.GetRecentListensAsync(limit, (IEnumerable) users); - - /// Gets recent listen(s) for a set of users. - /// The MusicBrainz IDs of the users whose data is needed. - /// The requested listens. - /// When there was a problem sending the web service request. - /// When the web service sends a response indicating an error. - public Task GetRecentListensAsync(params string[] users) - => this.GetAsync($"users/{ListenBrainz.FormatUserList(users)}/recent-listens", null); - - #endregion - #region /1/validate-token private static Dictionary OptionsForTokenValidation(string token) => new() { ["token"] = token }; diff --git a/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md b/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md index 0fb290f..e972e5a 100644 --- a/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md +++ b/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md @@ -190,26 +190,6 @@ public sealed class ListenBrainz : System.IDisposable { public System.Threading.Tasks.Task GetPlayingNowAsync(string user, System.Threading.CancellationToken cancellationToken = default); - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(System.Collections.Generic.IEnumerable users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(int limit, System.Collections.Generic.IEnumerable users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(int limit, params string[] users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(System.Collections.Generic.IEnumerable users, System.Threading.CancellationToken cancellationToken = default); - - public System.Threading.Tasks.Task GetRecentListensAsync(System.Threading.CancellationToken cancellationToken, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, System.Collections.Generic.IEnumerable users, System.Threading.CancellationToken cancellationToken = default); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, System.Threading.CancellationToken cancellationToken, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(params string[] users); - public MetaBrainz.ListenBrainz.Interfaces.IUserRecordingStatistics? GetRecordingStatistics(string user, int? count = default, int? offset = default, StatisticsRange? range = default); public System.Threading.Tasks.Task GetRecordingStatisticsAsync(string user, int? count = default, int? offset = default, StatisticsRange? range = default, System.Threading.CancellationToken cancellationToken = default); diff --git a/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md b/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md index 410b0c9..582e39b 100644 --- a/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md +++ b/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md @@ -190,26 +190,6 @@ public sealed class ListenBrainz : System.IDisposable { public System.Threading.Tasks.Task GetPlayingNowAsync(string user, System.Threading.CancellationToken cancellationToken = default); - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(System.Collections.Generic.IEnumerable users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(int limit, System.Collections.Generic.IEnumerable users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(int limit, params string[] users); - - public MetaBrainz.ListenBrainz.Interfaces.IRecentListens GetRecentListens(params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(System.Collections.Generic.IEnumerable users, System.Threading.CancellationToken cancellationToken = default); - - public System.Threading.Tasks.Task GetRecentListensAsync(System.Threading.CancellationToken cancellationToken, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, System.Collections.Generic.IEnumerable users, System.Threading.CancellationToken cancellationToken = default); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, System.Threading.CancellationToken cancellationToken, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(int limit, params string[] users); - - public System.Threading.Tasks.Task GetRecentListensAsync(params string[] users); - public MetaBrainz.ListenBrainz.Interfaces.IUserRecordingStatistics? GetRecordingStatistics(string user, int? count = default, int? offset = default, StatisticsRange? range = default); public System.Threading.Tasks.Task GetRecordingStatisticsAsync(string user, int? count = default, int? offset = default, StatisticsRange? range = default, System.Threading.CancellationToken cancellationToken = default); From b53f223bf953fabad93eeb7a29e6df2fa721d063 Mon Sep 17 00:00:00 2001 From: Tim Van Holder Date: Fri, 22 Dec 2023 15:47:28 +0100 Subject: [PATCH 2/2] Drop the types associated with `GetRecentListens` This includes the `IRecentListens` interface, the `RecentListens` backing object, and the `RecentListensReader`. --- .../Interfaces/IRecentListens.cs | 19 ------- MetaBrainz.ListenBrainz/Json/Converters.cs | 1 - .../Json/Readers/RecentListensReader.cs | 54 ------------------- .../Objects/RecentListens.cs | 22 -------- .../MetaBrainz.ListenBrainz.net6.0.cs.md | 16 ------ .../MetaBrainz.ListenBrainz.net8.0.cs.md | 16 ------ 6 files changed, 128 deletions(-) delete mode 100644 MetaBrainz.ListenBrainz/Interfaces/IRecentListens.cs delete mode 100644 MetaBrainz.ListenBrainz/Json/Readers/RecentListensReader.cs delete mode 100644 MetaBrainz.ListenBrainz/Objects/RecentListens.cs diff --git a/MetaBrainz.ListenBrainz/Interfaces/IRecentListens.cs b/MetaBrainz.ListenBrainz/Interfaces/IRecentListens.cs deleted file mode 100644 index 6138813..0000000 --- a/MetaBrainz.ListenBrainz/Interfaces/IRecentListens.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; - -using JetBrains.Annotations; - -using MetaBrainz.Common.Json; - -namespace MetaBrainz.ListenBrainz.Interfaces; - -/// Information about recent listens for a set of users. -[PublicAPI] -public interface IRecentListens : IJsonBasedObject { - - /// The recent listens for the users listed in . - IReadOnlyList Listens { get; } - - /// A comma-separated list of the MusicBrainz IDs of the users for which the listens were fetched. - string UserList { get; } - -} diff --git a/MetaBrainz.ListenBrainz/Json/Converters.cs b/MetaBrainz.ListenBrainz/Json/Converters.cs index 2e84f2c..7749350 100644 --- a/MetaBrainz.ListenBrainz/Json/Converters.cs +++ b/MetaBrainz.ListenBrainz/Json/Converters.cs @@ -15,7 +15,6 @@ public static IEnumerable Readers { yield return LatestImportReader.Instance; yield return ListenCountReader.Instance; yield return PlayingNowReader.Instance; - yield return RecentListensReader.Instance; yield return SiteArtistStatisticsReader.Instance; yield return TokenValidationResultReader.Instance; yield return UserArtistMapReader.Instance; diff --git a/MetaBrainz.ListenBrainz/Json/Readers/RecentListensReader.cs b/MetaBrainz.ListenBrainz/Json/Readers/RecentListensReader.cs deleted file mode 100644 index c1beb2b..0000000 --- a/MetaBrainz.ListenBrainz/Json/Readers/RecentListensReader.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.Json; - -using MetaBrainz.Common.Json; -using MetaBrainz.ListenBrainz.Interfaces; -using MetaBrainz.ListenBrainz.Objects; - -namespace MetaBrainz.ListenBrainz.Json.Readers; - -internal sealed class RecentListensReader : PayloadReader { - - public static readonly RecentListensReader Instance = new(); - - protected override RecentListens ReadPayload(ref Utf8JsonReader reader, JsonSerializerOptions options) { - int? count = null; - IReadOnlyList? listens = null; - string? userList = null; - Dictionary? rest = null; - while (reader.TokenType == JsonTokenType.PropertyName) { - var prop = reader.GetPropertyName(); - try { - reader.Read(); - switch (prop) { - case "count": - count = reader.GetUInt16(); - break; - case "listens": - listens = reader.ReadList(ListenReader.Instance, options); - break; - case "user_list": - userList = reader.GetString(); - break; - default: - rest ??= new Dictionary(); - rest[prop] = reader.GetOptionalObject(options); - break; - } - } - catch (Exception e) { - throw new JsonException($"Failed to deserialize the '{prop}' property.", e); - } - reader.Read(); - } - listens = PayloadReader.VerifyPayloadContents(count, listens); - if (userList is null) { - throw new JsonException("Expected user list not found or null."); - } - return new RecentListens(listens, userList) { - UnhandledProperties = rest - }; - } - -} diff --git a/MetaBrainz.ListenBrainz/Objects/RecentListens.cs b/MetaBrainz.ListenBrainz/Objects/RecentListens.cs deleted file mode 100644 index 8939a10..0000000 --- a/MetaBrainz.ListenBrainz/Objects/RecentListens.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; - -using JetBrains.Annotations; - -using MetaBrainz.Common.Json; -using MetaBrainz.ListenBrainz.Interfaces; - -namespace MetaBrainz.ListenBrainz.Objects; - -[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] -internal sealed class RecentListens : JsonBasedObject, IRecentListens { - - public RecentListens(IReadOnlyList listens, string userList) { - this.Listens = listens; - this.UserList = userList; - } - - public IReadOnlyList Listens { get; } - - public string UserList { get; } - -} diff --git a/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md b/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md index e972e5a..565cedd 100644 --- a/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md +++ b/public-api/MetaBrainz.ListenBrainz.net6.0.cs.md @@ -677,22 +677,6 @@ public interface IPlayingTrack : MetaBrainz.Common.Json.IJsonBasedObject { } ``` -### Type: IRecentListens - -```cs -public interface IRecentListens : MetaBrainz.Common.Json.IJsonBasedObject { - - System.Collections.Generic.IReadOnlyList Listens { - public abstract get; - } - - string UserList { - public abstract get; - } - -} -``` - ### Type: IRecordingInfo ```cs diff --git a/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md b/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md index 582e39b..77aa874 100644 --- a/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md +++ b/public-api/MetaBrainz.ListenBrainz.net8.0.cs.md @@ -677,22 +677,6 @@ public interface IPlayingTrack : MetaBrainz.Common.Json.IJsonBasedObject { } ``` -### Type: IRecentListens - -```cs -public interface IRecentListens : MetaBrainz.Common.Json.IJsonBasedObject { - - System.Collections.Generic.IReadOnlyList Listens { - public abstract get; - } - - string UserList { - public abstract get; - } - -} -``` - ### Type: IRecordingInfo ```cs