From 8a6a64d104831dbfa0488e84fbc5596e3b694bb5 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 19 May 2013 18:32:05 -0700 Subject: [PATCH] NotificationModule added to API --- .../Notifications/NotificationModule.cs | 36 +++++++++++++++++++ .../Notifications/NotificationResource.cs | 14 ++++++++ NzbDrone.Api/NzbDrone.Api.csproj | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 NzbDrone.Api/Notifications/NotificationModule.cs create mode 100644 NzbDrone.Api/Notifications/NotificationResource.cs diff --git a/NzbDrone.Api/Notifications/NotificationModule.cs b/NzbDrone.Api/Notifications/NotificationModule.cs new file mode 100644 index 000000000..34b51865d --- /dev/null +++ b/NzbDrone.Api/Notifications/NotificationModule.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using NzbDrone.Api.ClientSchema; +using NzbDrone.Core.Notifications; +using Omu.ValueInjecter; + +namespace NzbDrone.Api.Notifications +{ + public class NotificationModule : NzbDroneRestModule + { + private readonly INotificationService _notificationService; + + public NotificationModule(INotificationService notificationService) + { + _notificationService = notificationService; + GetResourceAll = GetAll; + } + + private List GetAll() + { + var notifications = _notificationService.All(); + + var result = new List(notifications.Count); + + foreach (var notification in notifications) + { + var indexerResource = new NotificationResource(); + indexerResource.InjectFrom(notification); + indexerResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings); + + result.Add(indexerResource); + } + + return result; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/Notifications/NotificationResource.cs b/NzbDrone.Api/Notifications/NotificationResource.cs new file mode 100644 index 000000000..77deb5426 --- /dev/null +++ b/NzbDrone.Api/Notifications/NotificationResource.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using NzbDrone.Api.ClientSchema; +using NzbDrone.Api.REST; + +namespace NzbDrone.Api.Notifications +{ + public class NotificationResource : RestResource + { + public Boolean Enable { get; set; } + public String Name { get; set; } + public List Fields { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index ddac818a3..d23daf537 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -112,6 +112,8 @@ + +