mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 06:00:50 -07:00
Added the application tester for CP #9
This commit is contained in:
parent
334a6f3d8e
commit
4c0884999e
9 changed files with 175 additions and 3 deletions
|
@ -27,11 +27,13 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
using PlexRequests.Api.Models.Movie;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Interfaces
|
namespace PlexRequests.Api.Interfaces
|
||||||
{
|
{
|
||||||
public interface ICouchPotatoApi
|
public interface ICouchPotatoApi
|
||||||
{
|
{
|
||||||
bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl);
|
bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl);
|
||||||
|
CouchPotatoStatus GetStatus(Uri url, string apiKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
13
PlexRequests.Api.Models/Movie/CouchPotatoStatus.cs
Normal file
13
PlexRequests.Api.Models/Movie/CouchPotatoStatus.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Movie\CouchPotatoAdd.cs" />
|
<Compile Include="Movie\CouchPotatoAdd.cs" />
|
||||||
|
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
||||||
<Compile Include="Plex\PlexAuthentication.cs" />
|
<Compile Include="Plex\PlexAuthentication.cs" />
|
||||||
<Compile Include="Plex\PlexError.cs" />
|
<Compile Include="Plex\PlexError.cs" />
|
||||||
<Compile Include="Plex\PlexFriends.cs" />
|
<Compile Include="Plex\PlexFriends.cs" />
|
||||||
|
|
|
@ -30,6 +30,8 @@ using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
|
using PlexRequests.Api.Models.Movie;
|
||||||
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace PlexRequests.Api
|
namespace PlexRequests.Api
|
||||||
|
@ -71,5 +73,25 @@ namespace PlexRequests.Api
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">The URL.</param>
|
||||||
|
/// <param name="apiKey">The API key.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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<CouchPotatoStatus>(request,url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -199,6 +199,8 @@ namespace PlexRequests.UI.Modules
|
||||||
return View["CouchPotato", model];
|
return View["CouchPotato", model];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Response SaveCouchPotato()
|
private Response SaveCouchPotato()
|
||||||
{
|
{
|
||||||
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
||||||
|
|
89
PlexRequests.UI/Modules/ApplicationTesterModule.cs
Normal file
89
PlexRequests.UI/Modules/ApplicationTesterModule.cs
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: ApplicationTesterModule.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 System.Linq;
|
||||||
|
|
||||||
|
using Nancy;
|
||||||
|
using Nancy.ModelBinding;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public class ApplicationTesterModule : BaseModule
|
||||||
|
{
|
||||||
|
|
||||||
|
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi) : base("test")
|
||||||
|
{
|
||||||
|
this.RequiresAuthentication();
|
||||||
|
|
||||||
|
CpApi = cpApi;
|
||||||
|
SonarrApi = sonarrApi;
|
||||||
|
|
||||||
|
|
||||||
|
Post["/cp"] = _ => CouchPotatoTest();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
private ISonarrApi SonarrApi { get; set; }
|
||||||
|
private ICouchPotatoApi CpApi { get; }
|
||||||
|
|
||||||
|
private Response CouchPotatoTest()
|
||||||
|
{
|
||||||
|
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var status = CpApi.GetStatus(couchPotatoSettings.FullUri, couchPotatoSettings.ApiKey);
|
||||||
|
return status.success
|
||||||
|
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to CouchPotato successfully!" })
|
||||||
|
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to CouchPotato, 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 CP's status: ");
|
||||||
|
Log.Warn(e);
|
||||||
|
var message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||||
|
if (e.InnerException != null)
|
||||||
|
{
|
||||||
|
message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||||
|
}
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -166,6 +166,7 @@
|
||||||
<Compile Include="Models\SearchTvShowViewModel.cs" />
|
<Compile Include="Models\SearchTvShowViewModel.cs" />
|
||||||
<Compile Include="Models\SessionKeys.cs" />
|
<Compile Include="Models\SessionKeys.cs" />
|
||||||
<Compile Include="Modules\AdminModule.cs" />
|
<Compile Include="Modules\AdminModule.cs" />
|
||||||
|
<Compile Include="Modules\ApplicationTesterModule.cs" />
|
||||||
<Compile Include="Modules\BaseModule.cs" />
|
<Compile Include="Modules\BaseModule.cs" />
|
||||||
<Compile Include="Modules\IndexModule.cs" />
|
<Compile Include="Modules\IndexModule.cs" />
|
||||||
<Compile Include="Modules\ApprovalModule.cs" />
|
<Compile Include="Modules\ApprovalModule.cs" />
|
||||||
|
|
|
@ -39,6 +39,13 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div>
|
||||||
|
<button id="testCp" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -51,3 +58,37 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
$('#testCp').click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var $form = $("#mainForm");
|
||||||
|
$.ajax({
|
||||||
|
type: $form.prop("method"),
|
||||||
|
url: "/test/cp",
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -90,3 +90,4 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue