2013-06-13 05:55:11 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2013-05-25 04:51:25 +03:00
|
|
|
using NzbDrone.Api.ClientSchema;
|
|
|
|
using NzbDrone.Core.Notifications;
|
|
|
|
using Omu.ValueInjecter;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Notifications
|
|
|
|
{
|
|
|
|
public class NotificationSchemaModule : NzbDroneRestModule<NotificationResource>
|
|
|
|
{
|
|
|
|
private readonly INotificationService _notificationService;
|
|
|
|
|
|
|
|
public NotificationSchemaModule(INotificationService notificationService)
|
|
|
|
: base("notification/schema")
|
|
|
|
{
|
|
|
|
_notificationService = notificationService;
|
|
|
|
|
2013-05-28 03:19:07 +03:00
|
|
|
GetResourceAll = GetSchema;
|
2013-05-25 04:51:25 +03:00
|
|
|
}
|
|
|
|
|
2013-05-28 03:19:07 +03:00
|
|
|
private List<NotificationResource> GetSchema()
|
2013-05-25 04:51:25 +03:00
|
|
|
{
|
|
|
|
var notifications = _notificationService.Schema();
|
|
|
|
|
|
|
|
var result = new List<NotificationResource>(notifications.Count);
|
|
|
|
|
|
|
|
foreach (var notification in notifications)
|
|
|
|
{
|
|
|
|
var notificationResource = new NotificationResource();
|
|
|
|
notificationResource.InjectFrom(notification);
|
|
|
|
notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
|
2013-06-13 18:21:38 +03:00
|
|
|
notificationResource.TestCommand = String.Format("test{0}", notification.Implementation.ToLowerInvariant());
|
2013-05-25 04:51:25 +03:00
|
|
|
|
|
|
|
result.Add(notificationResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|