Lidarr/src/NzbDrone.Core/Notifications/Twitter/TwitterSettings.cs

54 lines
2.0 KiB
C#
Raw Normal View History

using FluentValidation;
2015-03-29 05:30:58 +00:00
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Notifications.Twitter
{
public class TwitterSettingsValidator : AbstractValidator<TwitterSettings>
{
public TwitterSettingsValidator()
{
RuleFor(c => c.AccessToken).NotEmpty();
RuleFor(c => c.AccessTokenSecret).NotEmpty();
//TODO: Validate that it is a valid username (numbers, letters and underscores - I think)
RuleFor(c => c.Mention).NotEmpty().When(c => c.DirectMessage);
RuleFor(c => c.DirectMessage).Equal(true)
.WithMessage("Using Direct Messaging is recommended, or use a private account.")
.AsWarning();
2015-03-29 05:30:58 +00:00
}
}
public class TwitterSettings : IProviderConfig
{
private static readonly TwitterSettingsValidator Validator = new TwitterSettingsValidator();
public TwitterSettings()
{
DirectMessage = true;
2015-03-29 05:30:58 +00:00
AuthorizeNotification = "step1";
}
[FieldDefinition(0, Label = "Access Token", Advanced = true)]
public string AccessToken { get; set; }
2015-03-29 05:30:58 +00:00
[FieldDefinition(1, Label = "Access Token Secret", Advanced = true)]
public string AccessTokenSecret { get; set; }
2015-03-29 05:30:58 +00:00
[FieldDefinition(2, Label = "Mention", HelpText = "Mention this user in sent tweets")]
public string Mention { get; set; }
2015-03-29 05:30:58 +00:00
[FieldDefinition(3, Label = "Direct Message", Type = FieldType.Checkbox, HelpText = "Send a direct message instead of a public message")]
public bool DirectMessage { get; set; }
2015-03-29 05:30:58 +00:00
[FieldDefinition(4, Label = "Connect to twitter", Type = FieldType.Action)]
public string AuthorizeNotification { get; set; }
2015-03-29 05:30:58 +00:00
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}