diff --git a/NzbDrone.Core/Notifications/PushBullet/PushBullet.cs b/NzbDrone.Core/Notifications/PushBullet/PushBullet.cs new file mode 100644 index 000000000..82c058729 --- /dev/null +++ b/NzbDrone.Core/Notifications/PushBullet/PushBullet.cs @@ -0,0 +1,47 @@ +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Notifications.PushBullet +{ + public class PushBullet : NotificationBase + { + private readonly IPushBulletProxy _pushBulletProxy; + + public PushBullet(IPushBulletProxy pushBulletProxy) + { + _pushBulletProxy = pushBulletProxy; + } + + public override string Name + { + get { return "PushBullet"; } + } + + public override string ImplementationName + { + get { return "PushBullet"; } + } + + public override string Link + { + get { return "https://www.pushbullet.com/"; } + } + + public override void OnGrab(string message) + { + const string title = "Episode Grabbed"; + + _pushBulletProxy.SendNotification(title, message, Settings.ApiKey, Settings.DeviceId); + } + + public override void OnDownload(string message, Series series) + { + const string title = "Episode Downloaded"; + + _pushBulletProxy.SendNotification(title, message, Settings.ApiKey, Settings.DeviceId); + } + + public override void AfterRename(Series series) + { + } + } +} diff --git a/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs b/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs new file mode 100644 index 000000000..edeed98c4 --- /dev/null +++ b/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs @@ -0,0 +1,38 @@ +using System; +using NzbDrone.Core.Messaging.Commands; +using RestSharp; +using NzbDrone.Core.Rest; + +namespace NzbDrone.Core.Notifications.PushBullet +{ + public interface IPushBulletProxy + { + void SendNotification(string title, string message, string apiKey, int deviceId); + } + + public class PushBulletProxy : IPushBulletProxy, IExecute + { + private const string URL = "https://www.pushbullet.com/api/pushes"; + + public void SendNotification(string title, string message, string apiKey, int deviceId) + { + var client = new RestClient(URL); + var request = new RestRequest(Method.POST); + request.AddParameter("device_id", deviceId); + request.AddParameter("type", "note"); + request.AddParameter("title", title); + request.AddParameter("body", message); + + client.Authenticator = new HttpBasicAuthenticator(apiKey, String.Empty); + client.ExecuteAndValidate(request); + } + + public void Execute(TestPushBulletCommand message) + { + const string title = "Test Notification"; + const string body = "This is a test message from NzbDrone"; + + SendNotification(title, body, message.ApiKey, message.DeviceId); + } + } +} diff --git a/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs b/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs new file mode 100644 index 000000000..f7a492622 --- /dev/null +++ b/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs @@ -0,0 +1,22 @@ +using System; +using NzbDrone.Core.Annotations; + +namespace NzbDrone.Core.Notifications.PushBullet +{ + public class PushBulletSettings : INotifcationSettings + { + [FieldDefinition(0, Label = "API Key", HelpLink = "https://www.pushbullet.com/")] + public String ApiKey { get; set; } + + [FieldDefinition(1, Label = "Device ID")] + public Int32 DeviceId { get; set; } + + public bool IsValid + { + get + { + return !String.IsNullOrWhiteSpace(ApiKey) && DeviceId > 0; + } + } + } +} diff --git a/NzbDrone.Core/Notifications/PushBullet/TestPushBulletCommand.cs b/NzbDrone.Core/Notifications/PushBullet/TestPushBulletCommand.cs new file mode 100644 index 000000000..715be4661 --- /dev/null +++ b/NzbDrone.Core/Notifications/PushBullet/TestPushBulletCommand.cs @@ -0,0 +1,18 @@ +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Notifications.PushBullet +{ + public class TestPushBulletCommand : Command + { + + public override bool SendUpdatesToClient + { + get + { + return true; + } + } + public string ApiKey { get; set; } + public int DeviceId { get; set; } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e53438f4a..591ccb069 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -254,6 +254,10 @@ + + + +