diff --git a/PlexRequests.Api.Interfaces/ISonarrApi.cs b/PlexRequests.Api.Interfaces/ISonarrApi.cs index 74ec72d1c..d9e7c61db 100644 --- a/PlexRequests.Api.Interfaces/ISonarrApi.cs +++ b/PlexRequests.Api.Interfaces/ISonarrApi.cs @@ -37,5 +37,7 @@ namespace PlexRequests.Api.Interfaces SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, bool episodes, string apiKey, Uri baseUrl); + + SystemStatus SystemStatus(string apiKey, Uri baseUrl); } } \ No newline at end of file diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index c7d8aaeef..fd5200e72 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -51,6 +51,7 @@ + diff --git a/PlexRequests.Api.Models/Sonarr/SystemStatus.cs b/PlexRequests.Api.Models/Sonarr/SystemStatus.cs new file mode 100644 index 000000000..5f04c607a --- /dev/null +++ b/PlexRequests.Api.Models/Sonarr/SystemStatus.cs @@ -0,0 +1,48 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SystemStatus.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace PlexRequests.Api.Models.Sonarr +{ + public class SystemStatus + { + public string version { get; set; } + public string buildTime { get; set; } + public bool isDebug { get; set; } + public bool isProduction { get; set; } + public bool isAdmin { get; set; } + public bool isUserInteractive { get; set; } + public string startupPath { get; set; } + public string appData { get; set; } + public string osVersion { get; set; } + public bool isMono { get; set; } + public bool isLinux { get; set; } + public bool isWindows { get; set; } + public string branch { get; set; } + public bool authentication { get; set; } + public int startOfWeek { get; set; } + public string urlBase { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs index 81a0fb5d8..4ff51e2d7 100644 --- a/PlexRequests.Api/SonarrApi.cs +++ b/PlexRequests.Api/SonarrApi.cs @@ -98,5 +98,15 @@ namespace PlexRequests.Api return obj; } + + public SystemStatus SystemStatus(string apiKey, Uri baseUrl) + { + var request = new RestRequest { Resource = "/api/system/status", Method = Method.GET }; + request.AddHeader("X-Api-Key", apiKey); + + var obj = Api.ExecuteJson(request, baseUrl); + + return obj; + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApplicationTesterModule.cs b/PlexRequests.UI/Modules/ApplicationTesterModule.cs index b979952bf..eeeef9cfc 100644 --- a/PlexRequests.UI/Modules/ApplicationTesterModule.cs +++ b/PlexRequests.UI/Modules/ApplicationTesterModule.cs @@ -25,8 +25,6 @@ // ************************************************************************/ #endregion using System; -using System.Collections.Generic; -using System.Linq; using Nancy; using Nancy.ModelBinding; @@ -34,11 +32,8 @@ using Nancy.Security; using NLog; -using PlexRequests.Api; using PlexRequests.Api.Interfaces; -using PlexRequests.Core; using PlexRequests.Core.SettingModels; -using PlexRequests.Store; using PlexRequests.UI.Models; namespace PlexRequests.UI.Modules @@ -55,6 +50,7 @@ namespace PlexRequests.UI.Modules Post["/cp"] = _ => CouchPotatoTest(); + Post["/sonarr"] = _ => SonarrTest(); } @@ -85,5 +81,29 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); } } + + private Response SonarrTest() + { + var sonarrSettings = this.Bind(); + try + { + var status = SonarrApi.SystemStatus(sonarrSettings.ApiKey, sonarrSettings.FullUri); + return status != null + ? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Sonarr successfully!" }) + : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." }); + + } + catch (ApplicationException e) // Exceptions are expected if we cannot connect so we will just log and swallow them. + { + Log.Warn("Exception thrown when attempting to get Sonarr's status: "); + Log.Warn(e); + var message = $"Could not connect to Sonarr, please check your settings. Exception Message: {e.Message}"; + if (e.InnerException != null) + { + message = $"Could not connect to Sonarr, please check your settings. Exception Message: {e.InnerException.Message}"; + } + return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); + } + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index a9ae695c0..b20787ced 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -85,10 +85,6 @@ } }); }); - - - - - + }); \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/Sonarr.cshtml b/PlexRequests.UI/Views/Admin/Sonarr.cshtml index 60c490a91..f63e58a0b 100644 --- a/PlexRequests.UI/Views/Admin/Sonarr.cshtml +++ b/PlexRequests.UI/Views/Admin/Sonarr.cshtml @@ -74,6 +74,12 @@ +
+
+ +
+
+
@@ -183,6 +189,31 @@ }); }); + $('#testSonarr').click(function (e) { + e.preventDefault(); + var $form = $("#mainForm"); + $.ajax({ + type: $form.prop("method"), + url: "/test/sonarr", + data: $form.serialize(), + dataType: "json", + success: function (response) { + console.log(response); + if (response.result === true) { + generateNotify(response.message, "success"); + $('#authToken').val(response.authToken); + } else { + generateNotify(response.message, "warning"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + }); + + }) \ No newline at end of file