mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
added RestSharpExtensions to help validate REST response
This commit is contained in:
@@ -4,11 +4,11 @@ namespace NzbDrone.Core.Notifications.Pushover
|
||||
{
|
||||
public class Pushover : NotificationBase<PushoverSettings>
|
||||
{
|
||||
private readonly IPushoverService _pushoverService;
|
||||
private readonly IPushoverProxy _pushoverProxy;
|
||||
|
||||
public Pushover(IPushoverService pushoverService)
|
||||
public Pushover(IPushoverProxy pushoverProxy)
|
||||
{
|
||||
_pushoverService = pushoverService;
|
||||
_pushoverProxy = pushoverProxy;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
@@ -30,14 +30,14 @@ namespace NzbDrone.Core.Notifications.Pushover
|
||||
{
|
||||
const string title = "Episode Grabbed";
|
||||
|
||||
_pushoverService.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
|
||||
_pushoverProxy.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
|
||||
}
|
||||
|
||||
public override void OnDownload(string message, Series series)
|
||||
{
|
||||
const string title = "Episode Downloaded";
|
||||
|
||||
_pushoverService.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
|
||||
_pushoverProxy.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
|
||||
}
|
||||
|
||||
public override void AfterRename(Series series)
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
using System.Net;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using RestSharp;
|
||||
using NzbDrone.Core.Rest;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Pushover
|
||||
{
|
||||
public interface IPushoverService
|
||||
public interface IPushoverProxy
|
||||
{
|
||||
void SendNotification(string title, string message, string userKey, PushoverPriority priority);
|
||||
}
|
||||
|
||||
public class PushoverService : IPushoverService, IExecute<TestPushoverCommand>
|
||||
public class PushoverProxy : IPushoverProxy, IExecute<TestPushoverCommand>
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
private const string TOKEN = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
|
||||
private const string URL = "https://api.pushover.net/1/messages.json";
|
||||
|
||||
public PushoverService(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void SendNotification(string title, string message, string userKey, PushoverPriority priority)
|
||||
{
|
||||
var client = new RestClient(URL);
|
||||
@@ -32,12 +24,7 @@ namespace NzbDrone.Core.Notifications.Pushover
|
||||
request.AddParameter("message", message);
|
||||
request.AddParameter("priority", (int)priority);
|
||||
|
||||
var response = client.Execute(request);
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new InvalidResponseException(response.Content);
|
||||
}
|
||||
client.ExecuteAndValidate(request);
|
||||
}
|
||||
|
||||
public void Execute(TestPushoverCommand message)
|
||||
|
||||
Reference in New Issue
Block a user