2013-05-20 03:30:02 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2013-08-24 05:42:45 +03:00
|
|
|
using Newtonsoft.Json;
|
2013-05-20 03:30:02 +03:00
|
|
|
using NzbDrone.Api.REST;
|
|
|
|
using NzbDrone.Core.Update;
|
|
|
|
using NzbDrone.Api.Mapping;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Update
|
|
|
|
{
|
|
|
|
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
|
|
|
{
|
2013-06-28 03:04:52 +03:00
|
|
|
private readonly ICheckUpdateService _checkUpdateService;
|
2013-09-28 21:48:30 +03:00
|
|
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
2013-05-20 03:30:02 +03:00
|
|
|
|
2013-09-28 21:48:30 +03:00
|
|
|
public UpdateModule(ICheckUpdateService checkUpdateService,
|
|
|
|
IRecentUpdateProvider recentUpdateProvider)
|
2013-05-20 03:30:02 +03:00
|
|
|
{
|
2013-06-28 03:04:52 +03:00
|
|
|
_checkUpdateService = checkUpdateService;
|
2013-09-28 21:48:30 +03:00
|
|
|
_recentUpdateProvider = recentUpdateProvider;
|
|
|
|
GetResourceAll = GetRecentUpdates;
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
|
2013-09-28 21:48:30 +03:00
|
|
|
private UpdateResource GetAvailableUpdate()
|
2013-05-20 03:30:02 +03:00
|
|
|
{
|
2013-06-28 03:04:52 +03:00
|
|
|
var update = _checkUpdateService.AvailableUpdate();
|
2013-09-28 21:48:30 +03:00
|
|
|
var response = new UpdateResource();
|
2013-05-20 03:30:02 +03:00
|
|
|
|
|
|
|
if (update != null)
|
|
|
|
{
|
2013-09-28 21:48:30 +03:00
|
|
|
return update.InjectTo<UpdateResource>();
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2013-09-28 21:48:30 +03:00
|
|
|
|
|
|
|
private List<UpdateResource> GetRecentUpdates()
|
|
|
|
{
|
|
|
|
return ToListResource(_recentUpdateProvider.GetRecentUpdatePackages);
|
|
|
|
}
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public class UpdateResource : RestResource
|
|
|
|
{
|
2013-08-24 05:42:45 +03:00
|
|
|
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
2013-05-20 03:30:02 +03:00
|
|
|
public Version Version { get; set; }
|
2013-08-24 05:42:45 +03:00
|
|
|
|
|
|
|
public String Branch { get; set; }
|
|
|
|
public DateTime ReleaseDate { get; set; }
|
2013-05-20 03:30:02 +03:00
|
|
|
public String FileName { get; set; }
|
|
|
|
public String Url { get; set; }
|
2013-09-28 21:48:30 +03:00
|
|
|
|
|
|
|
public UpdateChanges Changes { get; set; }
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
}
|