diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs index ee7d2701f..de238d9f6 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs @@ -39,7 +39,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests fakeConfig.SetupGet(c => c.SabTvCategory).Returns("tv"); } - private void WithFailResponse() { Mocker.GetMock() @@ -57,7 +56,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests Mocker.Resolve().DownloadNzb(url, title).Should().BeTrue(); } - [Test] public void newzbin_add_url_should_format_request_properly() { @@ -122,7 +120,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests result.categories.Should().NotBeEmpty(); } - [Test] public void GetHistory_should_return_a_list_with_items_when_the_history_has_items() { @@ -162,5 +159,54 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests Assert.Throws(() => Mocker.Resolve().GetHistory(), "API Key Incorrect"); } + [Test] + public void GetVersion_should_return_the_version_using_passed_in_values() + { + var response = "{ \"version\": \"0.6.9\" }"; + + Mocker.GetMock() + .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=version&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) + .Returns(response); + + //Act + var result = Mocker.Resolve().GetVersion("192.168.5.55", 2222, "5c770e3197e4fe763423ee7c392c25d1", "admin", "pass"); + + //Assert + result.Should().NotBeNull(); + result.Version.Should().Be("0.6.9"); + } + + [Test] + public void GetVersion_should_return_the_version_using_saved_values() + { + var response = "{ \"version\": \"0.6.9\" }"; + + Mocker.GetMock() + .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=version&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) + .Returns(response); + + //Act + var result = Mocker.Resolve().GetVersion(); + + //Assert + result.Should().NotBeNull(); + result.Version.Should().Be("0.6.9"); + } + + [Test] + public void Test_should_return_version_as_a_string() + { + var response = "{ \"version\": \"0.6.9\" }"; + + Mocker.GetMock() + .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=version&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) + .Returns(response); + + //Act + var result = Mocker.Resolve().Test("192.168.5.55", 2222, "5c770e3197e4fe763423ee7c392c25d1", "admin", "pass"); + + //Assert + result.Should().Be("0.6.9"); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Model/Sabnzbd/SabVersionModel.cs b/NzbDrone.Core/Model/Sabnzbd/SabVersionModel.cs new file mode 100644 index 000000000..2e326a7c9 --- /dev/null +++ b/NzbDrone.Core/Model/Sabnzbd/SabVersionModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Model.Sabnzbd +{ + public class SabVersionModel + { + public string Version { get; set; } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 77e606eb4..7d67e161f 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -263,6 +263,7 @@ + diff --git a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs index 2602842c1..82c6bdbd4 100644 --- a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs @@ -121,7 +121,6 @@ namespace NzbDrone.Core.Providers.DownloadClients return items ?? new List(); } - public virtual SabCategoryModel GetCategories(string host = null, int port = 0, string apiKey = null, string username = null, string password = null) { //Get saved values if any of these are defaults @@ -155,6 +154,54 @@ namespace NzbDrone.Core.Providers.DownloadClients return categories; } + public virtual SabVersionModel GetVersion(string host = null, int port = 0, string apiKey = null, string username = null, string password = null) + { + //Get saved values if any of these are defaults + if (host == null) + host = _configProvider.SabHost; + + if (port == 0) + port = _configProvider.SabPort; + + if (apiKey == null) + apiKey = _configProvider.SabApiKey; + + if (username == null) + username = _configProvider.SabUsername; + + if (password == null) + password = _configProvider.SabPassword; + + const string action = "mode=version&output=json"; + + var command = string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}", + host, port, action, apiKey, username, password); + + var response = _httpProvider.DownloadString(command); + + if (String.IsNullOrWhiteSpace(response)) + return null; + + var version = JsonConvert.DeserializeObject(response); + + return version; + } + + public virtual string Test(string host, int port, string apiKey, string username, string password) + { + try + { + var version = GetVersion(host, port, apiKey, username, password); + return version.Version; + } + catch(Exception ex) + { + logger.DebugException("Failed to Test SABnzbd", ex); + } + + return String.Empty; + } + private string GetSabRequest(string action) { return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}", diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 9a0926ef3..03487435b 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -17,10 +17,12 @@ namespace NzbDrone.Web.Controllers private readonly EpisodeProvider _episodeProvider; private readonly GrowlProvider _growlProvider; private readonly SeasonProvider _seasonProvider; + private readonly ProwlProvider _prowlProvider; public CommandController(JobProvider jobProvider, SabProvider sabProvider, SmtpProvider smtpProvider, TwitterProvider twitterProvider, - EpisodeProvider episodeProvider, GrowlProvider growlProvider, SeasonProvider seasonProvider) + EpisodeProvider episodeProvider, GrowlProvider growlProvider, + SeasonProvider seasonProvider, ProwlProvider prowlProvider) { _jobProvider = jobProvider; _sabProvider = sabProvider; @@ -29,6 +31,7 @@ namespace NzbDrone.Web.Controllers _episodeProvider = episodeProvider; _growlProvider = growlProvider; _seasonProvider = seasonProvider; + _prowlProvider = prowlProvider; } public JsonResult RssSync() @@ -126,5 +129,22 @@ namespace NzbDrone.Web.Controllers _episodeProvider.SetEpisodeIgnore(episodeId, ignored); return new EmptyResult(); } + + public JsonResult TestProwl(string apiKeys) + { + _prowlProvider.TestNotification(apiKeys); + return JsonNotificationResult.Info("Good News!", "Test message has been sent to Prowl"); + } + + public JsonResult TestSabnzbd(string host, int port, string apiKey, string username, string password) + { + //_prowlProvider.TestNotification(apiKeys); + var version = _sabProvider.Test(host, port, apiKey, username, password); + + if (String.IsNullOrWhiteSpace(version)) + return JsonNotificationResult.Oops("Failed to connect to SABnzbd, please check your settings"); + + return JsonNotificationResult.Info("Success!", "SABnzbd settings have been verified successfully! Version: " + version); + } } } diff --git a/NzbDrone.Web/Scripts/NzbDrone/settings.js b/NzbDrone.Web/Scripts/NzbDrone/settings.js index 1b50e656f..802d9e289 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/settings.js +++ b/NzbDrone.Web/Scripts/NzbDrone/settings.js @@ -6,6 +6,10 @@ $('#SeparatorStyle').live('change', function () { createExamples(); }); $('#NumberStyle').live('change', function () { createExamples(); }); $('#MultiEpisodeStyle').live('change', function () { createExamples(); }); +var testProwlUrl = '../Command/TestProwl'; +var testSabUrl = '../Command/TestSabnzbd'; + + function createExamples() { createSingleEpisodeExample(); createMultiEpisodeExample(); @@ -101,4 +105,32 @@ function createMultiEpisodeExample() { result = result.replace(/\s/g, '.'); $('#multiEpisodeExample').children('.result').text(result); +} + +function testProwl(event) { + var apiKeys = $('#ProwlApiKeys').val(); + + $.ajax({ + type: "GET", + url: testProwlUrl, + data: jQuery.param({ apiKeys: apiKeys }) + }); + + event.preventDefault(); +} + +function testSabnzbd(event) { + var host = $('#SabHost').val(); + var port = $('#SabPort').val(); + var apiKey = $('#SabApiKey').val(); + var username = $('#SabUsername').val(); + var password = $('#SabPassword').val(); + + $.ajax({ + type: "GET", + url: testSabUrl, + data: jQuery.param({ host: host, port: port, apiKey: apiKey, username: username, password: password }) + }); + + event.preventDefault(); } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Prowl.cshtml b/NzbDrone.Web/Views/Settings/Prowl.cshtml index ded7a69d9..aaf1ef473 100644 --- a/NzbDrone.Web/Views/Settings/Prowl.cshtml +++ b/NzbDrone.Web/Views/Settings/Prowl.cshtml @@ -31,4 +31,9 @@ @Html.DescriptionFor(m => m.ProwlPriority) @Html.DropDownListFor(m => m.ProwlPriority, Model.ProwlPrioritySelectList, new { @class = "inputClass selectClass" }) + + + \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Sabnzbd.cshtml b/NzbDrone.Web/Views/Settings/Sabnzbd.cshtml index 740b74709..ce18214d1 100644 --- a/NzbDrone.Web/Views/Settings/Sabnzbd.cshtml +++ b/NzbDrone.Web/Views/Settings/Sabnzbd.cshtml @@ -50,5 +50,8 @@ @Html.DropDownListFor(m => m.SabTvPriority, Model.PrioritySelectList, new { @class = "inputClass selectClass" }) - + + \ No newline at end of file