IF.Lastfm/IF.Lastfm.Core/Api/Commands/PostAsyncCommandBase.cs
2013-09-01 20:52:44 +01:00

40 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace IF.Lastfm.Core.Api.Commands
{
internal abstract class PostAsyncCommandBase<T> : LastAsyncCommandBase<T>
{
protected PostAsyncCommandBase(IAuth auth)
{
Auth = auth;
}
protected override Uri BuildRequestUrl()
{
return new Uri(LastFm.ApiRoot, UriKind.Absolute);
}
public override async Task<T> ExecuteAsync()
{
SetParameters();
Url = BuildRequestUrl();
Parameters.Add("sk", Auth.User.Token);
var apisig = Auth.GenerateMethodSignature(Method, Parameters);
var postContent = LastFm.CreatePostBody(Method,
Auth.ApiKey,
apisig,
Parameters);
var httpClient = new HttpClient();
var response = await httpClient.PostAsync(Url, postContent);
return await HandleResponse(response);
}
}
}