using System; using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Webhook { public class WebhookSettingsValidator : AbstractValidator { public WebhookSettingsValidator() { RuleFor(c => c.Url).IsValidUrl(); } } public class WebhookSettings : NotificationBaseSettings { private static readonly WebhookSettingsValidator Validator = new WebhookSettingsValidator(); public WebhookSettings() { Method = Convert.ToInt32(WebhookMethod.POST); } [FieldDefinition(0, Label = "URL", Type = FieldType.Url)] public string Url { get; set; } [FieldDefinition(1, Label = "Method", Type = FieldType.Select, SelectOptions = typeof(WebhookMethod), HelpText = "Which HTTP method to use submit to the Webservice")] public int Method { get; set; } [FieldDefinition(2, Label = "Username", HelpText = "Username", Type = FieldType.Textbox, Privacy = PrivacyLevel.UserName)] public string Username { get; set; } [FieldDefinition(3, Label = "Password", HelpText = "Password", Type = FieldType.Password, Privacy = PrivacyLevel.Password)] public string Password { get; set; } public override NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); } } }