1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Add missing On Delete Notifications to Mailgun notifications

(cherry picked from commit a824fa44d21328d9c8bbb1ccfd6d247d4ff5c888)
This commit is contained in:
Robin Dadswell 2021-04-23 15:54:15 +01:00
parent 5c0ee04271
commit b9abc1be11
4 changed files with 50 additions and 33 deletions

View File

@ -29,6 +29,20 @@ public override void OnDownload(DownloadMessage downloadMessage)
_proxy.SendNotification(MOVIE_GRABBED_TITLE, downloadMessage.Message, Settings);
}
public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
{
var body = $"{deleteMessage.Message} deleted.";
_proxy.SendNotification(MOVIE_FILE_DELETED_TITLE, body, Settings);
}
public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{
var body = $"{deleteMessage.Message}";
_proxy.SendNotification(MOVIE_DELETED_TITLE, body, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheckMessage)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheckMessage.Message, Settings);
@ -41,7 +55,7 @@ public override ValidationResult Test()
try
{
const string title = "Test Notification";
const string body = "This is a test message from Sonarr, though Mailgun.";
const string body = "This is a test message from Radarr, though Mailgun.";
_proxy.SendNotification(title, body, Settings);
_logger.Info("Successsfully sent email though Mailgun.");

View File

@ -5,9 +5,14 @@ namespace NzbDrone.Core.Notifications.Mailgun
{
public class MailgunException : NzbDroneException
{
public MailgunException(string message) : base (message) { }
public MailgunException(string message)
: base(message)
{
}
public MailgunException(string message, Exception innerException, params object[] args)
: base(message, innerException, args) { }
: base(message, innerException, args)
{
}
}
}

View File

@ -3,19 +3,19 @@
using NzbDrone.Common.Http;
using HttpMethod = NzbDrone.Common.Http.HttpMethod;
namespace NzbDrone.Core.Notifications.Mailgun {
namespace NzbDrone.Core.Notifications.Mailgun
{
public interface IMailgunProxy
{
void SendNotification(string tittle, string message, MailgunSettings settings);
void SendNotification(string title, string message, MailgunSettings settings);
}
public class MailgunProxy : IMailgunProxy
{
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
private const string BaseUrlEu = "https://api.eu.mailgun.net/v3";
private const string BaseUrlUs = "https://api.mailgun.net/v3";
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
public MailgunProxy(IHttpClient httpClient, Logger logger)
{
@ -27,24 +27,23 @@ public void SendNotification(string title, string message, MailgunSettings setti
{
try
{
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.POST,
title, message).Build();
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.POST, title, message).Build();
_httpClient.Execute(request);
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
throw new MailgunException("Unauthorised - ApiKey is invalid");
_logger.Error("Unathorized - ApiKey is invalid");
throw new MailgunException("Unauthorized - ApiKey is invalid");
}
_logger.Error(ex, "Unable to connect to Mailgun. Status code: " + ex.Message);
throw new MailgunException("Unable to connect to Mailgun. Status code: {0}", ex);
}
}
private HttpRequestBuilder BuildRequest(MailgunSettings settings, string resource, HttpMethod method,
string messageSubject, string messageBody)
private HttpRequestBuilder BuildRequest(MailgunSettings settings, string resource, HttpMethod method, string messageSubject, string messageBody)
{
var loginCredentials = new NetworkCredential("api", settings.ApiKey);
var url = settings.UseEuEndpoint ? BaseUrlEu : BaseUrlUs;

View File

@ -25,11 +25,10 @@ public MailgunSettings()
Recipients = new string[] { };
}
[FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")]
public string ApiKey { get; set; }
[FieldDefinition(1, Label = "Use EU Endpoint?", HelpText = "You can choose to use the EU MailGun endpoint with this", Type = FieldType.Checkbox)]
[FieldDefinition(1, Label = "Use EU Endpoint?", HelpText = "Use the EU MailGun endpoint", Type = FieldType.Checkbox)]
public bool UseEuEndpoint { get; set; }
[FieldDefinition(2, Label = "From Address")]