2013-09-11 06:33:47 +00:00
|
|
|
|
using NzbDrone.Core.Messaging;
|
2013-07-25 07:24:09 +00:00
|
|
|
|
using RestSharp;
|
2013-08-18 00:17:37 +00:00
|
|
|
|
using NzbDrone.Core.Rest;
|
2013-07-25 07:24:09 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Notifications.Pushover
|
|
|
|
|
{
|
2013-08-18 00:17:37 +00:00
|
|
|
|
public interface IPushoverProxy
|
2013-07-25 07:24:09 +00:00
|
|
|
|
{
|
|
|
|
|
void SendNotification(string title, string message, string userKey, PushoverPriority priority);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 00:17:37 +00:00
|
|
|
|
public class PushoverProxy : IPushoverProxy, IExecute<TestPushoverCommand>
|
2013-07-25 07:24:09 +00:00
|
|
|
|
{
|
|
|
|
|
private const string TOKEN = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
|
|
|
|
|
private const string URL = "https://api.pushover.net/1/messages.json";
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2013-08-18 00:17:37 +00:00
|
|
|
|
client.ExecuteAndValidate(request);
|
2013-07-25 07:24:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|