1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 12:32:31 +01:00

Fixed: Removed NotifyMyAndroid and Pushalot

Fixes #4033
Tack onto migration 164
This commit is contained in:
Qstick 2020-01-15 22:39:42 -05:00
parent ccc77bfcfe
commit 16c03444ab
10 changed files with 3 additions and 390 deletions

View File

@ -23,6 +23,9 @@ protected override void MainDbUpgrade()
.WithColumn("Type").AsInt32(); .WithColumn("Type").AsInt32();
Create.Index().OnTable("Credits").OnColumn("MovieId"); Create.Index().OnTable("Credits").OnColumn("MovieId");
Delete.FromTable("Notifications").Row(new { Implementation = "NotifyMyAndroid" });
Delete.FromTable("Notifications").Row(new { Implementation = "Pushalot" });
} }
} }
} }

View File

@ -1,48 +0,0 @@
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
public class NotifyMyAndroid : NotificationBase<NotifyMyAndroidSettings>
{
private readonly INotifyMyAndroidProxy _proxy;
public NotifyMyAndroid(INotifyMyAndroidProxy proxy)
{
_proxy = proxy;
}
public override string Link => "http://www.notifymyandroid.com/";
public override void OnGrab(GrabMessage grabMessage)
{
const string title = "Movie Grabbed";
_proxy.SendNotification(title, grabMessage.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Movie Downloaded";
_proxy.SendNotification(title, message.Message, Settings.ApiKey, (NotifyMyAndroidPriority)Settings.Priority);
}
public override void OnMovieRename(Movie movie)
{
}
public override string Name => "Notify My Android";
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_proxy.Test(Settings));
return new ValidationResult(failures);
}
}
}

View File

@ -1,11 +0,0 @@
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
public enum NotifyMyAndroidPriority
{
VeryLow = -2,
Moderate = -1,
Normal = 0,
High = 1,
Emergency = 2
}
}

View File

@ -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 NzbDrone.Core.Rest;
using RestSharp;
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 const string URL = "https://www.notifymyandroid.com/publicapi";
private readonly Logger _logger;
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", "Radarr");
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 Radarr";
Verify(settings.ApiKey);
SendNotification(title, body, settings.ApiKey, (NotifyMyAndroidPriority)settings.Priority);
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send test message: " + ex.Message);
return new ValidationFailure("ApiKey", "Unable to send test message");
}
return null;
}
}
}

View File

@ -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));
}
}
}

View File

@ -1,48 +0,0 @@
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.Pushalot
{
public class Pushalot : NotificationBase<PushalotSettings>
{
private readonly IPushalotProxy _proxy;
public Pushalot(IPushalotProxy proxy)
{
_proxy = proxy;
}
public override string Link => "https://www.Pushalot.com/";
public override void OnGrab(GrabMessage grabMessage)
{
const string title = "Movie Grabbed";
_proxy.SendNotification(title, grabMessage.Message, Settings);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Movie Downloaded";
_proxy.SendNotification(title, message.Message, Settings);
}
public override void OnMovieRename(Movie movie)
{
}
public override string Name => "Pushalot";
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_proxy.Test(Settings));
return new ValidationResult(failures);
}
}
}

View File

@ -1,9 +0,0 @@
namespace NzbDrone.Core.Notifications.Pushalot
{
public enum PushalotPriority
{
Silent = -1,
Normal = 0,
Important = 1
}
}

View File

@ -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 const string URL = "https://pushalot.com/api/sendmessage";
private readonly Logger _logger;
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", "Radarr");
if (settings.Image)
{
request.AddParameter("Image", "https://raw.githubusercontent.com/Radarr/Radarr/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 Radarr";
SendNotification(title, body, settings);
}
catch (RestException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Error(ex, "Authentication Token is invalid: " + ex.Message);
return new ValidationFailure("AuthToken", "Authentication Token is invalid");
}
if (ex.Response.StatusCode == HttpStatusCode.NotAcceptable)
{
_logger.Error(ex, "Message limit reached: " + ex.Message);
return new ValidationFailure("AuthToken", "Message limit reached");
}
if (ex.Response.StatusCode == HttpStatusCode.Gone)
{
_logger.Error(ex, "Authorization Token is no longer valid: " + ex.Message);
return new ValidationFailure("AuthToken", "Authorization Token is no longer valid, please use a new one.");
}
var response = Json.Deserialize<PushalotResponse>(ex.Response.Content);
_logger.Error(ex, "Unable to send test message: " + ex.Message);
return new ValidationFailure("AuthToken", response.Description);
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send test message: " + ex.Message);
return new ValidationFailure("", "Unable to send test message");
}
return null;
}
}
}

View File

@ -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; }
}
}

View File

@ -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<PushalotSettings>
{
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 Radarr logo with notifications")]
public bool Image { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(AuthToken);
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}