diff --git a/src/NzbDrone.Core/Datastore/Migration/017_remove_nma.cs b/src/NzbDrone.Core/Datastore/Migration/017_remove_nma.cs new file mode 100644 index 000000000..530506dc4 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/017_remove_nma.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(17)] + public class remove_nma : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("DELETE FROM Notifications WHERE Implementation = 'Notify My Android';"); + } + } +} diff --git a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs b/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs deleted file mode 100644 index c642ad360..000000000 --- a/src/NzbDrone.Core/Notifications/NotifyMyAndroid/NotifyMyAndroid.cs +++ /dev/null @@ -1,43 +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(ALBUM_GRABBED_TITLE, grabMessage.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority); - } - - public override void OnDownload(TrackDownloadMessage message) - { - _proxy.SendNotification(TRACK_DOWNLOADED_TITLE, message.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority); - } - - public override void OnAlbumDownload(AlbumDownloadMessage message) - { - _proxy.SendNotification(ALBUM_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 402f7f239..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", "Lidarr"); - 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 Lidarr"; - 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/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index cddd548f9..c44c8ffb1 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -188,6 +188,7 @@ + @@ -993,10 +994,6 @@ - - - - Code