IF.Lastfm/IF.Lastfm.Core/Api/Commands/ArtistApi/GetArtistShoutsCommand.cs

50 lines
1.5 KiB
C#
Raw Normal View History

2013-07-24 07:59:07 +01:00
using System;
using System.Net.Http;
using System.Threading.Tasks;
using IF.Lastfm.Core.Api.Enums;
using IF.Lastfm.Core.Api.Helpers;
using IF.Lastfm.Core.Objects;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IF.Lastfm.Core.Api.Commands.ArtistApi
{
public class GetArtistShoutsCommand : GetAsyncCommandBase<PageResponse<Shout>>
2013-07-24 07:59:07 +01:00
{
public string ArtistName { get; set; }
public bool Autocorrect { get; set; }
public GetArtistShoutsCommand(IAuth auth, string artistname)
: base(auth)
{
Method = "artist.getShouts";
ArtistName = artistname;
}
public override void SetParameters()
2013-07-24 07:59:07 +01:00
{
Parameters.Add("artist", ArtistName);
Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString());
2013-07-24 07:59:07 +01:00
base.AddPagingParameters();
base.DisableCaching();
2013-07-24 07:59:07 +01:00
}
public override async Task<PageResponse<Shout>> HandleResponse(HttpResponseMessage response)
2013-07-24 07:59:07 +01:00
{
string json = await response.Content.ReadAsStringAsync();
LastFmApiError error;
if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode)
{
var jtoken = JsonConvert.DeserializeObject<JToken>(json).SelectToken("shouts");
2013-07-24 07:59:07 +01:00
return Shout.ParsePageJToken(jtoken);
2013-07-24 07:59:07 +01:00
}
else
{
return PageResponse<Shout>.CreateErrorResponse(error);
}
}
}
}