mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-25 22:46:31 -04:00
New: MediaBrowser notifications
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Rest;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.MediaBrowser
|
||||
{
|
||||
public interface IMediaBrowserService
|
||||
{
|
||||
void Notify(MediaBrowserSettings settings, String title, String message);
|
||||
void Update(MediaBrowserSettings settings, Series series);
|
||||
ValidationFailure Test(MediaBrowserSettings settings);
|
||||
}
|
||||
|
||||
public class MediaBrowserService : IMediaBrowserService
|
||||
{
|
||||
private readonly MediaBrowserProxy _proxy;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MediaBrowserService(MediaBrowserProxy proxy, Logger logger)
|
||||
{
|
||||
_proxy = proxy;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Notify(MediaBrowserSettings settings, String title, String message)
|
||||
{
|
||||
_proxy.Notify(settings, title, message);
|
||||
}
|
||||
|
||||
public void Update(MediaBrowserSettings settings, Series series)
|
||||
{
|
||||
_proxy.Update(settings, series.TvdbId);
|
||||
}
|
||||
|
||||
public ValidationFailure Test(MediaBrowserSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.Debug("Testing connection to MediaBrowser: {0}", settings.Address);
|
||||
|
||||
Notify(settings, "Test from Sonarr", "Success! MediaBrowser has been successfully configured!");
|
||||
}
|
||||
catch (RestException ex)
|
||||
{
|
||||
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new ValidationFailure("ApiKey", "API Key is incorrect");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Unable to send test message: " + ex.Message, ex);
|
||||
return new ValidationFailure("Host", "Unable to send test message: " + ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user