2016-02-11 07:43:40 +00:00
using FluentValidation ;
2013-07-25 07:24:09 +00:00
using NzbDrone.Core.Annotations ;
2013-09-21 06:39:26 +00:00
using NzbDrone.Core.ThingiProvider ;
2015-03-17 04:33:34 +00:00
using NzbDrone.Core.Validation ;
2013-07-25 07:24:09 +00:00
namespace NzbDrone.Core.Notifications.Pushover
{
2013-10-12 18:44:40 +00:00
public class PushoverSettingsValidator : AbstractValidator < PushoverSettings >
{
public PushoverSettingsValidator ( )
{
RuleFor ( c = > c . UserKey ) . NotEmpty ( ) ;
2016-02-11 07:43:40 +00:00
RuleFor ( c = > c . Retry ) . GreaterThanOrEqualTo ( 30 ) . LessThanOrEqualTo ( 86400 ) . When ( c = > ( PushoverPriority ) c . Priority = = PushoverPriority . Emergency ) ;
RuleFor ( c = > c . Retry ) . GreaterThanOrEqualTo ( 0 ) . LessThanOrEqualTo ( 86400 ) . When ( c = > ( PushoverPriority ) c . Priority = = PushoverPriority . Emergency ) ;
2013-10-12 18:44:40 +00:00
}
}
2013-09-21 06:39:26 +00:00
public class PushoverSettings : IProviderConfig
2013-07-25 07:24:09 +00:00
{
2013-10-12 18:44:40 +00:00
private static readonly PushoverSettingsValidator Validator = new PushoverSettingsValidator ( ) ;
2014-08-05 20:51:06 +00:00
public PushoverSettings ( )
{
Priority = 0 ;
}
2014-11-25 15:21:33 +00:00
//TODO: Get Pushover to change our app name (or create a new app) when we have a new logo
2013-12-31 04:48:14 +00:00
[FieldDefinition(0, Label = "API Key", HelpLink = "https://pushover.net/apps/clone/nzbdrone")]
2015-10-03 17:45:26 +00:00
public string ApiKey { get ; set ; }
2013-12-31 04:48:14 +00:00
[FieldDefinition(1, Label = "User Key", HelpLink = "https://pushover.net/")]
2015-10-03 17:45:26 +00:00
public string UserKey { get ; set ; }
2013-07-25 07:24:09 +00:00
2013-12-31 04:48:14 +00:00
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
2015-10-03 17:45:26 +00:00
public int Priority { get ; set ; }
2013-07-25 07:24:09 +00:00
2016-02-11 07:43:40 +00:00
[FieldDefinition(3, Label = "Retry", Type = FieldType.Textbox, HelpText = "Interval to retry Emergency alerts, minimum 30 seconds")]
public int Retry { get ; set ; }
[FieldDefinition(4, Label = "Expire", Type = FieldType.Textbox, HelpText = "Maximum time to retry Emergency alerts, maximum 86400 seconds")]
public int Expire { get ; set ; }
[FieldDefinition(5, Label = "Sound", Type = FieldType.Textbox, HelpText = "Notification sound, leave blank to use the default", HelpLink = "https://pushover.net/api#sounds")]
2015-10-03 17:45:26 +00:00
public string Sound { get ; set ; }
2014-04-03 14:05:38 +00:00
2013-07-25 07:24:09 +00:00
public bool IsValid
{
get
{
2014-07-04 08:09:48 +00:00
return ! string . IsNullOrWhiteSpace ( UserKey ) & & Priority > = - 1 & & Priority < = 2 ;
2013-07-25 07:24:09 +00:00
}
}
2013-09-21 07:09:26 +00:00
2015-03-17 04:33:34 +00:00
public NzbDroneValidationResult Validate ( )
2013-09-21 07:09:26 +00:00
{
2015-03-17 04:33:34 +00:00
return new NzbDroneValidationResult ( Validator . Validate ( this ) ) ;
2013-09-21 07:09:26 +00:00
}
2013-07-25 07:24:09 +00:00
}
}