New: Remove Defunct Boxcar notifications

pull/6029/head^2
Stevie Robinson 12 months ago committed by GitHub
parent 75420d4a89
commit c6ad2396bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,73 +0,0 @@
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Notifications.Boxcar
{
public class Boxcar : NotificationBase<BoxcarSettings>
{
private readonly IBoxcarProxy _proxy;
public Boxcar(IBoxcarProxy proxy)
{
_proxy = proxy;
}
public override string Link => "https://boxcar.io/client";
public override string Name => "Boxcar";
public override void OnGrab(GrabMessage grabMessage)
{
_proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage.Message, Settings);
}
public override void OnDownload(DownloadMessage message)
{
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage)
{
_proxy.SendNotification(EPISODE_DELETED_TITLE, deleteMessage.Message, Settings);
}
public override void OnSeriesAdd(SeriesAddMessage message)
{
_proxy.SendNotification(SERIES_ADDED_TITLE, message.Message, Settings);
}
public override void OnSeriesDelete(SeriesDeleteMessage deleteMessage)
{
_proxy.SendNotification(SERIES_DELETED_TITLE, deleteMessage.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, message.Message, Settings);
}
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{
_proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", Settings);
}
public override void OnApplicationUpdate(ApplicationUpdateMessage message)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE, message.Message, Settings);
}
public override void OnManualInteractionRequired(ManualInteractionRequiredMessage message)
{
_proxy.SendNotification(MANUAL_INTERACTION_REQUIRED_TITLE, message.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_proxy.Test(Settings));
return new ValidationResult(failures);
}
}
}

@ -1,18 +0,0 @@
using System;
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.Notifications.Boxcar
{
public class BoxcarException : NzbDroneException
{
public BoxcarException(string message)
: base(message)
{
}
public BoxcarException(string message, Exception innerException, params object[] args)
: base(message, innerException, args)
{
}
}
}

@ -1,97 +0,0 @@
using System;
using System.Net;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.Notifications.Boxcar
{
public interface IBoxcarProxy
{
void SendNotification(string title, string message, BoxcarSettings settings);
ValidationFailure Test(BoxcarSettings settings);
}
public class BoxcarProxy : IBoxcarProxy
{
private const string URL = "https://new.boxcar.io/api/notifications";
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
public BoxcarProxy(IHttpClient httpClient, Logger logger)
{
_httpClient = httpClient;
_logger = logger;
}
public void SendNotification(string title, string message, BoxcarSettings settings)
{
try
{
ProcessNotification(title, message, settings);
}
catch (BoxcarException ex)
{
_logger.Error(ex, "Unable to send message");
throw new BoxcarException("Unable to send Boxcar notifications");
}
}
public ValidationFailure Test(BoxcarSettings settings)
{
try
{
const string title = "Test Notification";
const string body = "This is a test message from Sonarr";
SendNotification(title, body, settings);
return null;
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Error(ex, "Access Token is invalid");
return new ValidationFailure("Token", "Access Token is invalid");
}
_logger.Error(ex, "Unable to send test message");
return new ValidationFailure("Token", "Unable to send test message");
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send test message");
return new ValidationFailure("", "Unable to send test message");
}
}
private void ProcessNotification(string title, string message, BoxcarSettings settings)
{
try
{
var requestBuilder = new HttpRequestBuilder(URL).Post();
var request = requestBuilder.AddFormParameter("user_credentials", settings.Token)
.AddFormParameter("notification[title]", title)
.AddFormParameter("notification[long_message]", message)
.AddFormParameter("notification[source_name]", BuildInfo.AppName)
.AddFormParameter("notification[icon_url]", "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/64.png")
.Build();
_httpClient.Post(request);
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Error(ex, "Access Token is invalid");
throw;
}
throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
}
}
}
}

@ -1,28 +0,0 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Notifications.Boxcar
{
public class BoxcarSettingsValidator : AbstractValidator<BoxcarSettings>
{
public BoxcarSettingsValidator()
{
RuleFor(c => c.Token).NotEmpty();
}
}
public class BoxcarSettings : IProviderConfig
{
private static readonly BoxcarSettingsValidator Validator = new BoxcarSettingsValidator();
[FieldDefinition(0, Label = "Access Token", Privacy = PrivacyLevel.ApiKey, HelpText = "Your Access Token, from your Boxcar account settings: https://new.boxcar.io/account/edit", HelpLink = "https://new.boxcar.io/account/edit")]
public string Token { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
Loading…
Cancel
Save