Minor updates related to Github's comments

* Access-Token Header is not sent if it has not been configured (or left blank)
* Access token is now also sent in URI string with "token" as key
* NotificationType is manually added to the notification data (original data is cloned before to avoid conflict in case of re-usage by other notification handlers)
This commit is contained in:
Namaneo 2019-11-30 18:18:33 +01:00
parent 78ac3984cb
commit 8ae98c91c1
4 changed files with 14 additions and 6 deletions

View file

@ -5,6 +5,6 @@ namespace Ombi.Api.Webhook
{
public interface IWebhookApi
{
Task PushAsync(string endpoint, string accessToken, IReadOnlyDictionary<string, string> parameters);
Task PushAsync(string endpoint, string accessToken, IDictionary<string, string> parameters);
}
}

View file

@ -17,17 +17,22 @@ namespace Ombi.Api.Webhook
private readonly IApi _api;
public async Task PushAsync(string baseUrl, string accessToken, IReadOnlyDictionary<string, string> parameters)
public async Task PushAsync(string baseUrl, string accessToken, IDictionary<string, string> parameters)
{
var request = new Request("/", baseUrl, HttpMethod.Post);
request.AddHeader("Access-Token", accessToken);
request.ApplicationJsonContentType();
if (!string.IsNullOrWhiteSpace(accessToken))
{
request.AddQueryString("token", 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);