mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
Chagned: Remove NMA Notifications (#371)
This commit is contained in:
parent
3344810653
commit
ff77eab156
6 changed files with 15 additions and 176 deletions
14
src/NzbDrone.Core/Datastore/Migration/017_remove_nma.cs
Normal file
14
src/NzbDrone.Core/Datastore/Migration/017_remove_nma.cs
Normal file
|
@ -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';");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using FluentValidation.Results;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
|
||||
{
|
||||
public class NotifyMyAndroid : NotificationBase<NotifyMyAndroidSettings>
|
||||
{
|
||||
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<ValidationFailure>();
|
||||
|
||||
failures.AddIfNotNull(_proxy.Test(Settings));
|
||||
|
||||
return new ValidationResult(failures);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
|
||||
{
|
||||
public enum NotifyMyAndroidPriority
|
||||
{
|
||||
VeryLow = -2,
|
||||
Moderate = -1,
|
||||
Normal = 0,
|
||||
High = 1,
|
||||
Emergency = 2
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<NotifyMyAndroidSettings>
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -188,6 +188,7 @@
|
|||
<Compile Include="Datastore\Migration\012_add_release_status.cs" />
|
||||
<Compile Include="Datastore\Migration\015_remove_fanzub.cs" />
|
||||
<Compile Include="Datastore\Migration\016_update_artist_history_indexes.cs" />
|
||||
<Compile Include="Datastore\Migration\017_remove_nma.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />
|
||||
|
@ -993,10 +994,6 @@
|
|||
<Compile Include="Notifications\NotificationFactory.cs" />
|
||||
<Compile Include="Notifications\NotificationRepository.cs" />
|
||||
<Compile Include="Notifications\NotificationService.cs" />
|
||||
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroid.cs" />
|
||||
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroidPriority.cs" />
|
||||
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroidProxy.cs" />
|
||||
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroidSettings.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexClient.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue