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

View file

@ -1,5 +1,7 @@
using System;
using NzbDrone.Core.Messaging.Commands;
using System.Net;
using FluentValidation.Results;
using NLog;
using RestSharp;
using NzbDrone.Core.Rest;
@ -8,12 +10,19 @@ namespace NzbDrone.Core.Notifications.PushBullet
public interface IPushBulletProxy
{
void SendNotification(string title, string message, string apiKey, string deviceId);
ValidationFailure Test(PushBulletSettings settings);
}
public class PushBulletProxy : IPushBulletProxy, IExecute<TestPushBulletCommand>
public class PushBulletProxy : IPushBulletProxy
{
private readonly Logger _logger;
private const string URL = "https://api.pushbullet.com/api/pushes";
public PushBulletProxy(Logger logger)
{
_logger = logger;
}
public void SendNotification(string title, string message, string apiKey, string deviceId)
{
var client = new RestClient(URL);
@ -45,12 +54,33 @@ namespace NzbDrone.Core.Notifications.PushBullet
return request;
}
public void Execute(TestPushBulletCommand message)
public ValidationFailure Test(PushBulletSettings settings)
{
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
try
{
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
SendNotification(title, body, message.ApiKey, message.DeviceId);
SendNotification(title, body, settings.ApiKey, settings.DeviceId);
}
catch (RestException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.ErrorException("API Key is invalid: " + ex.Message, ex);
return new ValidationFailure("ApiKey", "API Key is invalid");
}
_logger.ErrorException("Unable to send test message: " + ex.Message, ex);
return new ValidationFailure("ApiKey", "Unable to send test message");
}
catch (Exception ex)
{
_logger.ErrorException("Unable to send test message: " + ex.Message, ex);
return new ValidationFailure("", "Unable to send test message");
}
return null;
}
}
}