From c19802c4718236b1e933b90bf4631bfbc208debc Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Sat, 25 Nov 2023 21:23:00 +0100 Subject: [PATCH] New: Remove defunct Boxcar notifications (cherry picked from commit c6ad2396bb98dc8eb1ad47bf5d066b227a47f8b5) --- .../Notifications/Boxcar/Boxcar.cs | 48 ---------- .../Notifications/Boxcar/BoxcarException.cs | 18 ---- .../Notifications/Boxcar/BoxcarProxy.cs | 96 ------------------- .../Notifications/Boxcar/BoxcarSettings.cs | 28 ------ 4 files changed, 190 deletions(-) delete mode 100644 src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs delete mode 100644 src/NzbDrone.Core/Notifications/Boxcar/BoxcarException.cs delete mode 100644 src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs delete mode 100644 src/NzbDrone.Core/Notifications/Boxcar/BoxcarSettings.cs diff --git a/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs b/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs deleted file mode 100644 index c1f616d5a..000000000 --- a/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using FluentValidation.Results; -using NzbDrone.Common.Extensions; - -namespace NzbDrone.Core.Notifications.Boxcar -{ - public class Boxcar : NotificationBase - { - private readonly IBoxcarProxy _proxy; - - public Boxcar(IBoxcarProxy proxy) - { - _proxy = proxy; - } - - public override string Link => "https://boxcar.io/client"; - public override string Name => "Boxcar"; - - public override void OnGrab(GrabMessage message) - { - _proxy.SendNotification(RELEASE_GRABBED_TITLE, message.Message, Settings); - } - - public override void OnHealthIssue(HealthCheck.HealthCheck message) - { - _proxy.SendNotification(HEALTH_ISSUE_TITLE, message.Message, Settings); - } - - public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) - { - _proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", Settings); - } - - public override void OnApplicationUpdate(ApplicationUpdateMessage message) - { - _proxy.SendNotification(APPLICATION_UPDATE_TITLE, message.Message, Settings); - } - - public override ValidationResult Test() - { - var failures = new List(); - - failures.AddIfNotNull(_proxy.Test(Settings)); - - return new ValidationResult(failures); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarException.cs b/src/NzbDrone.Core/Notifications/Boxcar/BoxcarException.cs deleted file mode 100644 index 6108d4aab..000000000 --- a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarException.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using NzbDrone.Common.Exceptions; - -namespace NzbDrone.Core.Notifications.Boxcar -{ - public class BoxcarException : NzbDroneException - { - public BoxcarException(string message) - : base(message) - { - } - - public BoxcarException(string message, Exception innerException, params object[] args) - : base(message, innerException, args) - { - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs b/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs deleted file mode 100644 index 9b60fde16..000000000 --- a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Net; -using FluentValidation.Results; -using NLog; -using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Http; - -namespace NzbDrone.Core.Notifications.Boxcar -{ - public interface IBoxcarProxy - { - void SendNotification(string title, string message, BoxcarSettings settings); - ValidationFailure Test(BoxcarSettings settings); - } - - public class BoxcarProxy : IBoxcarProxy - { - private const string URL = "https://new.boxcar.io/api/notifications"; - private readonly IHttpClient _httpClient; - private readonly Logger _logger; - - public BoxcarProxy(IHttpClient httpClient, Logger logger) - { - _httpClient = httpClient; - _logger = logger; - } - - public void SendNotification(string title, string message, BoxcarSettings settings) - { - try - { - ProcessNotification(title, message, settings); - } - catch (BoxcarException ex) - { - _logger.Error(ex, "Unable to send message"); - throw new BoxcarException("Unable to send Boxcar notifications"); - } - } - - public ValidationFailure Test(BoxcarSettings settings) - { - try - { - const string title = "Test Notification"; - const string body = "This is a test message from Prowlarr"; - - SendNotification(title, body, settings); - return null; - } - catch (HttpException ex) - { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) - { - _logger.Error(ex, "Access Token is invalid: " + ex.Message); - return new ValidationFailure("Token", "Access Token is invalid"); - } - - _logger.Error(ex, "Unable to send test message: " + ex.Message); - return new ValidationFailure("Token", "Unable to send test message"); - } - catch (Exception ex) - { - _logger.Error(ex, "Unable to send test message: " + ex.Message); - return new ValidationFailure("", "Unable to send test message"); - } - } - - private void ProcessNotification(string title, string message, BoxcarSettings settings) - { - try - { - var requestBuilder = new HttpRequestBuilder(URL).Post(); - - var request = requestBuilder.AddFormParameter("user_credentials", settings.Token) - .AddFormParameter("notification[title]", title) - .AddFormParameter("notification[long_message]", message) - .AddFormParameter("notification[source_name]", BuildInfo.AppName) - .AddFormParameter("notification[icon_url]", "https://raw.githubusercontent.com/Prowlarr/Prowlarr/develop/Logo/64.png") - .Build(); - - _httpClient.Post(request); - } - catch (HttpException ex) - { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) - { - _logger.Error(ex, "Access Token is invalid: " + ex.Message); - throw; - } - - throw new BoxcarException("Unable to send text message: " + ex.Message, ex); - } - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarSettings.cs b/src/NzbDrone.Core/Notifications/Boxcar/BoxcarSettings.cs deleted file mode 100644 index 0fec4e2b6..000000000 --- a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -using FluentValidation; -using NzbDrone.Core.Annotations; -using NzbDrone.Core.ThingiProvider; -using NzbDrone.Core.Validation; - -namespace NzbDrone.Core.Notifications.Boxcar -{ - public class BoxcarSettingsValidator : AbstractValidator - { - public BoxcarSettingsValidator() - { - RuleFor(c => c.Token).NotEmpty(); - } - } - - public class BoxcarSettings : IProviderConfig - { - private static readonly BoxcarSettingsValidator Validator = new BoxcarSettingsValidator(); - - [FieldDefinition(0, Label = "Access Token", Privacy = PrivacyLevel.ApiKey, HelpText = "Your Access Token, from your Boxcar account settings: https://new.boxcar.io/account/edit", HelpLink = "https://new.boxcar.io/account/edit")] - public string Token { get; set; } - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -}