New: Choose notification sound for PushOver

This commit is contained in:
Mark McDowall 2014-04-03 07:05:38 -07:00
parent 48a92696e9
commit 037127163f
4 changed files with 15 additions and 7 deletions

View File

@ -20,14 +20,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{ {
const string title = "Episode Grabbed"; 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) public override void OnDownload(DownloadMessage message)
{ {
const string title = "Episode Downloaded"; 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) public override void AfterRename(Series series)

View File

@ -1,4 +1,5 @@
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Common;
using NzbDrone.Core.Messaging.Commands;
using RestSharp; using RestSharp;
using NzbDrone.Core.Rest; using NzbDrone.Core.Rest;
@ -6,14 +7,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{ {
public interface IPushoverProxy 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<TestPushoverCommand> public class PushoverProxy : IPushoverProxy, IExecute<TestPushoverCommand>
{ {
private const string URL = "https://api.pushover.net/1/messages.json"; 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 client = new RestClient(URL);
var request = new RestRequest(Method.POST); var request = new RestRequest(Method.POST);
@ -23,6 +24,9 @@ namespace NzbDrone.Core.Notifications.Pushover
request.AddParameter("message", message); request.AddParameter("message", message);
request.AddParameter("priority", (int)priority); request.AddParameter("priority", (int)priority);
if (!sound.IsNullOrWhiteSpace()) request.AddParameter("sound", sound);
client.ExecuteAndValidate(request); client.ExecuteAndValidate(request);
} }
@ -31,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Pushover
const string title = "Test Notification"; const string title = "Test Notification";
const string body = "This is a test message from NzbDrone"; 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);
} }
} }
} }

View File

@ -27,6 +27,9 @@ namespace NzbDrone.Core.Notifications.Pushover
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )] [FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
public Int32 Priority { get; set; } 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 public bool IsValid
{ {
get get

View File

@ -16,5 +16,6 @@ namespace NzbDrone.Core.Notifications.Pushover
public string ApiKey { get; set; } public string ApiKey { get; set; }
public string UserKey { get; set; } public string UserKey { get; set; }
public int Priority { get; set; } public int Priority { get; set; }
public string Sound { get; set; }
} }
} }