New: Remove defunct Boxcar notifications

(cherry picked from commit c6ad2396bb98dc8eb1ad47bf5d066b227a47f8b5)

Closes #4339
pull/4340/head v2.0.5.3813
Stevie Robinson 6 months ago committed by Bogdan
parent a9bef2b4a1
commit d9520eb23e

@ -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(ALBUM_GRABBED_TITLE, grabMessage.Message, Settings);
}
public override void OnReleaseImport(AlbumDownloadMessage message)
{
_proxy.SendNotification(ALBUM_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage)
{
_proxy.SendNotification(ALBUM_DELETED_TITLE, deleteMessage.Message, Settings);
}
public override void OnArtistDelete(ArtistDeleteMessage deleteMessage)
{
_proxy.SendNotification(ARTIST_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 OnDownloadFailure(DownloadFailedMessage message)
{
_proxy.SendNotification(DOWNLOAD_FAILURE_TITLE, message.Message, Settings);
}
public override void OnImportFailure(AlbumDownloadMessage message)
{
_proxy.SendNotification(IMPORT_FAILURE_TITLE, message.Message, Settings);
}
public override void OnApplicationUpdate(ApplicationUpdateMessage message)
{
_proxy.SendNotification(APPLICATION_UPDATE_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,96 +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 Lidarr";
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/Lidarr/Lidarr/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