mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 15:23:08 +01:00
73e1831986
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.
57 lines
1.3 KiB
C#
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
|
|
}
|
|
} |