From 895a0c50eb6830b0f804960cb2bbab56bc3c6c38 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 21 Mar 2016 14:23:55 +0000 Subject: [PATCH] Added a subdir to CP, SickRage, Sonarr and Plex #43 --- .../SettingModels/CouchPotatoSettings.cs | 6 ++++++ .../SettingModels/PlexSettings.cs | 6 ++++++ .../SettingModels/SickRageSettings.cs | 6 ++++++ .../SettingModels/SonarrSettings.cs | 6 ++++++ PlexRequests.Helpers.Tests/UriHelperTests.cs | 19 ++++++++++++++++++- PlexRequests.Helpers/UriHelper.cs | 19 +++++++++++++++++++ .../Views/Admin/CouchPotato.cshtml | 6 ++++++ PlexRequests.UI/Views/Admin/Plex.cshtml | 6 ++++++ PlexRequests.UI/Views/Admin/Sickrage.cshtml | 7 +++++++ PlexRequests.UI/Views/Admin/Sonarr.cshtml | 6 ++++++ 10 files changed, 86 insertions(+), 1 deletion(-) diff --git a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs index 7c18ca5d7..ff7ea01a5 100644 --- a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs +++ b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs @@ -38,12 +38,18 @@ namespace PlexRequests.Core.SettingModels public string ApiKey { get; set; } public bool Ssl { get; set; } public string ProfileId { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/SettingModels/PlexSettings.cs b/PlexRequests.Core/SettingModels/PlexSettings.cs index 89bc01931..fa39af857 100644 --- a/PlexRequests.Core/SettingModels/PlexSettings.cs +++ b/PlexRequests.Core/SettingModels/PlexSettings.cs @@ -36,12 +36,18 @@ namespace PlexRequests.Core.SettingModels public string Ip { get; set; } public int Port { get; set; } public bool Ssl { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/SettingModels/SickRageSettings.cs b/PlexRequests.Core/SettingModels/SickRageSettings.cs index 344e41434..657de3b50 100644 --- a/PlexRequests.Core/SettingModels/SickRageSettings.cs +++ b/PlexRequests.Core/SettingModels/SickRageSettings.cs @@ -39,12 +39,18 @@ namespace PlexRequests.Core.SettingModels public string ApiKey { get; set; } public string QualityProfile { get; set; } public bool Ssl { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/SettingModels/SonarrSettings.cs b/PlexRequests.Core/SettingModels/SonarrSettings.cs index 2c128f993..3c680e0e5 100644 --- a/PlexRequests.Core/SettingModels/SonarrSettings.cs +++ b/PlexRequests.Core/SettingModels/SonarrSettings.cs @@ -41,12 +41,18 @@ namespace PlexRequests.Core.SettingModels public bool SeasonFolders { get; set; } public string RootPath { get; set; } public bool Ssl { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Helpers.Tests/UriHelperTests.cs b/PlexRequests.Helpers.Tests/UriHelperTests.cs index 7c767dfd0..93fb32997 100644 --- a/PlexRequests.Helpers.Tests/UriHelperTests.cs +++ b/PlexRequests.Helpers.Tests/UriHelperTests.cs @@ -26,6 +26,7 @@ #endregion using System; +using System.Linq.Expressions; using NUnit.Framework; namespace PlexRequests.Helpers.Tests @@ -35,7 +36,7 @@ namespace PlexRequests.Helpers.Tests { [TestCaseSource(nameof(UriData))] public void CreateUri1(string uri, Uri expected) - { + { var result = uri.ReturnUri(); Assert.That(result, Is.EqualTo(expected)); @@ -58,6 +59,14 @@ namespace PlexRequests.Helpers.Tests Assert.That(result, Is.EqualTo(expected)); } + [TestCaseSource(nameof(UriDataWithSubDir))] + public void CreateUriWithSubDir(string uri, int port, bool ssl, string subDir, Uri expected) + { + var result = uri.ReturnUriWithSubDir(port, ssl, subDir); + + Assert.That(result, Is.EqualTo(expected)); + } + static readonly object[] UriData = { new object[] { "google.com", new Uri("http://google.com/"), }, @@ -84,5 +93,13 @@ namespace PlexRequests.Helpers.Tests new object[] {"http://www.google.com/id=2", 443, new Uri("http://www.google.com:443/id=2") }, new object[] {"https://www.google.com/id=2", 443, new Uri("https://www.google.com:443/id=2") }, }; + + static readonly object[] UriDataWithSubDir = +{ + new object[] {"www.google.com", 80, false,"test", new Uri("http://www.google.com:80/test"), }, + new object[] {"www.google.com", 443, false,"test", new Uri("http://www.google.com:443/test") }, + new object[] {"http://www.google.com", 443, true,"test", new Uri("https://www.google.com:443/test") }, + new object[] {"https://www.google.com", 443,true,"test", new Uri("https://www.google.com:443/test") }, + }; } } \ No newline at end of file diff --git a/PlexRequests.Helpers/UriHelper.cs b/PlexRequests.Helpers/UriHelper.cs index c33d5ddf4..707f70436 100644 --- a/PlexRequests.Helpers/UriHelper.cs +++ b/PlexRequests.Helpers/UriHelper.cs @@ -53,7 +53,10 @@ namespace PlexRequests.Helpers /// /// The value. /// The port. + /// if set to true [SSL]. + /// The subdir. /// + /// The URI is null, please check your settings to make sure you have configured the applications correctly. /// public static Uri ReturnUri(this string val, int port, bool ssl = default(bool)) { @@ -93,5 +96,21 @@ namespace PlexRequests.Helpers throw new Exception(exception.Message, exception); } } + + public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir) + { + var uriBuilder = new UriBuilder(val); + if (ssl) + { + uriBuilder.Scheme = Uri.UriSchemeHttps; + } + if (!string.IsNullOrEmpty(subDir)) + { + uriBuilder.Path = subDir; + } + uriBuilder.Port = port; + + return uriBuilder.Uri; + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index 4be47db0a..9e0aff8ef 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -51,6 +51,12 @@ +
+ +
+ +
+
diff --git a/PlexRequests.UI/Views/Admin/Plex.cshtml b/PlexRequests.UI/Views/Admin/Plex.cshtml index fca742fdf..af3702a63 100644 --- a/PlexRequests.UI/Views/Admin/Plex.cshtml +++ b/PlexRequests.UI/Views/Admin/Plex.cshtml @@ -43,6 +43,12 @@
+
+ +
+ +
+
diff --git a/PlexRequests.UI/Views/Admin/Sickrage.cshtml b/PlexRequests.UI/Views/Admin/Sickrage.cshtml index e03f6a458..15d57d873 100644 --- a/PlexRequests.UI/Views/Admin/Sickrage.cshtml +++ b/PlexRequests.UI/Views/Admin/Sickrage.cshtml @@ -64,6 +64,13 @@
+ +
+ +
+ +
+
diff --git a/PlexRequests.UI/Views/Admin/Sonarr.cshtml b/PlexRequests.UI/Views/Admin/Sonarr.cshtml index 5185e8ff4..454f06578 100644 --- a/PlexRequests.UI/Views/Admin/Sonarr.cshtml +++ b/PlexRequests.UI/Views/Admin/Sonarr.cshtml @@ -64,6 +64,12 @@
+
+ +
+ +
+