mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
merge
This commit is contained in:
commit
ac51126437
39 changed files with 529 additions and 29 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, IDictionary<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.1</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>
|
40
src/Ombi.Api.Webhook/WebhookApi.cs
Normal file
40
src/Ombi.Api.Webhook/WebhookApi.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
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, IDictionary<string, string> parameters)
|
||||
{
|
||||
var request = new Request("/", baseUrl, HttpMethod.Post);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
request.AddHeader("Access-Token", accessToken);
|
||||
}
|
||||
|
||||
var body = parameters.ToDictionary(
|
||||
x => _nameResolver.GetResolvedPropertyName(x.Key),
|
||||
x => x.Value
|
||||
);
|
||||
|
||||
request.ApplicationJsonContentType();
|
||||
request.AddJsonBody(body);
|
||||
|
||||
await _api.Request(request);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue