mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 03:28:28 -07:00
Add webhook notification and API logic
This commit is contained in:
parent
faba87cdc6
commit
cdc002ecd7
8 changed files with 216 additions and 2 deletions
36
src/Ombi.Api.Webhook/WebhookApi.cs
Normal file
36
src/Ombi.Api.Webhook/WebhookApi.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue