1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 01:38:24 +00:00

Added pushover notifications

This commit is contained in:
Mark McDowall 2013-07-25 00:24:09 -07:00
parent 20e72ca103
commit e96e1b10db
7 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,15 @@
using System;
namespace NzbDrone.Core.Notifications.Pushover
{
public class InvalidResponseException : Exception
{
public InvalidResponseException()
{
}
public InvalidResponseException(string message) : base(message)
{
}
}
}

View file

@ -0,0 +1,44 @@
using NzbDrone.Core.Notifications.Prowl;
using NzbDrone.Core.Tv;
using Prowlin;
namespace NzbDrone.Core.Notifications.Pushover
{
public class Pushover : NotificationBase<PushoverSettings>
{
private readonly IPushoverService _pushoverService;
public Pushover(IPushoverService pushoverService)
{
_pushoverService = pushoverService;
}
public override string Name
{
get { return "Pushover"; }
}
public override string ImplementationName
{
get { return "Pushover"; }
}
public override void OnGrab(string message)
{
const string title = "Episode Grabbed";
_pushoverService.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void OnDownload(string message, Series series)
{
const string title = "Episode Downloaded";
_pushoverService.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void AfterRename(Series series)
{
}
}
}

View file

@ -0,0 +1,10 @@
namespace NzbDrone.Core.Notifications.Pushover
{
public enum PushoverPriority
{
Quiet = -1,
Normal = 0,
High = 1,
Emergency = 2
}
}

View file

@ -0,0 +1,52 @@
using System;
using System.Net;
using NLog;
using NzbDrone.Common.Messaging;
using RestSharp;
namespace NzbDrone.Core.Notifications.Pushover
{
public interface IPushoverService
{
void SendNotification(string title, string message, string userKey, PushoverPriority priority);
}
public class PushoverService : IPushoverService, IExecute<TestPushoverCommand>
{
private readonly Logger _logger;
private const string TOKEN = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
private const string URL = "https://api.pushover.net/1/messages.json";
public PushoverService(Logger logger)
{
_logger = logger;
}
public void SendNotification(string title, string message, string userKey, PushoverPriority priority)
{
var client = new RestClient(URL);
var request = new RestRequest(Method.POST);
request.AddParameter("token", TOKEN);
request.AddParameter("user", userKey);
request.AddParameter("title", title);
request.AddParameter("message", message);
request.AddParameter("priority", (int)priority);
var response = client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new InvalidResponseException(response.Content);
}
}
public void Execute(TestPushoverCommand message)
{
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
SendNotification(title, body, message.UserKey, (PushoverPriority)message.Priority);
}
}
}

View file

@ -0,0 +1,22 @@
using System;
using NzbDrone.Core.Annotations;
namespace NzbDrone.Core.Notifications.Pushover
{
public class PushoverSettings : INotifcationSettings
{
[FieldDefinition(0, Label = "User Key")]
public String UserKey { get; set; }
[FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
public Int32 Priority { get; set; }
public bool IsValid
{
get
{
return !string.IsNullOrWhiteSpace(UserKey) && Priority != null & Priority >= -1 && Priority <= 2;
}
}
}
}

View file

@ -0,0 +1,10 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Notifications.Pushover
{
public class TestPushoverCommand : ICommand
{
public string UserKey { get; set; }
public int Priority { get; set; }
}
}

View file

@ -356,6 +356,12 @@
<Compile Include="Notifications\Prowl\ProwlSettings.cs" />
<Compile Include="Notifications\Email\EmailSettings.cs" />
<Compile Include="Notifications\Prowl\TestProwlCommand.cs" />
<Compile Include="Notifications\Pushover\InvalidResponseException.cs" />
<Compile Include="Notifications\Pushover\Pushover.cs" />
<Compile Include="Notifications\Pushover\PushoverPriority.cs" />
<Compile Include="Notifications\Pushover\PushoverService.cs" />
<Compile Include="Notifications\Pushover\PushoverSettings.cs" />
<Compile Include="Notifications\Pushover\TestPushoverCommand.cs" />
<Compile Include="Notifications\Xbmc\HttpApiProvider.cs" />
<Compile Include="Notifications\Xbmc\IApiProvider.cs" />
<Compile Include="Notifications\Xbmc\InvalidXbmcVersionException.cs" />