1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-24 22:36:19 -04:00

Webhook improvements

New: Include Path/Relative Path for on download Webhooks
New: IsUpgrade flag for on download Webhooks
This commit is contained in:
Mark McDowall
2017-06-28 14:13:50 -07:00
parent 601b54c244
commit 4189bc6f76
10 changed files with 214 additions and 135 deletions
@@ -0,0 +1,41 @@
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Rest;
namespace NzbDrone.Core.Notifications.Webhook
{
public interface IWebhookProxy
{
void SendWebhook(WebhookPayload payload, WebhookSettings settings);
}
public class WebhookProxy : IWebhookProxy
{
private readonly IHttpClient _httpClient;
public WebhookProxy(IHttpClient httpClient)
{
_httpClient = httpClient;
}
public void SendWebhook(WebhookPayload body, WebhookSettings settings)
{
try
{
var request = new HttpRequestBuilder(settings.Url)
.Accept(HttpAccept.Json)
.Build();
request.Method = (HttpMethod)settings.Method;
request.Headers.ContentType = "application/json";
request.SetContent(body.ToJson());
_httpClient.Execute(request);
}
catch (RestException ex)
{
throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
}
}
}
}