1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

New: Remove defunct Boxcar notifications

(cherry picked from commit c6ad2396bb98dc8eb1ad47bf5d066b227a47f8b5)

Closes #9451
This commit is contained in:
Stevie Robinson 2023-11-25 21:23:00 +01:00 committed by Bogdan
parent cb08c0767d
commit ff1987be84
4 changed files with 0 additions and 216 deletions

View File

@ -1,74 +0,0 @@
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Movies;
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(MOVIE_GRABBED_TITLE, grabMessage.Message, Settings);
}
public override void OnDownload(DownloadMessage message)
{
_proxy.SendNotification(MOVIE_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnMovieAdded(Movie movie)
{
_proxy.SendNotification(MOVIE_ADDED_TITLE, $"{movie.Title} added to library", Settings);
}
public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
{
_proxy.SendNotification(MOVIE_FILE_DELETED_TITLE, deleteMessage.Message, Settings);
}
public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{
_proxy.SendNotification(MOVIE_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);
}
}
}

View File

@ -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)
{
}
}
}

View File

@ -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 Radarr";
SendNotification(title, body, settings);
return null;
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Error(ex, "Access Token is invalid: " + ex.Message);
return new ValidationFailure("Token", "Access Token is invalid");
}
_logger.Error(ex, "Unable to send test message: " + ex.Message);
return new ValidationFailure("Token", "Unable to send test message");
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send test message: " + ex.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/Radarr/Radarr/develop/Logo/64.png")
.Build();
_httpClient.Post(request);
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Error(ex, "Access Token is invalid: " + ex.Message);
throw;
}
throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
}
}
}
}

View File

@ -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));
}
}
}