diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrEnvironment.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrEnvironment.cs new file mode 100644 index 000000000..c46c3dd87 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrEnvironment.cs @@ -0,0 +1,8 @@ +namespace NzbDrone.Core.Notifications.Notifiarr +{ + public enum NotifiarrEnvironment + { + Live, + Development + } +} diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs index 2f7468b4f..4b9397749 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs @@ -15,7 +15,6 @@ namespace NzbDrone.Core.Notifications.Notifiarr public class NotifiarrProxy : INotifiarrProxy { - private const string URL = "https://notifiarr.com/notifier.php"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -50,10 +49,19 @@ namespace NzbDrone.Core.Notifications.Notifiarr } catch (HttpException ex) { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) + switch ((int)ex.Response.StatusCode) { - _logger.Error(ex, "API key is invalid: " + ex.Message); - return new ValidationFailure("APIKey", "API key is invalid"); + case 401: + _logger.Error(ex, "API key is invalid: " + ex.Message); + return new ValidationFailure("APIKey", "API key is invalid"); + case 400: + case 520: + case 521: + case 522: + case 523: + case 524: + _logger.Error(ex, "Unable to send test notification: " + ex.Message); + return new ValidationFailure("", "Unable to send test notification"); } _logger.Error(ex, "Unable to send test message: " + ex.Message); @@ -70,8 +78,10 @@ namespace NzbDrone.Core.Notifications.Notifiarr { try { - var requestBuilder = new HttpRequestBuilder(URL).Post(); + var url = settings.Environment == (int)NotifiarrEnvironment.Development ? "https://dev.notifiarr.com" : "https://notifiarr.com"; + var requestBuilder = new HttpRequestBuilder(url + "/notifier.php").Post(); requestBuilder.AddFormParameter("api", settings.APIKey).Build(); + requestBuilder.AddFormParameter("instanceName", settings.InstanceName).Build(); foreach (string key in message.Keys) { @@ -84,10 +94,19 @@ namespace NzbDrone.Core.Notifications.Notifiarr } catch (HttpException ex) { - if (ex.Response.StatusCode == HttpStatusCode.BadRequest) + switch ((int)ex.Response.StatusCode) { - _logger.Error(ex, "API key is invalid"); - throw; + case 401: + _logger.Error(ex, "API key is invalid"); + throw; + case 400: + case 520: + case 521: + case 522: + case 523: + case 524: + _logger.Error(ex, "Unable to send notification"); + throw; } throw new NotifiarrException("Unable to send notification", ex); diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs index 1a8bb06c9..ec0897995 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs @@ -19,6 +19,10 @@ namespace NzbDrone.Core.Notifications.Notifiarr [FieldDefinition(0, Label = "API Key", Privacy = PrivacyLevel.ApiKey, HelpText = "Your API key from your profile", HelpLink = "https://notifiarr.com")] public string APIKey { get; set; } + [FieldDefinition(1, Label = "Instance Name", Advanced = true, HelpText = "Unique name for this instance", HelpLink = "https://notifiarr.com")] + public string InstanceName { get; set; } + [FieldDefinition(2, Label = "Environment", Advanced = true, Type = FieldType.Select, SelectOptions = typeof(NotifiarrEnvironment), HelpText = "Live unless told otherwise", HelpLink = "https://notifiarr.com")] + public int Environment { get; set; } public NzbDroneValidationResult Validate() {