1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-26 22:46:53 -04:00

Provider testing improvements

New: Test button for indexers in UI

Fixed: Testing download clients shows error messages in UI
Fixed: Testing notifications shows error messages in UI
This commit is contained in:
Mark McDowall
2014-07-04 01:09:48 -07:00
parent c5bd8b27fb
commit 7af782d353
70 changed files with 727 additions and 591 deletions
@@ -1,14 +1,19 @@
using NzbDrone.Core.Tv;

using System.Collections.Generic;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
public class NotifyMyAndroid : NotificationBase<NotifyMyAndroidSettings>
{
private readonly INotifyMyAndroidProxy _notifyMyAndroidProxy;
private readonly INotifyMyAndroidProxy _proxy;
public NotifyMyAndroid(INotifyMyAndroidProxy notifyMyAndroidProxy)
public NotifyMyAndroid(INotifyMyAndroidProxy proxy)
{
_notifyMyAndroidProxy = notifyMyAndroidProxy;
_proxy = proxy;
}
public override string Link
@@ -20,18 +25,27 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
const string title = "Episode Grabbed";
_notifyMyAndroidProxy.SendNotification(title, message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
_proxy.SendNotification(title, message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Episode Downloaded";
_notifyMyAndroidProxy.SendNotification(title, message.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
_proxy.SendNotification(title, message.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
}
public override void AfterRename(Series series)
{
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_proxy.Test(Settings));
return new ValidationResult(failures);
}
}
}
@@ -2,8 +2,9 @@
using System.Linq;
using System.Net;
using System.Xml.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.Messaging.Commands;
using RestSharp;
using NzbDrone.Core.Rest;
@@ -12,12 +13,19 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
public interface INotifyMyAndroidProxy
{
void SendNotification(string title, string message, string apiKye, NotifyMyAndroidPriority priority);
ValidationFailure Test(NotifyMyAndroidSettings settings);
}
public class NotifyMyAndroidProxy : INotifyMyAndroidProxy, IExecute<TestNotifyMyAndroidCommand>
public class NotifyMyAndroidProxy : INotifyMyAndroidProxy
{
private readonly Logger _logger;
private const string URL = "https://www.notifymyandroid.com/publicapi";
public NotifyMyAndroidProxy(Logger logger)
{
_logger = logger;
}
public void SendNotification(string title, string message, string apiKey, NotifyMyAndroidPriority priority)
{
var client = new RestClient(URL);
@@ -56,12 +64,22 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
}
}
public void Execute(TestNotifyMyAndroidCommand message)
public ValidationFailure Test(NotifyMyAndroidSettings settings)
{
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
Verify(message.ApiKey);
SendNotification(title, body, message.ApiKey, (NotifyMyAndroidPriority)message.Priority);
try
{
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
Verify(settings.ApiKey);
SendNotification(title, body, settings.ApiKey, (NotifyMyAndroidPriority)settings.Priority);
}
catch (Exception ex)
{
_logger.ErrorException("Unable to send test message: " + ex.Message, ex);
return new ValidationFailure("ApiKey", "Unable to send test message");
}
return null;
}
}
}
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
get
{
return !String.IsNullOrWhiteSpace(ApiKey) && Priority != null & Priority >= -1 && Priority <= 2;
return !String.IsNullOrWhiteSpace(ApiKey) && Priority >= -1 && Priority <= 2;
}
}
@@ -1,18 +0,0 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
public class TestNotifyMyAndroidCommand : Command
{
public override bool SendUpdatesToClient
{
get
{
return true;
}
}
public string ApiKey { get; set; }
public int Priority { get; set; }
}
}