Added PushBullet notifications

pull/4/head
Mark McDowall 11 years ago
parent 742a21252c
commit 42efef0bb2

@ -0,0 +1,47 @@
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications.PushBullet
{
public class PushBullet : NotificationBase<PushBulletSettings>
{
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)
{
}
}
}

@ -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<TestPushBulletCommand>
{
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);
}
}
}

@ -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;
}
}
}
}

@ -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; }
}
}

@ -254,6 +254,10 @@
<Compile Include="Messaging\Events\IEventAggregator.cs" />
<Compile Include="Messaging\Events\IHandle.cs" />
<Compile Include="MetadataSource\Trakt\TraktException.cs" />
<Compile Include="Notifications\PushBullet\PushBullet.cs" />
<Compile Include="Notifications\PushBullet\PushBulletProxy.cs" />
<Compile Include="Notifications\PushBullet\PushBulletSettings.cs" />
<Compile Include="Notifications\PushBullet\TestPushBulletCommand.cs" />
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroid.cs" />
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroidPriority.cs" />
<Compile Include="Notifications\NotifyMyAndroid\NotifyMyAndroidProxy.cs" />

Loading…
Cancel
Save