sonarr-repo-only/NzbDrone.Core/Notifications/Prowl/ProwlProvider.cs

79 lines
2.4 KiB
C#
Raw Normal View History

2011-11-03 02:44:22 +00:00
using System;
using NLog;
using Prowlin;
2013-05-19 23:17:32 +00:00
namespace NzbDrone.Core.Notifications.Prowl
2011-11-03 02:44:22 +00:00
{
public class ProwlProvider
{
2011-11-10 05:30:51 +00:00
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2011-11-03 02:44:22 +00:00
public virtual bool 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")
return true;
}
2011-11-10 05:30:51 +00:00
catch (Exception ex)
2011-11-03 02:44:22 +00:00
{
Logger.TraceException(ex.Message, ex);
Logger.Warn("Invalid API Key: {0}", apiKey);
}
return false;
}
2013-05-19 23:17:32 +00:00
public virtual bool SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null)
2011-11-03 02:44:22 +00:00
{
try
{
2013-05-19 23:17:32 +00:00
var notification = new Prowlin.Notification
2011-11-03 02:44:22 +00:00
{
2011-11-10 05:30:51 +00:00
Application = "NzbDrone",
Description = message,
Event = title,
Priority = priority,
Url = url
2011-11-03 02:44:22 +00:00
};
2013-05-19 23:17:32 +00:00
notification.AddApiKey(apiKey.Trim());
2011-11-03 02:44:22 +00:00
var client = new ProwlClient();
Logger.Trace("Sending Prowl Notification");
var notificationResult = client.SendNotification(notification);
if (String.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
return true;
}
2011-11-10 05:30:51 +00:00
catch (Exception ex)
2011-11-03 02:44:22 +00:00
{
Logger.TraceException(ex.Message, ex);
2013-05-19 23:17:32 +00:00
Logger.Warn("Invalid API Key: {0}", apiKey);
2011-11-03 02:44:22 +00:00
}
return false;
}
public virtual void TestNotification(string apiKeys)
{
const string title = "Test Notification";
const string message = "This is a test message from NzbDrone";
SendNotification(title, message, apiKeys);
}
}
}