mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Notifications can be tested
Notification ImplementationType was added for showing in UI (Humanized/Title cased of Implementation)
This commit is contained in:
parent
1f4cf0034e
commit
8cac7ed1cd
34 changed files with 418 additions and 328 deletions
93
NzbDrone.Core/Notifications/Prowl/ProwlService.cs
Normal file
93
NzbDrone.Core/Notifications/Prowl/ProwlService.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using Prowlin;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Prowl
|
||||
{
|
||||
public interface IProwlService
|
||||
{
|
||||
void SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null);
|
||||
}
|
||||
|
||||
public class ProwlService : IProwlService, IExecute<TestProwlCommand>
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ProwlService(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var notification = new Prowlin.Notification
|
||||
{
|
||||
Application = "NzbDrone",
|
||||
Description = message,
|
||||
Event = title,
|
||||
Priority = priority,
|
||||
Url = url
|
||||
};
|
||||
|
||||
notification.AddApiKey(apiKey.Trim());
|
||||
|
||||
var client = new ProwlClient();
|
||||
|
||||
_logger.Trace("Sending Prowl Notification");
|
||||
|
||||
var notificationResult = client.SendNotification(notification);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
|
||||
{
|
||||
throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.TraceException(ex.Message, ex);
|
||||
_logger.Warn("Invalid API Key: {0}", apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
public void Verify(string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
var verificationRequest = new Verification();
|
||||
verificationRequest.ApiKey = apiKey;
|
||||
|
||||
var client = new ProwlClient();
|
||||
|
||||
_logger.Trace("Verifying API Key: {0}", apiKey);
|
||||
|
||||
var verificationResult = client.SendVerification(verificationRequest);
|
||||
if (!String.IsNullOrWhiteSpace(verificationResult.ErrorMessage) &&
|
||||
verificationResult.ResultCode != "200")
|
||||
{
|
||||
throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.TraceException(ex.Message, ex);
|
||||
_logger.Warn("Invalid API Key: {0}", apiKey);
|
||||
throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(TestProwlCommand message)
|
||||
{
|
||||
Verify(message.ApiKey);
|
||||
|
||||
const string title = "Test Notification";
|
||||
const string body = "This is a test message from NzbDrone";
|
||||
|
||||
SendNotification(title, body, message.ApiKey);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue