IF.Lastfm/IF.Lastfm.Core/Api/Helpers/LastResponse.cs
Rikki Tooley 73e1831986 user.shout, artist.shout.
the api doesn't have album.shout and track.shout but i made commands for
them anyway, not put them in AlbumApi or TrackApi though.
2013-07-30 00:36:55 +01:00

57 lines
1.3 KiB
C#

using System.Net.Http;
using System.Threading.Tasks;
using IF.Lastfm.Core.Api.Enums;
namespace IF.Lastfm.Core.Api.Helpers
{
public class LastResponse
{
#region Properties
public bool Success { get; set; }
public LastFmApiError Error { get; set; }
#endregion
#region Factory methods
public static LastResponse CreateSuccessResponse()
{
var r = new LastResponse
{
Success = true,
Error = LastFmApiError.None
};
return r;
}
public static LastResponse CreateErrorResponse(LastFmApiError error)
{
var r = new LastResponse
{
Success = false,
Error = error
};
return r;
}
public async static Task<LastResponse> HandleResponse(HttpResponseMessage response)
{
string json = await response.Content.ReadAsStringAsync();
LastFmApiError error;
if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode)
{
return LastResponse.CreateSuccessResponse();
}
else
{
return LastResponse.CreateErrorResponse(error);
}
}
#endregion
}
}