2013-06-23 20:10:57 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
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.AlbumApi
|
|
|
|
|
{
|
|
|
|
|
internal class GetAlbumInfoCommand : GetAsyncCommandBase<LastResponse<Album>>
|
|
|
|
|
{
|
|
|
|
|
public string ArtistName { get; private set; }
|
|
|
|
|
public string AlbumName { get; private set; }
|
|
|
|
|
public bool Autocorrect { get; set; }
|
|
|
|
|
|
|
|
|
|
public GetAlbumInfoCommand(IAuth auth, string artistname, string albumname) : base(auth)
|
|
|
|
|
{
|
|
|
|
|
Method = "album.getInfo";
|
|
|
|
|
ArtistName = artistname;
|
|
|
|
|
AlbumName = albumname;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-23 22:46:29 +01:00
|
|
|
|
public override Uri BuildRequestUrl()
|
2013-06-23 20:10:57 +01:00
|
|
|
|
{
|
|
|
|
|
var parameters = new Dictionary<string, string>
|
|
|
|
|
{
|
2013-07-25 00:07:37 +01:00
|
|
|
|
{"artist", Uri.EscapeDataString(ArtistName)},
|
|
|
|
|
{"album", Uri.EscapeDataString(AlbumName)},
|
2013-06-23 20:10:57 +01:00
|
|
|
|
{"autocorrect", Convert.ToInt32(Autocorrect).ToString()}
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-24 01:48:55 +01:00
|
|
|
|
base.DisableCaching(parameters);
|
|
|
|
|
|
2013-06-23 20:10:57 +01:00
|
|
|
|
var apiUrl = LastFm.FormatApiUrl(Method, Auth.ApiKey, parameters);
|
2013-07-23 22:46:29 +01:00
|
|
|
|
return new Uri(apiUrl, UriKind.Absolute);
|
2013-06-23 20:10:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async override Task<LastResponse<Album>> HandleResponse(HttpResponseMessage response)
|
|
|
|
|
{
|
|
|
|
|
string json = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
LastFmApiError error;
|
|
|
|
|
if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
|
|
|
|
|
|
|
|
|
|
var album = Album.ParseJToken(jtoken.SelectToken("album"));
|
|
|
|
|
|
|
|
|
|
return LastResponse<Album>.CreateSuccessResponse(album);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return LastResponse<Album>.CreateErrorResponse(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|