2013-03-04 00:09:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-03-02 21:37:28 +00:00
|
|
|
|
using Nancy;
|
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Settings
|
|
|
|
|
{
|
|
|
|
|
public class SettingsModule : NzbDroneApiModule
|
|
|
|
|
{
|
2013-03-05 06:50:42 +00:00
|
|
|
|
private readonly IConfigService _configService;
|
2013-03-02 21:37:28 +00:00
|
|
|
|
|
2013-03-05 06:50:42 +00:00
|
|
|
|
public SettingsModule(IConfigService configService)
|
2013-03-02 21:37:28 +00:00
|
|
|
|
: base("/settings")
|
|
|
|
|
{
|
|
|
|
|
_configService = configService;
|
|
|
|
|
Get["/"] = x => GetAllSettings();
|
2013-03-05 06:50:42 +00:00
|
|
|
|
Post["/"] = x => SaveSettings();
|
2013-03-02 21:37:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetAllSettings()
|
|
|
|
|
{
|
2013-03-04 00:09:43 +00:00
|
|
|
|
var collection = Request.Query.Collection;
|
|
|
|
|
|
|
|
|
|
if(collection.HasValue && Boolean.Parse(collection.Value))
|
|
|
|
|
return _configService.All().AsResponse();
|
|
|
|
|
|
2013-03-04 01:07:22 +00:00
|
|
|
|
return _configService.AllWithDefaults().AsResponse();
|
2013-03-02 21:37:28 +00:00
|
|
|
|
}
|
2013-03-05 06:50:42 +00:00
|
|
|
|
|
|
|
|
|
private Response SaveSettings()
|
|
|
|
|
{
|
|
|
|
|
var request = Request.Body.FromJson<Dictionary<string, object>>();
|
2013-03-05 16:13:23 +00:00
|
|
|
|
_configService.SaveValues(request);
|
|
|
|
|
|
2013-03-05 06:50:42 +00:00
|
|
|
|
|
|
|
|
|
return request.AsResponse();
|
|
|
|
|
}
|
2013-03-02 21:37:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|