Skip to content

Commit

Permalink
Merge branch 'fckoppenol-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkit committed May 26, 2016
2 parents 74f9978 + 68e36f0 commit b285c27
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ArtistGetTopTagsCommandTests : CommandTestsBase
[SetUp]
public void Initialise()
{
_command = new GetTopTagsCommand(MAuth.Object, "");
_command = new GetTopTagsCommand(MAuth.Object);
}

[Test]
Expand Down
16 changes: 15 additions & 1 deletion src/IF.Lastfm.Core/Api/ArtistApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,29 @@ public Task<PageResponse<LastTag>> GetTagsByUserAsync(string artist, string user

public Task<PageResponse<LastTag>> GetTopTagsAsync(string artist, bool autocorrect = false)
{
var command = new GetTopTagsCommand(Auth, artist)
var command = new GetTopTagsCommand(Auth)
{
ArtistName = artist,
Autocorrect = autocorrect,
HttpClient = HttpClient
};

return command.ExecuteAsync();
}

public Task<PageResponse<LastTag>> GetTopTagsByMbidAsync(string mbid, bool autocorrect = false)
{
var command = new GetTopTagsCommand(Auth)
{
ArtistMbid = mbid,
Autocorrect = autocorrect,
HttpClient = HttpClient
};

return command.ExecuteAsync();
}


public async Task<PageResponse<LastShout>> GetShoutsAsync(string artist, int page = 0, int count = LastFm.DefaultPageLength, bool autocorrect = false)
{
var command = new GetShoutsCommand(Auth, artist)
Expand Down
32 changes: 27 additions & 5 deletions src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,40 @@ namespace IF.Lastfm.Core.Api.Commands.Artist
[ApiMethodName("artist.getTopTags")]
internal class GetTopTagsCommand : GetAsyncCommandBase<PageResponse<LastTag>>
{
public string ArtistMbid { get; set; }

public string ArtistName { get; set; }

public bool Autocorrect { get; set; }

public GetTopTagsCommand(ILastAuth auth, string artistName) : base(auth)
public GetTopTagsCommand(ILastAuth auth) : base(auth)
{
ArtistName = artistName;
}

public override void SetParameters()
{
Parameters.Add("artist", ArtistName);
var hasMbid = !string.IsNullOrEmpty(ArtistMbid);
var hasName = !string.IsNullOrEmpty(ArtistName);

if (!hasMbid && !hasName)
{
throw new InvalidOperationException($"Either {nameof(ArtistMbid)} or {nameof(ArtistName)} must be set");
}

if (hasMbid && hasName)
{
throw new InvalidOperationException($"");
}

if (hasMbid)
{
Parameters.Add("mbid", ArtistMbid);
}
else
{
Parameters.Add("artist", ArtistName);
}

Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString());
}

Expand All @@ -38,7 +60,7 @@ public override async Task<PageResponse<LastTag>> HandleResponse(HttpResponseMes
var resultsToken = jtoken.SelectToken("toptags");
var itemsToken = resultsToken.SelectToken("tag");

return PageResponse<LastTag>.CreateSuccessResponse(itemsToken, token => LastTag.ParseJToken(token));
return PageResponse<LastTag>.CreateSuccessResponse(itemsToken, LastTag.ParseJToken);
}
else
{
Expand Down

0 comments on commit b285c27

Please sign in to comment.