mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -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
10
src/Ombi.Api.Webhook/IWebhookApi.cs
Normal file
10
src/Ombi.Api.Webhook/IWebhookApi.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api.Webhook
|
||||
{
|
||||
public interface IWebhookApi
|
||||
{
|
||||
Task PushAsync(string endpoint, string accessToken, IReadOnlyDictionary<string, string> parameters);
|
||||
}
|
||||
}
|
15
src/Ombi.Api.Webhook/Ombi.Api.Webhook.csproj
Normal file
15
src/Ombi.Api.Webhook/Ombi.Api.Webhook.csproj
Normal file
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyVersion>3.0.0.0</AssemblyVersion>
|
||||
<FileVersion>3.0.0.0</FileVersion>
|
||||
<Version></Version>
|
||||
<PackageVersion></PackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
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