mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
Add missing On Delete Notifications to Mailgun notifications
(cherry picked from commit a824fa44d21328d9c8bbb1ccfd6d247d4ff5c888)
This commit is contained in:
parent
5c0ee04271
commit
b9abc1be11
@ -9,7 +9,7 @@ public class MailGun : NotificationBase<MailgunSettings>
|
|||||||
{
|
{
|
||||||
private readonly IMailgunProxy _proxy;
|
private readonly IMailgunProxy _proxy;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public MailGun(IMailgunProxy proxy, Logger logger)
|
public MailGun(IMailgunProxy proxy, Logger logger)
|
||||||
{
|
{
|
||||||
_proxy = proxy;
|
_proxy = proxy;
|
||||||
@ -29,6 +29,20 @@ public override void OnDownload(DownloadMessage downloadMessage)
|
|||||||
_proxy.SendNotification(MOVIE_GRABBED_TITLE, downloadMessage.Message, Settings);
|
_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)
|
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheckMessage)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheckMessage.Message, Settings);
|
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheckMessage.Message, Settings);
|
||||||
@ -41,7 +55,7 @@ public override ValidationResult Test()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const string title = "Test Notification";
|
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);
|
_proxy.SendNotification(title, body, Settings);
|
||||||
_logger.Info("Successsfully sent email though Mailgun.");
|
_logger.Info("Successsfully sent email though Mailgun.");
|
||||||
@ -51,7 +65,7 @@ public override ValidationResult Test()
|
|||||||
_logger.Error(ex, "Unable to send test message though Mailgun.");
|
_logger.Error(ex, "Unable to send test message though Mailgun.");
|
||||||
failures.Add(new ValidationFailure("", "Unable to send test message though Mailgun."));
|
failures.Add(new ValidationFailure("", "Unable to send test message though Mailgun."));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
return new ValidationResult(failures);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,14 @@ namespace NzbDrone.Core.Notifications.Mailgun
|
|||||||
{
|
{
|
||||||
public class MailgunException : NzbDroneException
|
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)
|
public MailgunException(string message, Exception innerException, params object[] args)
|
||||||
: base(message, innerException, args) { }
|
: base(message, innerException, args)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using HttpMethod = NzbDrone.Common.Http.HttpMethod;
|
using HttpMethod = NzbDrone.Common.Http.HttpMethod;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Mailgun {
|
namespace NzbDrone.Core.Notifications.Mailgun
|
||||||
|
{
|
||||||
public interface IMailgunProxy
|
public interface IMailgunProxy
|
||||||
{
|
{
|
||||||
void SendNotification(string tittle, string message, MailgunSettings settings);
|
void SendNotification(string title, string message, MailgunSettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MailgunProxy : IMailgunProxy
|
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 BaseUrlEu = "https://api.eu.mailgun.net/v3";
|
||||||
private const string BaseUrlUs = "https://api.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)
|
public MailgunProxy(IHttpClient httpClient, Logger logger)
|
||||||
{
|
{
|
||||||
@ -27,42 +27,41 @@ public void SendNotification(string title, string message, MailgunSettings setti
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.POST,
|
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.POST, title, message).Build();
|
||||||
title, message).Build();
|
|
||||||
_httpClient.Execute(request);
|
_httpClient.Execute(request);
|
||||||
}
|
}
|
||||||
catch (HttpException ex)
|
catch (HttpException ex)
|
||||||
{
|
{
|
||||||
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
|
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);
|
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 loginCredentials = new NetworkCredential("api", settings.ApiKey);
|
||||||
var url = settings.UseEuEndpoint ? BaseUrlEu : BaseUrlUs;
|
var url = settings.UseEuEndpoint ? BaseUrlEu : BaseUrlUs;
|
||||||
var requestBuilder = new HttpRequestBuilder(url).Resource(resource);
|
var requestBuilder = new HttpRequestBuilder(url).Resource(resource);
|
||||||
|
|
||||||
requestBuilder.Method = method;
|
requestBuilder.Method = method;
|
||||||
requestBuilder.NetworkCredential = loginCredentials;
|
requestBuilder.NetworkCredential = loginCredentials;
|
||||||
|
|
||||||
requestBuilder.AddFormParameter("from", $"{settings.From}");
|
requestBuilder.AddFormParameter("from", $"{settings.From}");
|
||||||
|
|
||||||
foreach (var recipient in settings.Recipients)
|
foreach (var recipient in settings.Recipients)
|
||||||
{
|
{
|
||||||
requestBuilder.AddFormParameter("to", $"{recipient}");
|
requestBuilder.AddFormParameter("to", $"{recipient}");
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBuilder.AddFormParameter("subject", $"{messageSubject}");
|
requestBuilder.AddFormParameter("subject", $"{messageSubject}");
|
||||||
requestBuilder.AddFormParameter("text", $"{messageBody}");
|
requestBuilder.AddFormParameter("text", $"{messageBody}");
|
||||||
|
|
||||||
return requestBuilder;
|
return requestBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public MailGunSettingsValidator()
|
|||||||
RuleFor(c => c.Recipients).NotEmpty();
|
RuleFor(c => c.Recipients).NotEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MailgunSettings : IProviderConfig
|
public class MailgunSettings : IProviderConfig
|
||||||
{
|
{
|
||||||
private static readonly MailGunSettingsValidator Validator = new MailGunSettingsValidator();
|
private static readonly MailGunSettingsValidator Validator = new MailGunSettingsValidator();
|
||||||
@ -24,20 +24,19 @@ public MailgunSettings()
|
|||||||
{
|
{
|
||||||
Recipients = new string[] { };
|
Recipients = new string[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")]
|
[FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")]
|
||||||
public string ApiKey { get; set; }
|
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; }
|
public bool UseEuEndpoint { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(2, Label = "From Address")]
|
[FieldDefinition(2, Label = "From Address")]
|
||||||
public string From { get; set; }
|
public string From { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(3, Label = "Sender Domain")]
|
[FieldDefinition(3, Label = "Sender Domain")]
|
||||||
public string SenderDomain { get; set; }
|
public string SenderDomain { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(4, Label = "Recipient Address(es)", Type = FieldType.Tag)]
|
[FieldDefinition(4, Label = "Recipient Address(es)", Type = FieldType.Tag)]
|
||||||
public IEnumerable<string> Recipients { get; set; }
|
public IEnumerable<string> Recipients { get; set; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user