From 037127163f4780ef58d32fa7e20c2dbcf5d85f83 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 3 Apr 2014 07:05:38 -0700 Subject: [PATCH] New: Choose notification sound for PushOver --- src/NzbDrone.Core/Notifications/Pushover/Pushover.cs | 6 +++--- .../Notifications/Pushover/PushoverService.cs | 12 ++++++++---- .../Notifications/Pushover/PushoverSettings.cs | 3 +++ .../Notifications/Pushover/TestPushoverCommand.cs | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Pushover/Pushover.cs b/src/NzbDrone.Core/Notifications/Pushover/Pushover.cs index 36258ebea..1e14e34fb 100644 --- a/src/NzbDrone.Core/Notifications/Pushover/Pushover.cs +++ b/src/NzbDrone.Core/Notifications/Pushover/Pushover.cs @@ -5,7 +5,7 @@ namespace NzbDrone.Core.Notifications.Pushover public class Pushover : NotificationBase { private readonly IPushoverProxy _pushoverProxy; - + public Pushover(IPushoverProxy pushoverProxy) { _pushoverProxy = pushoverProxy; @@ -20,14 +20,14 @@ namespace NzbDrone.Core.Notifications.Pushover { const string title = "Episode Grabbed"; - _pushoverProxy.SendNotification(title, message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority); + _pushoverProxy.SendNotification(title, message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority, Settings.Sound); } public override void OnDownload(DownloadMessage message) { const string title = "Episode Downloaded"; - _pushoverProxy.SendNotification(title, message.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority); + _pushoverProxy.SendNotification(title, message.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority, Settings.Sound); } public override void AfterRename(Series series) diff --git a/src/NzbDrone.Core/Notifications/Pushover/PushoverService.cs b/src/NzbDrone.Core/Notifications/Pushover/PushoverService.cs index 7527d3b66..cf7b055f0 100644 --- a/src/NzbDrone.Core/Notifications/Pushover/PushoverService.cs +++ b/src/NzbDrone.Core/Notifications/Pushover/PushoverService.cs @@ -1,4 +1,5 @@ -using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Common; +using NzbDrone.Core.Messaging.Commands; using RestSharp; using NzbDrone.Core.Rest; @@ -6,14 +7,14 @@ namespace NzbDrone.Core.Notifications.Pushover { public interface IPushoverProxy { - void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority); + void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound); } public class PushoverProxy : IPushoverProxy, IExecute { private const string URL = "https://api.pushover.net/1/messages.json"; - public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority) + public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound) { var client = new RestClient(URL); var request = new RestRequest(Method.POST); @@ -23,6 +24,9 @@ namespace NzbDrone.Core.Notifications.Pushover request.AddParameter("message", message); request.AddParameter("priority", (int)priority); + if (!sound.IsNullOrWhiteSpace()) request.AddParameter("sound", sound); + + client.ExecuteAndValidate(request); } @@ -31,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Pushover const string title = "Test Notification"; const string body = "This is a test message from NzbDrone"; - SendNotification(title, body, message.ApiKey, message.UserKey, (PushoverPriority)message.Priority); + SendNotification(title, body, message.ApiKey, message.UserKey, (PushoverPriority)message.Priority, message.Sound); } } } diff --git a/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs b/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs index 178ef3bd8..db5197022 100644 --- a/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs +++ b/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs @@ -27,6 +27,9 @@ namespace NzbDrone.Core.Notifications.Pushover [FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )] public Int32 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")] + public String Sound { get; set; } + public bool IsValid { get diff --git a/src/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs b/src/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs index 235679d57..d216e08ce 100644 --- a/src/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs +++ b/src/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs @@ -16,5 +16,6 @@ namespace NzbDrone.Core.Notifications.Pushover public string ApiKey { get; set; } public string UserKey { get; set; } public int Priority { get; set; } + public string Sound { get; set; } } }