mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-16 23:13:07 +01:00
Added user.getWeeklyArtistChart
This commit is contained in:
parent
920265eb4e
commit
9eb98d6e51
@ -0,0 +1,59 @@
|
||||
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.User
|
||||
{
|
||||
[ApiMethodName("user.getWeeklyArtistChart")]
|
||||
internal class GetWeeklyArtistChartCommand : GetAsyncCommandBase<PageResponse<LastArtist>>
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string To { get; set; }
|
||||
public string From { get; set; }
|
||||
|
||||
public GetWeeklyArtistChartCommand(ILastAuth auth, string username, string from, string to)
|
||||
: base(auth)
|
||||
{
|
||||
Username = username;
|
||||
From = from;
|
||||
To = to;
|
||||
}
|
||||
|
||||
public override void SetParameters()
|
||||
{
|
||||
if(!From.Equals(null))
|
||||
{
|
||||
Parameters.Add("from", From);
|
||||
}
|
||||
if(!To.Equals(null))
|
||||
{
|
||||
Parameters.Add("to", To);
|
||||
}
|
||||
|
||||
Parameters.Add("user", Username);
|
||||
DisableCaching();
|
||||
}
|
||||
|
||||
public override async Task<PageResponse<LastArtist>> HandleResponse(HttpResponseMessage response)
|
||||
{
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
|
||||
LastResponseStatus status;
|
||||
if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode)
|
||||
{
|
||||
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
|
||||
var chartListToken = jtoken.SelectToken("weeklyartistchart");
|
||||
var itemsToken = chartListToken.SelectToken("artist");
|
||||
var pageInfoToken = chartListToken.SelectToken("@attr");
|
||||
|
||||
return PageResponse<LastArtist>.CreateSuccessResponse(itemsToken, pageInfoToken, LastArtist.ParseJToken, LastPageResultsType.Attr);
|
||||
}
|
||||
|
||||
return LastResponse.CreateErrorResponse<PageResponse<LastArtist>>(status);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,11 @@
|
||||
namespace IF.Lastfm.Core.Api.Commands.User
|
||||
{
|
||||
[ApiMethodName("user.getWeeklyChartList")]
|
||||
internal class GetWeeklyChartsCommand : GetAsyncCommandBase<PageResponse<LastWeeklyChartList>>
|
||||
internal class GetWeeklyChartListCommand : GetAsyncCommandBase<PageResponse<LastWeeklyChartList>>
|
||||
{
|
||||
public string Username { get; set; }
|
||||
|
||||
public GetWeeklyChartsCommand(ILastAuth auth, string username)
|
||||
public GetWeeklyChartListCommand(ILastAuth auth, string username)
|
||||
: base(auth)
|
||||
{
|
||||
Username = username;
|
@ -41,5 +41,7 @@ Task<PageResponse<LastShout>> GetShoutsAsync(string username,
|
||||
Task<PageResponse<LastTrack>> GetLovedTracks(string username, int pagenumber, int count);
|
||||
|
||||
Task<PageResponse<LastWeeklyChartList>> GetWeeklyChartListAsync(string username);
|
||||
|
||||
Task<PageResponse<LastArtist>> GetWeeklyArtistChartAsync(string username, string to = null, string from = null);
|
||||
}
|
||||
}
|
@ -134,7 +134,15 @@ public async Task<PageResponse<LastTrack>> GetLovedTracks(
|
||||
}
|
||||
public async Task<PageResponse<LastWeeklyChartList>> GetWeeklyChartListAsync(string username)
|
||||
{
|
||||
var command = new GetWeeklyChartsCommand(auth: Auth, username: username)
|
||||
var command = new GetWeeklyChartListCommand(auth: Auth, username: username)
|
||||
{
|
||||
HttpClient = HttpClient
|
||||
};
|
||||
return await command.ExecuteAsync();
|
||||
}
|
||||
public async Task<PageResponse<LastArtist>> GetWeeklyArtistChartAsync(string username, string from = null, string to = null)
|
||||
{
|
||||
var command = new GetWeeklyArtistChartCommand(auth: Auth, username: username, from: from, to: to)
|
||||
{
|
||||
HttpClient = HttpClient
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user