2013-09-01 20:52:44 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading.Tasks;
|
2013-09-01 23:57:54 +01:00
|
|
|
using IF.Lastfm.Core.Api.Helpers;
|
2013-09-01 20:52:44 +01:00
|
|
|
|
|
|
|
namespace IF.Lastfm.Core.Api.Commands
|
|
|
|
{
|
2013-09-01 23:57:54 +01:00
|
|
|
public abstract class LastAsyncCommandBase<T> : IAsyncCommand<T> where T : LastResponse, new()
|
2013-09-01 20:52:44 +01:00
|
|
|
{
|
|
|
|
public string Method { get; protected set; }
|
|
|
|
public Uri Url { get; protected set; }
|
|
|
|
public IAuth Auth { get; protected set; }
|
|
|
|
public int Page { get; set; }
|
|
|
|
public int Count { get; set; }
|
|
|
|
|
|
|
|
protected Dictionary<string, string> Parameters { get; set; }
|
|
|
|
|
|
|
|
protected LastAsyncCommandBase()
|
|
|
|
{
|
|
|
|
Parameters = new Dictionary<string, string>();
|
2013-09-01 23:57:54 +01:00
|
|
|
}
|
2013-09-01 20:52:44 +01:00
|
|
|
|
|
|
|
public abstract void SetParameters();
|
|
|
|
protected abstract Uri BuildRequestUrl();
|
|
|
|
public abstract Task<T> ExecuteAsync();
|
|
|
|
public abstract Task<T> HandleResponse(HttpResponseMessage response);
|
|
|
|
|
|
|
|
protected void AddPagingParameters()
|
|
|
|
{
|
|
|
|
Parameters.Add("page", Page.ToString());
|
|
|
|
Parameters.Add("limit", Count.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Annoying workaround for Windows Phone's caching...
|
|
|
|
/// see http://stackoverflow.com/questions/6334788/windows-phone-7-webrequest-caching
|
|
|
|
/// </summary>
|
|
|
|
protected void DisableCaching()
|
|
|
|
{
|
|
|
|
Parameters.Add("disablecachetoken", DateTime.UtcNow.Ticks.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|