From d05d76be4bb9216942eeff0e2891d6ad786b7a85 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 14 Oct 2017 22:49:14 +0100 Subject: [PATCH] Finished the couchpotato settings --- src/Ombi.Api.CouchPotato/CouchPotatoApi.cs | 2 +- .../ClientApp/app/interfaces/ICouchPotato.ts | 2 +- .../services/applications/tester.service.ts | 6 ++++- .../couchpotato/couchpotato.component.html | 4 +-- .../couchpotato/couchpotato.component.ts | 12 ++++++--- .../app/settings/settingsmenu.component.html | 4 +-- .../Controllers/External/TesterController.cs | 27 ++++++++++++++++++- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/Ombi.Api.CouchPotato/CouchPotatoApi.cs b/src/Ombi.Api.CouchPotato/CouchPotatoApi.cs index 8980c4b11..36d4b0528 100644 --- a/src/Ombi.Api.CouchPotato/CouchPotatoApi.cs +++ b/src/Ombi.Api.CouchPotato/CouchPotatoApi.cs @@ -74,7 +74,7 @@ namespace Ombi.Api.CouchPotato public async Task GetApiKey(string baseUrl, string username, string password) { - var request = new Request("getkey/",baseUrl, HttpMethod.Get); + var request = new Request("getkey",baseUrl, HttpMethod.Get); request.AddQueryString("u",username.CalcuateMd5Hash()); request.AddQueryString("p",password.CalcuateMd5Hash()); diff --git a/src/Ombi/ClientApp/app/interfaces/ICouchPotato.ts b/src/Ombi/ClientApp/app/interfaces/ICouchPotato.ts index fb22cd0c0..8ce971b64 100644 --- a/src/Ombi/ClientApp/app/interfaces/ICouchPotato.ts +++ b/src/Ombi/ClientApp/app/interfaces/ICouchPotato.ts @@ -21,5 +21,5 @@ export interface IProfileList { export interface ICouchPotatoApiKey { success: boolean; - apiKey: string; + api_key: string; } diff --git a/src/Ombi/ClientApp/app/services/applications/tester.service.ts b/src/Ombi/ClientApp/app/services/applications/tester.service.ts index 98a4e1e79..c4f36a0b0 100644 --- a/src/Ombi/ClientApp/app/services/applications/tester.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/tester.service.ts @@ -6,6 +6,7 @@ import { Observable } from "rxjs/Rx"; import { ServiceAuthHelpers } from "../service.helpers"; import { + ICouchPotatoSettings, IDiscordNotifcationSettings, IEmailNotificationSettings, IEmbyServer, @@ -15,7 +16,7 @@ import { IPushoverNotificationSettings, IRadarrSettings, ISlackNotificationSettings, - ISonarrSettings, + ISonarrSettings } from "../../interfaces"; @Injectable() @@ -57,5 +58,8 @@ export class TesterService extends ServiceAuthHelpers { } public sonarrTest(settings: ISonarrSettings): Observable { return this.http.post(`${this.url}sonarr`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + } + public couchPotatoTest(settings: ICouchPotatoSettings): Observable { + return this.http.post(`${this.url}couchpotato`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); } } diff --git a/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.html b/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.html index 6dd87155b..ae8f7bb6f 100644 --- a/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.html +++ b/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.html @@ -58,10 +58,10 @@
- +
- +
diff --git a/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.ts b/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.ts index 1d680600a..3edfa7f42 100644 --- a/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.ts +++ b/src/Ombi/ClientApp/app/settings/couchpotato/couchpotato.component.ts @@ -34,6 +34,10 @@ export class CouchPotatoComponent implements OnInit { subDir: [x.subDir], defaultProfileId: [x.defaultProfileId], }); + + if(x.defaultProfileId) { + this.getProfiles(this.form); + } }); } @@ -68,11 +72,11 @@ export class CouchPotatoComponent implements OnInit { return; } const settings = form.value; - this.testerService.radarrTest(settings).subscribe(x => { + this.testerService.couchPotatoTest(settings).subscribe(x => { if (x === true) { - this.notificationService.success("Connected", "Successfully connected to Radarr!"); + this.notificationService.success("Connected", "Successfully connected to CouchPotato!"); } else { - this.notificationService.error("Connected", "We could not connect to Radarr!"); + this.notificationService.error("Connected", "We could not connect to CouchPotato!"); } }); } @@ -80,7 +84,7 @@ export class CouchPotatoComponent implements OnInit { public requestToken(form: FormGroup) { this.couchPotatoService.getApiKey(form.value).subscribe(x => { if (x.success === true) { - (this.form.controls.apiKey).setValue(x.apiKey); + (this.form.controls.apiKey).setValue(x.api_key); this.notificationService.success("Api Key", "Successfully got the Api Key"); } else { this.notificationService.error("Api Key", "Could not get the Api Key"); diff --git a/src/Ombi/ClientApp/app/settings/settingsmenu.component.html b/src/Ombi/ClientApp/app/settings/settingsmenu.component.html index 2084d1f12..b9268dfa4 100644 --- a/src/Ombi/ClientApp/app/settings/settingsmenu.component.html +++ b/src/Ombi/ClientApp/app/settings/settingsmenu.component.html @@ -72,8 +72,8 @@ diff --git a/src/Ombi/Controllers/External/TesterController.cs b/src/Ombi/Controllers/External/TesterController.cs index 3fc1b6092..0acdf9d9e 100644 --- a/src/Ombi/Controllers/External/TesterController.cs +++ b/src/Ombi/Controllers/External/TesterController.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Hangfire; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Ombi.Api.CouchPotato; using Ombi.Api.Emby; using Ombi.Api.Plex; using Ombi.Api.Radarr; @@ -44,9 +45,11 @@ namespace Ombi.Controllers.External /// The pushover. /// The mattermost. /// The logger. + /// public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN, IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm, - IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger log, IEmailProvider provider) + IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger log, IEmailProvider provider, + ICouchPotatoApi cpApi) { Service = service; DiscordNotification = notification; @@ -61,6 +64,7 @@ namespace Ombi.Controllers.External SonarrApi = sonarr; Log = log; EmailProvider = provider; + CouchPotatoApi = cpApi; } private INotificationService Service { get; } @@ -74,6 +78,7 @@ namespace Ombi.Controllers.External private IRadarrApi RadarrApi { get; } private IEmbyApi EmbyApi { get; } private ISonarrApi SonarrApi { get; } + private ICouchPotatoApi CouchPotatoApi { get; } private ILogger Log { get; } private IEmailProvider EmailProvider { get; } @@ -266,5 +271,25 @@ namespace Ombi.Controllers.External return false; } } + + /// + /// Checks if we can connect to Sonarr with the provided settings + /// + /// + /// + [HttpPost("couchpotato")] + public async Task CouchPotato([FromBody] CouchPotatoSettings settings) + { + try + { + var result = await CouchPotatoApi.Status(settings.FullUri, settings.ApiKey); + return result?.success ?? false; + } + catch (Exception e) + { + Log.LogError(LoggingEvents.Api, e, "Could not test CP"); + return false; + } + } } } \ No newline at end of file