From add4e86d4952d16a3b0607bcb80a2e1bf91f3a29 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 4 Jan 2017 08:24:50 +0000 Subject: [PATCH] More work on watcher, should all be good now. #878 --- Ombi.Api.Interfaces/IWatcherApi.cs | 1 + Ombi.Api.Models/Ombi.Api.Models.csproj | 1 + Ombi.Api.Models/Watcher/WatcherVersion.cs | 35 ++++++++++++++++++++++ Ombi.Api/WatcherApi.cs | 17 +++++++++++ Ombi.UI/Modules/ApplicationTesterModule.cs | 4 +-- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 Ombi.Api.Models/Watcher/WatcherVersion.cs diff --git a/Ombi.Api.Interfaces/IWatcherApi.cs b/Ombi.Api.Interfaces/IWatcherApi.cs index c747769ed..38dc042ae 100644 --- a/Ombi.Api.Interfaces/IWatcherApi.cs +++ b/Ombi.Api.Interfaces/IWatcherApi.cs @@ -36,5 +36,6 @@ namespace Ombi.Api.Interfaces WatcherAddMovieResult AddMovie(string imdbId, string apiKey, Uri baseUrl); WatcherListStatusResultContainer ListMovies(string apiKey, Uri baseUrl); WatcherListStatusResultContainer ListMovies(string apiKey, Uri baseUrl, string imdbId); + WatcherVersion Version(string apiKey, Uri baseUri); } } \ No newline at end of file diff --git a/Ombi.Api.Models/Ombi.Api.Models.csproj b/Ombi.Api.Models/Ombi.Api.Models.csproj index c44e89bf8..025115c83 100644 --- a/Ombi.Api.Models/Ombi.Api.Models.csproj +++ b/Ombi.Api.Models/Ombi.Api.Models.csproj @@ -108,6 +108,7 @@ + diff --git a/Ombi.Api.Models/Watcher/WatcherVersion.cs b/Ombi.Api.Models/Watcher/WatcherVersion.cs new file mode 100644 index 000000000..1e8936a0a --- /dev/null +++ b/Ombi.Api.Models/Watcher/WatcherVersion.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: WatcherVersion.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 Ombi.Api.Models.Watcher +{ + public class WatcherVersion + { + public string version { get; set; } + public bool response { get; set; } + public string ErrorMessage { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Api/WatcherApi.cs b/Ombi.Api/WatcherApi.cs index 42ed12e2c..08328a9d0 100644 --- a/Ombi.Api/WatcherApi.cs +++ b/Ombi.Api/WatcherApi.cs @@ -64,6 +64,23 @@ namespace Ombi.Api }; } } + public WatcherVersion Version(string apiKey, Uri baseUri) + { + var response = Send("version", apiKey, baseUri); + try + { + return JsonConvert.DeserializeObject(response.Content); + } + catch (Exception e) + { + Log.Error(e); + return new WatcherVersion + { + response = false, + ErrorMessage = e.Message + }; + } + } public WatcherListStatusResultContainer ListMovies(string apiKey, Uri baseUrl) { diff --git a/Ombi.UI/Modules/ApplicationTesterModule.cs b/Ombi.UI/Modules/ApplicationTesterModule.cs index 1fabfef12..e188848d3 100644 --- a/Ombi.UI/Modules/ApplicationTesterModule.cs +++ b/Ombi.UI/Modules/ApplicationTesterModule.cs @@ -113,8 +113,8 @@ namespace Ombi.UI.Modules } try { - var status = WatcherApi.ListMovies(settings.ApiKey, settings.FullUri); - return !status.Error + var status = WatcherApi.Version(settings.ApiKey, settings.FullUri); + return !status.response ? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Watcher successfully!" }) : Response.AsJson(new JsonResponseModel { Result = false, Message = $"Could not connect to Watcher, Error: {status.ErrorMessage}" });