Added album.getTopTags API method to get top tags

This commit is contained in:
Prashant Khandelwal 2014-12-04 20:10:07 +05:30
parent ba85890c53
commit 6899cf86ee
3 changed files with 84 additions and 2 deletions

View File

@ -46,9 +46,15 @@ public Task<PageResponse<LastTag>> GetUserTagsForAlbumAsync(string artist, strin
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<PageResponse<LastTag>> GetTopTagsForAlbumAsync(string artist, string album, bool autocorrect = false) public async Task<PageResponse<LastTag>> GetTopTagsForAlbumAsync(string artist, string album, bool autocorrect = false)
{ {
throw new NotImplementedException(); var command = new AlbumTopTagsCommand(Auth)
{
ArtistName = artist,
AlbumName = album
};
return await command.ExecuteAsync();
} }
public async Task<PageResponse<LastAlbum>> SearchForAlbumAsync(string albumname, int page = 1, int itemsPerPage = LastFm.DefaultPageLength) public async Task<PageResponse<LastAlbum>> SearchForAlbumAsync(string albumname, int page = 1, int itemsPerPage = LastFm.DefaultPageLength)

View File

@ -0,0 +1,75 @@
using IF.Lastfm.Core.Api.Enums;
using IF.Lastfm.Core.Api.Helpers;
using IF.Lastfm.Core.Objects;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace IF.Lastfm.Core.Api.Commands.AlbumApi
{
internal class AlbumTopTagsCommand : GetAsyncCommandBase<PageResponse<LastTag>>
{
public string AlbumMbid { get; set; }
public string ArtistName { get; set; }
public string AlbumName { get; set; }
public bool Autocorrect { get; set; }
public AlbumTopTagsCommand(ILastAuth auth)
: base(auth)
{
Method = "album.gettoptags";
}
public AlbumTopTagsCommand(ILastAuth auth, string album, string artist)
: this(auth)
{
AlbumName = album;
ArtistName = artist;
}
public override void SetParameters()
{
if (AlbumMbid != null)
{
Parameters.Add("mbid", AlbumMbid);
}
else
{
Parameters.Add("artist", ArtistName);
Parameters.Add("album", AlbumName);
}
Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString());
AddPagingParameters();
DisableCaching();
}
public async override Task<PageResponse<LastTag>> HandleResponse(HttpResponseMessage response)
{
var json = await response.Content.ReadAsStringAsync();
LastFmApiError error;
if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode)
{
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
var resultsToken = jtoken.SelectToken("toptags");
var itemsToken = resultsToken.SelectToken("tag");
return PageResponse<LastTag>.CreateSuccessResponse(itemsToken, resultsToken, LastTag.ParseJToken, false);
}
else
{
return LastResponse.CreateErrorResponse<PageResponse<LastTag>>(error);
}
}
}
}

View File

@ -40,6 +40,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Api\AlbumApi.cs" /> <Compile Include="Api\AlbumApi.cs" />
<Compile Include="Api\ArtistApi.cs" /> <Compile Include="Api\ArtistApi.cs" />
<Compile Include="Api\Commands\AlbumApi\AlbumTopTagsCommand.cs" />
<Compile Include="Api\Commands\UserApi\GetRecommendedArtistsCommand.cs" /> <Compile Include="Api\Commands\UserApi\GetRecommendedArtistsCommand.cs" />
<Compile Include="Api\LastAuth.cs" /> <Compile Include="Api\LastAuth.cs" />
<Compile Include="Api\ChartApi.cs" /> <Compile Include="Api\ChartApi.cs" />