New: Pushover Silent and Emergency priorities

Closes #878
pull/2/head
Mark McDowall 9 years ago
parent 262b8daec1
commit 2396af4589

@ -23,14 +23,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{
const string title = "Episode Grabbed";
_proxy.SendNotification(title, grabMessage.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority, Settings.Sound);
_proxy.SendNotification(title, grabMessage.Message, Settings);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Episode Downloaded";
_proxy.SendNotification(title, message.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority, Settings.Sound);
_proxy.SendNotification(title, message.Message, Settings);
}
public override void OnRename(Series series)

@ -2,9 +2,10 @@
{
public enum PushoverPriority
{
Silent = -1,
Quiet = -1,
Normal = 0,
High = 1,
//Emergency = 2
Emergency = 2
}
}

@ -9,7 +9,7 @@ namespace NzbDrone.Core.Notifications.Pushover
{
public interface IPushoverProxy
{
void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound);
void SendNotification(string title, string message, PushoverSettings settings);
ValidationFailure Test(PushoverSettings settings);
}
@ -23,17 +23,26 @@ namespace NzbDrone.Core.Notifications.Pushover
_logger = logger;
}
public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound)
public void SendNotification(string title, string message, PushoverSettings settings)
{
var client = RestClientFactory.BuildClient(URL);
var request = new RestRequest(Method.POST);
request.AddParameter("token", apiKey);
request.AddParameter("user", userKey);
request.AddParameter("token", settings.ApiKey);
request.AddParameter("user", settings.UserKey);
request.AddParameter("title", title);
request.AddParameter("message", message);
request.AddParameter("priority", (int)priority);
request.AddParameter("priority", settings.Priority);
if (!sound.IsNullOrWhiteSpace()) request.AddParameter("sound", sound);
if ((PushoverPriority)settings.Priority == PushoverPriority.Emergency)
{
request.AddParameter("retry", settings.Retry);
request.AddParameter("expire", settings.Expire);
}
if (!settings.Sound.IsNullOrWhiteSpace())
{
request.AddParameter("sound", settings.Sound);
}
client.ExecuteAndValidate(request);
@ -46,7 +55,7 @@ namespace NzbDrone.Core.Notifications.Pushover
const string title = "Test Notification";
const string body = "This is a test message from Sonarr";
SendNotification(title, body, settings.ApiKey, settings.UserKey, (PushoverPriority)settings.Priority, settings.Sound);
SendNotification(title, body, settings);
}
catch (Exception ex)
{

@ -1,5 +1,4 @@
using System;
using FluentValidation;
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
@ -11,6 +10,8 @@ namespace NzbDrone.Core.Notifications.Pushover
public PushoverSettingsValidator()
{
RuleFor(c => c.UserKey).NotEmpty();
RuleFor(c => c.Retry).GreaterThanOrEqualTo(30).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency);
RuleFor(c => c.Retry).GreaterThanOrEqualTo(0).LessThanOrEqualTo(86400).When(c => (PushoverPriority)c.Priority == PushoverPriority.Emergency);
}
}
@ -33,7 +34,13 @@ namespace NzbDrone.Core.Notifications.Pushover
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
public int Priority { get; set; }
[FieldDefinition(3, Label = "Sound", Type = FieldType.Textbox, HelpText = "Notification sound, leave blank to use the default", HelpLink = "https://pushover.net/api#sounds")]
[FieldDefinition(3, Label = "Retry", Type = FieldType.Textbox, HelpText = "Interval to retry Emergency alerts, minimum 30 seconds")]
public int Retry { get; set; }
[FieldDefinition(4, Label = "Expire", Type = FieldType.Textbox, HelpText = "Maximum time to retry Emergency alerts, maximum 86400 seconds")]
public int Expire { get; set; }
[FieldDefinition(5, Label = "Sound", Type = FieldType.Textbox, HelpText = "Notification sound, leave blank to use the default", HelpLink = "https://pushover.net/api#sounds")]
public string Sound { get; set; }
public bool IsValid

Loading…
Cancel
Save