From 62b03adb53f2888c3a04065243c1a36c38b48191 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 31 Aug 2018 19:36:38 -0700 Subject: [PATCH] Removed NotifyMyAndroid and Pushalot Fixed: Removed NotifyMyAndroid notifications Fixed: Remove Pushalot notifications --- ...y_my_android_and_pushalot_notifications.cs | 15 +++ .../NotifyMyAndroid/NotifyMyAndroid.cs | 38 ------- .../NotifyMyAndroidPriority.cs | 11 -- .../NotifyMyAndroid/NotifyMyAndroidProxy.cs | 85 -------------- .../NotifyMyAndroidSettings.cs | 33 ------ .../Notifications/Pushalot/Pushalot.cs | 40 ------- .../Pushalot/PushalotPriority.cs | 9 -- .../Notifications/Pushalot/PushalotProxy.cs | 106 ------------------ .../Pushalot/PushalotResponse.cs | 9 -- .../Pushalot/PushalotSettings.cs | 41 ------- src/NzbDrone.Core/NzbDrone.Core.csproj | 10 +- 11 files changed, 16 insertions(+), 381 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/125_remove_notify_my_android_and_pushalot_notifications.cs delete mode 100644 src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs delete mode 100644 src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidPriority.cs delete mode 100644 src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidProxy.cs delete mode 100644 src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidSettings.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/125_remove_notify_my_android_and_pushalot_notifications.cs b/src/NzbDrone.Core/Datastore/Migration/125_remove_notify_my_android_and_pushalot_notifications.cs new file mode 100644 index 000000000..86c18c1ef --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/125_remove_notify_my_android_and_pushalot_notifications.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(125)] + public class remove_notify_my_android_and_pushalot_notifications : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Delete.FromTable("Notifications").Row(new { Implementation = "NotifyMyAndroid" }); + Delete.FromTable("Notifications").Row(new { Implementation = "Pushalot" }); + } + } +} diff --git a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs b/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs deleted file mode 100644 index 693cb6537..000000000 --- a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using FluentValidation.Results; -using NzbDrone.Common.Extensions; - -namespace NzbDrone.Core.Notifications.NotifyMyAndroid -{ - public class NotifyMyAndroid : NotificationBase - { - private readonly INotifyMyAndroidProxy _proxy; - - public NotifyMyAndroid(INotifyMyAndroidProxy proxy) - { - _proxy = proxy; - } - - public override string Link => "https://www.notifymyandroid.com/"; - public override string Name => "Notify My Android"; - - public override void OnGrab(GrabMessage grabMessage) - { - _proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority); - } - - public override void OnDownload(DownloadMessage message) - { - _proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority); - } - - public override ValidationResult Test() - { - var failures = new List(); - - failures.AddIfNotNull(_proxy.Test(Settings)); - - return new ValidationResult(failures); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidPriority.cs b/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidPriority.cs deleted file mode 100644 index fd91e91d5..000000000 --- a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidPriority.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace NzbDrone.Core.Notifications.NotifyMyAndroid -{ - public enum NotifyMyAndroidPriority - { - VeryLow = -2, - Moderate = -1, - Normal = 0, - High = 1, - Emergency = 2 - } -} diff --git a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidProxy.cs b/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidProxy.cs deleted file mode 100644 index 070cf1591..000000000 --- a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidProxy.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Linq; -using System.Net; -using System.Xml.Linq; -using FluentValidation.Results; -using NLog; -using NzbDrone.Core.Exceptions; -using RestSharp; -using NzbDrone.Core.Rest; - -namespace NzbDrone.Core.Notifications.NotifyMyAndroid -{ - public interface INotifyMyAndroidProxy - { - void SendNotification(string title, string message, string apiKye, NotifyMyAndroidPriority priority); - ValidationFailure Test(NotifyMyAndroidSettings settings); - } - - public class NotifyMyAndroidProxy : INotifyMyAndroidProxy - { - private readonly Logger _logger; - private const string URL = "https://www.notifymyandroid.com/publicapi"; - - public NotifyMyAndroidProxy(Logger logger) - { - _logger = logger; - } - - public void SendNotification(string title, string message, string apiKey, NotifyMyAndroidPriority priority) - { - var client = RestClientFactory.BuildClient(URL); - var request = new RestRequest("notify", Method.POST); - request.RequestFormat = DataFormat.Xml; - request.AddParameter("apikey", apiKey); - request.AddParameter("application", "Sonarr"); - request.AddParameter("event", title); - request.AddParameter("description", message); - request.AddParameter("priority", (int)priority); - - var response = client.ExecuteAndValidate(request); - ValidateResponse(response); - } - - private void Verify(string apiKey) - { - var client = RestClientFactory.BuildClient(URL); - var request = new RestRequest("verify", Method.GET); - request.RequestFormat = DataFormat.Xml; - request.AddParameter("apikey", apiKey, ParameterType.GetOrPost); - - var response = client.ExecuteAndValidate(request); - ValidateResponse(response); - } - - private void ValidateResponse(IRestResponse response) - { - var xDoc = XDocument.Parse(response.Content); - var nma = xDoc.Descendants("nma").Single(); - var error = nma.Descendants("error").SingleOrDefault(); - - if (error != null) - { - ((HttpStatusCode)Convert.ToInt32(error.Attribute("code").Value)).VerifyStatusCode(error.Value); - } - } - - public ValidationFailure Test(NotifyMyAndroidSettings settings) - { - try - { - const string title = "Test Notification"; - const string body = "This is a test message from Sonarr"; - Verify(settings.ApiKey); - SendNotification(title, body, settings.ApiKey, (NotifyMyAndroidPriority)settings.Priority); - } - catch (Exception ex) - { - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("ApiKey", "Unable to send test message"); - } - - return null; - } - } -} diff --git a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidSettings.cs b/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidSettings.cs deleted file mode 100644 index 7dd3a96bf..000000000 --- a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroidSettings.cs +++ /dev/null @@ -1,33 +0,0 @@ -using FluentValidation; -using NzbDrone.Core.Annotations; -using NzbDrone.Core.ThingiProvider; -using NzbDrone.Core.Validation; - -namespace NzbDrone.Core.Notifications.NotifyMyAndroid -{ - public class NotifyMyAndroidSettingsValidator : AbstractValidator - { - public NotifyMyAndroidSettingsValidator() - { - RuleFor(c => c.ApiKey).NotEmpty(); - } - } - - public class NotifyMyAndroidSettings : IProviderConfig - { - private static readonly NotifyMyAndroidSettingsValidator Validator = new NotifyMyAndroidSettingsValidator(); - - [FieldDefinition(0, Label = "API Key", HelpLink = "http://www.notifymyandroid.com/")] - public string ApiKey { get; set; } - - [FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(NotifyMyAndroidPriority))] - public int Priority { get; set; } - - public bool IsValid => !string.IsNullOrWhiteSpace(ApiKey) && Priority >= -1 && Priority <= 2; - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs b/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs deleted file mode 100644 index c505034b8..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using FluentValidation.Results; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class Pushalot : NotificationBase - { - private readonly IPushalotProxy _proxy; - - public Pushalot(IPushalotProxy proxy) - { - _proxy = proxy; - } - - public override string Name => "Pushalot"; - public override string Link => "https://pushalot.com/"; - - public override void OnGrab(GrabMessage grabMessage) - { - _proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage.Message, Settings); - } - - public override void OnDownload(DownloadMessage message) - { - _proxy.SendNotification(EPISODE_DOWNLOADED_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/Pushalot/PushalotPriority.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs deleted file mode 100644 index 58effba2f..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace NzbDrone.Core.Notifications.Pushalot -{ - public enum PushalotPriority - { - Silent = -1, - Normal = 0, - Important = 1 - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs deleted file mode 100644 index 574441e65..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Net; -using FluentValidation.Results; -using NLog; -using NzbDrone.Common.Serializer; -using NzbDrone.Core.Rest; -using RestSharp; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public interface IPushalotProxy - { - void SendNotification(string title, string message, PushalotSettings settings); - ValidationFailure Test(PushalotSettings settings); - } - - public class PushalotProxy : IPushalotProxy - { - private readonly Logger _logger; - private const string URL = "https://pushalot.com/api/sendmessage"; - - public PushalotProxy(Logger logger) - { - _logger = logger; - } - - public void SendNotification(string title, string message, PushalotSettings settings) - { - var client = RestClientFactory.BuildClient(URL); - var request = BuildRequest(); - - request.AddParameter("Source", "Sonarr"); - - if (settings.Image) - { - request.AddParameter("Image", "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/128.png"); - } - - request.AddParameter("Title", title); - request.AddParameter("Body", message); - request.AddParameter("AuthorizationToken", settings.AuthToken); - - if ((PushalotPriority)settings.Priority == PushalotPriority.Important) - { - request.AddParameter("IsImportant", true); - } - - if ((PushalotPriority)settings.Priority == PushalotPriority.Silent) - { - request.AddParameter("IsSilent", true); - } - - client.ExecuteAndValidate(request); - } - - public RestRequest BuildRequest() - { - var request = new RestRequest(Method.POST); - - return request; - } - - public ValidationFailure Test(PushalotSettings settings) - { - try - { - const string title = "Test Notification"; - const string body = "This is a test message from Sonarr"; - - SendNotification(title, body, settings); - } - catch (RestException ex) - { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) - { - _logger.Error(ex, "Authentication Token is invalid"); - return new ValidationFailure("AuthToken", "Authentication Token is invalid"); - } - - if (ex.Response.StatusCode == HttpStatusCode.NotAcceptable) - { - _logger.Error(ex, "Message limit reached"); - return new ValidationFailure("AuthToken", "Message limit reached"); - } - - if (ex.Response.StatusCode == HttpStatusCode.Gone) - { - _logger.Error(ex, "Authorization Token is no longer valid"); - return new ValidationFailure("AuthToken", "Authorization Token is no longer valid, please use a new one."); - } - - var response = Json.Deserialize(ex.Response.Content); - - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("AuthToken", response.Description); - } - catch (Exception ex) - { - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("", "Unable to send test message"); - } - - return null; - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs deleted file mode 100644 index 860be65c6..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class PushalotResponse - { - public bool Success { get; set; } - public int Status { get; set; } - public string Description { get; set; } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs deleted file mode 100644 index a0fbd08e1..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs +++ /dev/null @@ -1,41 +0,0 @@ -using FluentValidation; -using NzbDrone.Core.Annotations; -using NzbDrone.Core.ThingiProvider; -using NzbDrone.Core.Validation; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class PushalotSettingsValidator : AbstractValidator - { - public PushalotSettingsValidator() - { - RuleFor(c => c.AuthToken).NotEmpty(); - } - } - - public class PushalotSettings : IProviderConfig - { - public PushalotSettings() - { - Image = true; - } - - private static readonly PushalotSettingsValidator Validator = new PushalotSettingsValidator(); - - [FieldDefinition(0, Label = "Authorization Token", HelpLink = "https://pushalot.com/manager/authorizations")] - public string AuthToken { get; set; } - - [FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushalotPriority))] - public int Priority { get; set; } - - [FieldDefinition(2, Label = "Image", Type = FieldType.Checkbox, HelpText = "Include Sonarr logo with notifications")] - public bool Image { get; set; } - - public bool IsValid => !string.IsNullOrWhiteSpace(AuthToken); - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index a985e359d..1ef0755f8 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -315,6 +315,7 @@ + @@ -1038,10 +1039,6 @@ - - - - Code @@ -1061,11 +1058,6 @@ Code - - - - -