New: PushOver will now require an application per user to avoid API limiting issues

pull/3113/head
Mark McDowall 11 years ago
parent 72e56a1845
commit c42777086b

@ -0,0 +1,67 @@
using System;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(33)]
public class add_api_key_to_pushover : NzbDroneMigrationBase
{
private const string API_KEY = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
protected override void MainDbUpgrade()
{
Execute.WithConnection(UpdatePushoverSettings);
}
private void UpdatePushoverSettings(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand selectCommand = conn.CreateCommand())
{
selectCommand.Transaction = tran;
selectCommand.CommandText = @"SELECT * FROM Notifications WHERE ConfigContract = 'PushoverSettings'";
using (IDataReader reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
var idIndex = reader.GetOrdinal("Id");
var settingsIndex = reader.GetOrdinal("Settings");
var id = reader.GetInt32(idIndex);
var settings = Json.Deserialize<PushoverSettingsForV33>(reader.GetString(settingsIndex));
settings.ApiKey = API_KEY;
//Set priority to high if its currently emergency
if (settings.Priority == 2)
{
settings.Priority = 1;
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = String.Format("UPDATE Notifications " +
"SET Settings = '{0}'" +
"WHERE Id = {1}",
settings.ToJson(), id
);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private class PushoverSettingsForV33
{
public String ApiKey { get; set; }
public String UserKey { get; set; }
public Int32 Priority { get; set; }
}
}
}

@ -20,14 +20,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{
const string title = "Episode Grabbed";
_pushoverProxy.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
_pushoverProxy.SendNotification(title, message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Episode Downloaded";
_pushoverProxy.SendNotification(title, message.Message, Settings.UserKey, (PushoverPriority)Settings.Priority);
_pushoverProxy.SendNotification(title, message.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void AfterRename(Series series)

@ -5,6 +5,6 @@
Quiet = -1,
Normal = 0,
High = 1,
Emergency = 2
//Emergency = 2
}
}

@ -6,19 +6,18 @@ namespace NzbDrone.Core.Notifications.Pushover
{
public interface IPushoverProxy
{
void SendNotification(string title, string message, string userKey, PushoverPriority priority);
void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority);
}
public class PushoverProxy : IPushoverProxy, IExecute<TestPushoverCommand>
{
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)
public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority)
{
var client = new RestClient(URL);
var request = new RestRequest(Method.POST);
request.AddParameter("token", TOKEN);
request.AddParameter("token", apiKey);
request.AddParameter("user", userKey);
request.AddParameter("title", title);
request.AddParameter("message", message);
@ -32,7 +31,7 @@ namespace NzbDrone.Core.Notifications.Pushover
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
SendNotification(title, body, message.UserKey, (PushoverPriority)message.Priority);
SendNotification(title, body, message.ApiKey, message.UserKey, (PushoverPriority)message.Priority);
}
}
}

@ -18,10 +18,13 @@ namespace NzbDrone.Core.Notifications.Pushover
{
private static readonly PushoverSettingsValidator Validator = new PushoverSettingsValidator();
[FieldDefinition(0, Label = "User Key", HelpLink = "https://pushover.net/")]
[FieldDefinition(0, Label = "API Key", HelpLink = "https://pushover.net/apps/clone/nzbdrone")]
public String ApiKey { get; set; }
[FieldDefinition(1, Label = "User Key", HelpLink = "https://pushover.net/")]
public String UserKey { get; set; }
[FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
public Int32 Priority { get; set; }
public bool IsValid

@ -12,6 +12,8 @@ namespace NzbDrone.Core.Notifications.Pushover
return true;
}
}
public string ApiKey { get; set; }
public string UserKey { get; set; }
public int Priority { get; set; }
}

@ -189,6 +189,7 @@
<Compile Include="Datastore\Migration\031_delete_old_naming_config_columns.cs" />
<Compile Include="Datastore\Migration\030_add_season_folder_format_to_naming_config.cs" />
<Compile Include="Datastore\Migration\032_set_default_release_group.cs" />
<Compile Include="Datastore\Migration\033_add_api_key_to_pushover.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

Loading…
Cancel
Save