From e4c2a0fcf4062ed9b7e75c752f3399c0da158b9f Mon Sep 17 00:00:00 2001 From: fckoppenol Date: Fri, 8 Apr 2016 10:09:26 +0100 Subject: [PATCH] Added ArtistApi.GetSimilarByMbidAsync --- src/IF.Lastfm.Core/Api/ArtistApi.cs | 15 +++++++++++- .../Api/Commands/Artist/GetSimilarCommand.cs | 23 +++++++++++++------ src/IF.Lastfm.Core/Api/IArtistApi.cs | 2 ++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/IF.Lastfm.Core/Api/ArtistApi.cs b/src/IF.Lastfm.Core/Api/ArtistApi.cs index 0f6b774..e0683e7 100644 --- a/src/IF.Lastfm.Core/Api/ArtistApi.cs +++ b/src/IF.Lastfm.Core/Api/ArtistApi.cs @@ -67,8 +67,21 @@ public async Task> GetTopTracksAsync(string artist, bool public async Task> GetSimilarAsync(string artistname, bool autocorrect = false, int limit = LastFm.DefaultPageLength) { - var command = new GetSimilarCommand(Auth, artistname) + var command = new GetSimilarCommand(Auth) { + ArtistName = artistname, + Autocorrect = autocorrect, + Limit = limit, + HttpClient = HttpClient + }; + return await command.ExecuteAsync(); + } + + public async Task> GetSimilarByMbidAsync(string mbid, bool autocorrect = false, int limit = LastFm.DefaultPageLength) + { + var command = new GetSimilarCommand(Auth) + { + ArtistMbid = mbid, Autocorrect = autocorrect, Limit = limit, HttpClient = HttpClient diff --git a/src/IF.Lastfm.Core/Api/Commands/Artist/GetSimilarCommand.cs b/src/IF.Lastfm.Core/Api/Commands/Artist/GetSimilarCommand.cs index 2366b94..e9f9b02 100644 --- a/src/IF.Lastfm.Core/Api/Commands/Artist/GetSimilarCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/Artist/GetSimilarCommand.cs @@ -14,19 +14,28 @@ internal class GetSimilarCommand : GetAsyncCommandBase> { public bool Autocorrect { get; set; } + public string ArtistMbid { get; set; } + public string ArtistName { get; set; } public int? Limit { get; set; } - public GetSimilarCommand(ILastAuth auth, string artistName) - : base(auth) - { - ArtistName = artistName; - } + public GetSimilarCommand(ILastAuth auth) + : base(auth){} + public override void SetParameters() { - Parameters.Add("artist", ArtistName); + + if (ArtistMbid != null) + { + Parameters.Add("mbid", ArtistMbid); + } + else + { + Parameters.Add("artist", ArtistName); + } + Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString()); if (Limit != null) @@ -37,7 +46,7 @@ public override void SetParameters() DisableCaching(); } - public async override Task> HandleResponse(HttpResponseMessage response) + public override async Task> HandleResponse(HttpResponseMessage response) { var json = await response.Content.ReadAsStringAsync(); diff --git a/src/IF.Lastfm.Core/Api/IArtistApi.cs b/src/IF.Lastfm.Core/Api/IArtistApi.cs index 447fe90..2455ce5 100644 --- a/src/IF.Lastfm.Core/Api/IArtistApi.cs +++ b/src/IF.Lastfm.Core/Api/IArtistApi.cs @@ -20,6 +20,8 @@ Task> GetInfoByMbidAsync(string mbid, string bioLang = Task> GetSimilarAsync(string artistname, bool autocorrect = false, int limit = 100); + Task> GetSimilarByMbidAsync(string mbid, bool autocorrect = false, int limit = 100); + Task> GetTopAlbumsAsync(string artist, bool autocorrect = false, int page = 1,