Add webhook notification and API logic

This commit is contained in:
Namaneo 2019-11-29 16:05:14 +01:00
parent faba87cdc6
commit cdc002ecd7
8 changed files with 216 additions and 2 deletions

View file

@ -0,0 +1,36 @@
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Ombi.Api.Webhook
{
public class WebhookApi : IWebhookApi
{
private static readonly CamelCasePropertyNamesContractResolver _nameResolver = new CamelCasePropertyNamesContractResolver();
public WebhookApi(IApi api)
{
_api = api;
}
private readonly IApi _api;
public async Task PushAsync(string baseUrl, string accessToken, IReadOnlyDictionary<string, string> parameters)
{
var request = new Request("/", baseUrl, HttpMethod.Post);
request.AddHeader("Access-Token", accessToken);
request.ApplicationJsonContentType();
var body = parameters.ToDictionary(
x => _nameResolver.GetResolvedPropertyName(x.Key),
x => x.Value
);
request.AddJsonBody(body);
await _api.Request(request);
}
}
}