diff --git a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs index a7b17d61c..bcfdb3dfd 100644 --- a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs +++ b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs @@ -27,11 +27,13 @@ using System; +using PlexRequests.Api.Models.Movie; + namespace PlexRequests.Api.Interfaces { public interface ICouchPotatoApi { bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl); - + CouchPotatoStatus GetStatus(Uri url, string apiKey); } } \ No newline at end of file diff --git a/PlexRequests.Api.Interfaces/IPlexApi.cs b/PlexRequests.Api.Interfaces/IPlexApi.cs index 59fffb5d5..473bf3237 100644 --- a/PlexRequests.Api.Interfaces/IPlexApi.cs +++ b/PlexRequests.Api.Interfaces/IPlexApi.cs @@ -36,6 +36,7 @@ namespace PlexRequests.Api.Interfaces PlexAuthentication SignIn(string username, string password); PlexFriends GetUsers(string authToken); PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost); + PlexStatus GetStatus(string authToken, Uri uri); } } \ No newline at end of file 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.Interfaces/Properties/AssemblyInfo.cs b/PlexRequests.Api.Interfaces/Properties/AssemblyInfo.cs index cc5288abe..e8fb7c60d 100644 --- a/PlexRequests.Api.Interfaces/Properties/AssemblyInfo.cs +++ b/PlexRequests.Api.Interfaces/Properties/AssemblyInfo.cs @@ -34,3 +34,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Api.Models/Movie/CouchPotatoStatus.cs b/PlexRequests.Api.Models/Movie/CouchPotatoStatus.cs new file mode 100644 index 000000000..7f20a7596 --- /dev/null +++ b/PlexRequests.Api.Models/Movie/CouchPotatoStatus.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlexRequests.Api.Models.Movie +{ + public class CouchPotatoStatus + { + public bool success { get; set; } + } +} diff --git a/PlexRequests.Api.Models/Plex/PlexSearch.cs b/PlexRequests.Api.Models/Plex/PlexSearch.cs index 28a72e6f4..1d19b18bd 100644 --- a/PlexRequests.Api.Models/Plex/PlexSearch.cs +++ b/PlexRequests.Api.Models/Plex/PlexSearch.cs @@ -24,11 +24,10 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion - using System.Collections.Generic; using System.Xml.Serialization; -namespace PlexRequests.Api.Models +namespace PlexRequests.Api.Models.Plex { [XmlRoot(ElementName = "Part")] public class Part diff --git a/PlexRequests.Api.Models/Plex/PlexStatus.cs b/PlexRequests.Api.Models/Plex/PlexStatus.cs new file mode 100644 index 000000000..e6f1e64bb --- /dev/null +++ b/PlexRequests.Api.Models/Plex/PlexStatus.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace PlexRequests.Api.Models.Plex +{ + [XmlRoot(ElementName = "Directory")] + public class Directory + { + [XmlAttribute(AttributeName = "count")] + public string Count { get; set; } + [XmlAttribute(AttributeName = "key")] + public string Key { get; set; } + [XmlAttribute(AttributeName = "title")] + public string Title { get; set; } + } + + [XmlRoot(ElementName = "MediaContainer")] + public class PlexStatus + { + [XmlElement(ElementName = "Directory")] + public List Directory { get; set; } + [XmlAttribute(AttributeName = "size")] + public string Size { get; set; } + [XmlAttribute(AttributeName = "allowCameraUpload")] + public string AllowCameraUpload { get; set; } + [XmlAttribute(AttributeName = "allowChannelAccess")] + public string AllowChannelAccess { get; set; } + [XmlAttribute(AttributeName = "allowMediaDeletion")] + public string AllowMediaDeletion { get; set; } + [XmlAttribute(AttributeName = "allowSync")] + public string AllowSync { get; set; } + [XmlAttribute(AttributeName = "backgroundProcessing")] + public string BackgroundProcessing { get; set; } + [XmlAttribute(AttributeName = "certificate")] + public string Certificate { get; set; } + [XmlAttribute(AttributeName = "companionProxy")] + public string CompanionProxy { get; set; } + [XmlAttribute(AttributeName = "friendlyName")] + public string FriendlyName { get; set; } + [XmlAttribute(AttributeName = "machineIdentifier")] + public string MachineIdentifier { get; set; } + [XmlAttribute(AttributeName = "multiuser")] + public string Multiuser { get; set; } + [XmlAttribute(AttributeName = "myPlex")] + public string MyPlex { get; set; } + [XmlAttribute(AttributeName = "myPlexMappingState")] + public string MyPlexMappingState { get; set; } + [XmlAttribute(AttributeName = "myPlexSigninState")] + public string MyPlexSigninState { get; set; } + [XmlAttribute(AttributeName = "myPlexSubscription")] + public string MyPlexSubscription { get; set; } + [XmlAttribute(AttributeName = "myPlexUsername")] + public string MyPlexUsername { get; set; } + [XmlAttribute(AttributeName = "platform")] + public string Platform { get; set; } + [XmlAttribute(AttributeName = "platformVersion")] + public string PlatformVersion { get; set; } + [XmlAttribute(AttributeName = "requestParametersInCookie")] + public string RequestParametersInCookie { get; set; } + [XmlAttribute(AttributeName = "sync")] + public string Sync { get; set; } + [XmlAttribute(AttributeName = "transcoderActiveVideoSessions")] + public string TranscoderActiveVideoSessions { get; set; } + [XmlAttribute(AttributeName = "transcoderAudio")] + public string TranscoderAudio { get; set; } + [XmlAttribute(AttributeName = "transcoderLyrics")] + public string TranscoderLyrics { get; set; } + [XmlAttribute(AttributeName = "transcoderPhoto")] + public string TranscoderPhoto { get; set; } + [XmlAttribute(AttributeName = "transcoderSubtitles")] + public string TranscoderSubtitles { get; set; } + [XmlAttribute(AttributeName = "transcoderVideo")] + public string TranscoderVideo { get; set; } + [XmlAttribute(AttributeName = "transcoderVideoBitrates")] + public string TranscoderVideoBitrates { get; set; } + [XmlAttribute(AttributeName = "transcoderVideoQualities")] + public string TranscoderVideoQualities { get; set; } + [XmlAttribute(AttributeName = "transcoderVideoResolutions")] + public string TranscoderVideoResolutions { get; set; } + [XmlAttribute(AttributeName = "updatedAt")] + public string UpdatedAt { get; set; } + [XmlAttribute(AttributeName = "version")] + public string Version { get; set; } + } +} diff --git a/PlexRequests.Api.Models/Plex/PlexUserRequest.cs b/PlexRequests.Api.Models/Plex/PlexUserRequest.cs index eaa517000..a466740e4 100644 --- a/PlexRequests.Api.Models/Plex/PlexUserRequest.cs +++ b/PlexRequests.Api.Models/Plex/PlexUserRequest.cs @@ -25,7 +25,7 @@ // ************************************************************************/ #endregion -namespace PlexRequests.Api.Models +namespace PlexRequests.Api.Models.Plex { public class PlexUserRequest { diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 79683c5fe..2255291fe 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -42,14 +42,17 @@ + + + diff --git a/PlexRequests.Api.Models/Properties/AssemblyInfo.cs b/PlexRequests.Api.Models/Properties/AssemblyInfo.cs index 2774b1281..8115a2543 100644 --- a/PlexRequests.Api.Models/Properties/AssemblyInfo.cs +++ b/PlexRequests.Api.Models/Properties/AssemblyInfo.cs @@ -34,3 +34,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Api.Models/Sonarr/SystemStatus.cs b/PlexRequests.Api.Models/Sonarr/SystemStatus.cs new file mode 100644 index 000000000..19d822805 --- /dev/null +++ b/PlexRequests.Api.Models/Sonarr/SystemStatus.cs @@ -0,0 +1,51 @@ +#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 isMonoRuntime { get; set; } + public bool isMono { get; set; } + public bool isLinux { get; set; } + public bool isOsx { get; set; } + public bool isWindows { get; set; } + public string branch { get; set; } + public string authentication { get; set; } + public string sqliteVersion { get; set; } + public string urlBase { get; set; } + public string runtimeVersion { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api/ApiRequest.cs b/PlexRequests.Api/ApiRequest.cs index f90aec7cf..f1a2c11d0 100644 --- a/PlexRequests.Api/ApiRequest.cs +++ b/PlexRequests.Api/ApiRequest.cs @@ -95,10 +95,17 @@ namespace PlexRequests.Api throw new ApplicationException(message, response.ErrorException); } - var json = JsonConvert.DeserializeObject(response.Content); - - return json; + try + { + var json = JsonConvert.DeserializeObject(response.Content); + return json; + } + catch (Exception e) + { + Log.Fatal(e); + throw; + } } public T DeserializeXml(string input) diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index 0f8e91fcd..bdb238ee2 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -30,6 +30,8 @@ using Newtonsoft.Json.Linq; using NLog; using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models.Movie; + using RestSharp; namespace PlexRequests.Api @@ -71,5 +73,25 @@ namespace PlexRequests.Api } return false; } + + /// + /// Gets the status. + /// + /// The URL. + /// The API key. + /// + public CouchPotatoStatus GetStatus(Uri url, string apiKey) + { + Log.Trace("Getting CP Status, ApiKey = {0}", apiKey); + var request = new RestRequest + { + Resource = "api/{apikey}/app.available/", + Method = Method.GET + }; + + request.AddUrlSegment("apikey", apiKey); + + return Api.Execute(request,url); + } } } \ No newline at end of file diff --git a/PlexRequests.Api/Mocks/MockSonarrApi.cs b/PlexRequests.Api/Mocks/MockSonarrApi.cs index 1d9622467..8508d5a13 100644 --- a/PlexRequests.Api/Mocks/MockSonarrApi.cs +++ b/PlexRequests.Api/Mocks/MockSonarrApi.cs @@ -50,5 +50,10 @@ namespace PlexRequests.Api.Mocks var obj = JsonConvert.DeserializeObject(json); return obj; } + + public SystemStatus SystemStatus(string apiKey, Uri baseUrl) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/PlexRequests.Api/PlexApi.cs b/PlexRequests.Api/PlexApi.cs index cf31ce53e..2308910b7 100644 --- a/PlexRequests.Api/PlexApi.cs +++ b/PlexRequests.Api/PlexApi.cs @@ -115,6 +115,25 @@ namespace PlexRequests.Api return search; } + + public PlexStatus GetStatus(string authToken, Uri uri) + { + var request = new RestRequest + { + Method = Method.GET, + }; + + request.AddHeader("X-Plex-Client-Identifier", "Test213"); + request.AddHeader("X-Plex-Product", "Request Plex"); + request.AddHeader("X-Plex-Version", Version); + request.AddHeader("X-Plex-Token", authToken); + request.AddHeader("Content-Type", "application/xml"); + + var api = new ApiRequest(); + var users = api.ExecuteXml(request, uri); + + return users; + } } } diff --git a/PlexRequests.Api/Properties/AssemblyInfo.cs b/PlexRequests.Api/Properties/AssemblyInfo.cs index bf8845186..e09af95eb 100644 --- a/PlexRequests.Api/Properties/AssemblyInfo.cs +++ b/PlexRequests.Api/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] 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.Core.Tests/PlexRequests.Core.Tests.csproj b/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj index bbcac92ee..7674966ff 100644 --- a/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj +++ b/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj @@ -59,6 +59,7 @@ + @@ -71,6 +72,10 @@ {DD7DC444-D3BF-4027-8AB9-EFC71F5EC581} PlexRequests.Core + + {1252336D-42A3-482A-804C-836E60173DFA} + PlexRequests.Helpers + diff --git a/PlexRequests.Core.Tests/Properties/AssemblyInfo.cs b/PlexRequests.Core.Tests/Properties/AssemblyInfo.cs index 874fc2052..1cc04fc46 100644 --- a/PlexRequests.Core.Tests/Properties/AssemblyInfo.cs +++ b/PlexRequests.Core.Tests/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Core.Tests/StatusCheckerTests.cs b/PlexRequests.Core.Tests/StatusCheckerTests.cs new file mode 100644 index 000000000..e45b4dcab --- /dev/null +++ b/PlexRequests.Core.Tests/StatusCheckerTests.cs @@ -0,0 +1,45 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AuthenticationSettingsTests.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 + +using System; +using NUnit.Framework; + +namespace PlexRequests.Core.Tests +{ + [TestFixture] + public class StatusCheckerTests + { + [Test] + public void CheckStatusTest() + { + var checker = new StatusChecker(); + var status = checker.GetStatus(); + + Assert.That(status, Is.Not.Null); + } + } +} \ No newline at end of file diff --git a/PlexRequests.Core.Tests/app.config b/PlexRequests.Core.Tests/app.config index 7503b02ee..ee433ca9b 100644 --- a/PlexRequests.Core.Tests/app.config +++ b/PlexRequests.Core.Tests/app.config @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/PlexRequests.Core/Models/StatusModel.cs b/PlexRequests.Core/Models/StatusModel.cs new file mode 100644 index 000000000..33d8f0fe1 --- /dev/null +++ b/PlexRequests.Core/Models/StatusModel.cs @@ -0,0 +1,37 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StatusModel.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.Core.Models +{ + public class StatusModel + { + public string Version { get; set; } + public bool UpdateAvailable { get; set; } + public int ReleasesBehind { get; set; } + public string UpdateUri { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index 79aca698c..eb20f81d1 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -46,6 +46,10 @@ ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True + + ..\packages\Octokit.0.19.0\lib\net45\Octokit.dll + True + ..\packages\valueinjecter.3.1.1.2\lib\net40\Omu.ValueInjecter.dll True @@ -66,6 +70,7 @@ + @@ -77,6 +82,7 @@ + diff --git a/PlexRequests.Core/Properties/AssemblyInfo.cs b/PlexRequests.Core/Properties/AssemblyInfo.cs index 9ecb23fff..c72e6cfae 100644 --- a/PlexRequests.Core/Properties/AssemblyInfo.cs +++ b/PlexRequests.Core/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Core/StatusChecker.cs b/PlexRequests.Core/StatusChecker.cs new file mode 100644 index 000000000..52b135312 --- /dev/null +++ b/PlexRequests.Core/StatusChecker.cs @@ -0,0 +1,78 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StatusChecker.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 +using System; +using System.Linq; +using System.Reflection; +using System.Runtime.Versioning; +using System.Threading.Tasks; + +using Octokit; + +using PlexRequests.Core.Models; +using PlexRequests.Helpers; + +namespace PlexRequests.Core +{ + public class StatusChecker + { + public StatusChecker() + { + Git = new GitHubClient(new ProductHeaderValue("PlexRequests-StatusChecker")); + } + private IGitHubClient Git { get; } + private const string Owner = "tidusjar"; + private const string RepoName = "PlexRequests.Net"; + + public async Task GetLatestRelease() + { + var releases = await Git.Repository.Release.GetAll(Owner, RepoName); + return releases.FirstOrDefault(); + } + + public StatusModel GetStatus() + { + var assemblyVersion = AssemblyHelper.GetProductVersion(); + var model = new StatusModel + { + Version = assemblyVersion, + }; + + var latestRelease = GetLatestRelease(); + + var latestVersionArray = latestRelease.Result.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries); + var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty; + + if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase)) + { + model.UpdateAvailable = true; + model.UpdateUri = latestRelease.Result.HtmlUrl; + } + + return model; + } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/app.config b/PlexRequests.Core/app.config index 7503b02ee..ee433ca9b 100644 --- a/PlexRequests.Core/app.config +++ b/PlexRequests.Core/app.config @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/PlexRequests.Core/packages.config b/PlexRequests.Core/packages.config index 2d5fcc6ef..ddcb2361b 100644 --- a/PlexRequests.Core/packages.config +++ b/PlexRequests.Core/packages.config @@ -3,5 +3,6 @@ + \ No newline at end of file diff --git a/PlexRequests.Helpers.Tests/AssemblyHelperTests.cs b/PlexRequests.Helpers.Tests/AssemblyHelperTests.cs new file mode 100644 index 000000000..b55443e61 --- /dev/null +++ b/PlexRequests.Helpers.Tests/AssemblyHelperTests.cs @@ -0,0 +1,41 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AssemblyHelperTests.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 +using NUnit.Framework; + +namespace PlexRequests.Helpers.Tests +{ + [TestFixture] + public class AssemblyHelperTests + { + [Test] + public void GetReleaseVersionTest() + { + var result = AssemblyHelper.GetProductVersion(); + Assert.That(result, Is.Not.Null); + } + } +} \ No newline at end of file diff --git a/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj b/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj index 0fa7e92d8..54af6aebe 100644 --- a/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj +++ b/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj @@ -35,14 +35,6 @@ 4 - - ..\packages\Hangfire.Core.1.5.3\lib\net45\Hangfire.Core.dll - True - - - ..\packages\Hangfire.SqlServer.1.5.3\lib\net45\Hangfire.SqlServer.dll - True - ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll True @@ -78,6 +70,7 @@ + diff --git a/PlexRequests.Helpers.Tests/Properties/AssemblyInfo.cs b/PlexRequests.Helpers.Tests/Properties/AssemblyInfo.cs index 66ce11c94..1bebc4548 100644 --- a/PlexRequests.Helpers.Tests/Properties/AssemblyInfo.cs +++ b/PlexRequests.Helpers.Tests/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Helpers/AssemblyHelper.cs b/PlexRequests.Helpers/AssemblyHelper.cs index a2a1b6163..6c450bda8 100644 --- a/PlexRequests.Helpers/AssemblyHelper.cs +++ b/PlexRequests.Helpers/AssemblyHelper.cs @@ -37,5 +37,13 @@ namespace PlexRequests.Helpers var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); return fvi.FileVersion; } + + public static string GetProductVersion() + { + var assembly = Assembly.GetExecutingAssembly(); + var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); + var retVersion = fvi.ProductVersion; + return retVersion; + } } } \ No newline at end of file diff --git a/PlexRequests.Helpers/Properties/AssemblyInfo.cs b/PlexRequests.Helpers/Properties/AssemblyInfo.cs index 2001ed779..e1d4fa2db 100644 --- a/PlexRequests.Helpers/Properties/AssemblyInfo.cs +++ b/PlexRequests.Helpers/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")] diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs new file mode 100644 index 000000000..ed70fcf7d --- /dev/null +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -0,0 +1,103 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexAvailabilityCheckerTests.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 +using System; +using System.Collections.Generic; + +using Moq; + +using NUnit.Framework; + +using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models; +using PlexRequests.Api.Models.Plex; +using PlexRequests.Core; +using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers.Exceptions; +using PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services.Tests +{ + [TestFixture] + public class PlexAvailabilityCheckerTests + { + public IAvailabilityChecker Checker { get; set; } + + [Test] + public void IsAvailableWithEmptySettingsTest() + { + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); + + Assert.Throws(() => Checker.IsAvailable("title"), "We should be throwing an exception since we cannot talk to the services."); + } + + [Test] + public void IsAvailableTest() + { + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + + var searchResult = new PlexSearch {Video = new List