2013-04-14 02:57:10 +03:00
|
|
|
using System;
|
2013-09-28 21:48:30 +03:00
|
|
|
using System.Collections.Generic;
|
2013-04-14 02:57:10 +03:00
|
|
|
using NzbDrone.Common;
|
2013-09-11 09:33:47 +03:00
|
|
|
using RestSharp;
|
|
|
|
using NzbDrone.Core.Rest;
|
2013-04-14 02:57:10 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Update
|
|
|
|
{
|
2013-04-15 04:41:39 +03:00
|
|
|
public interface IUpdatePackageProvider
|
2013-04-14 02:57:10 +03:00
|
|
|
{
|
2013-09-11 09:33:47 +03:00
|
|
|
UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
|
2013-09-28 21:48:30 +03:00
|
|
|
List<UpdatePackage> GetRecentUpdates(string branch);
|
2013-04-14 02:57:10 +03:00
|
|
|
}
|
|
|
|
|
2013-04-15 04:41:39 +03:00
|
|
|
public class UpdatePackageProvider : IUpdatePackageProvider
|
2013-04-14 02:57:10 +03:00
|
|
|
{
|
2013-09-11 09:33:47 +03:00
|
|
|
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
|
2013-04-14 02:57:10 +03:00
|
|
|
{
|
2013-09-11 09:33:47 +03:00
|
|
|
var restClient = new RestClient(Services.RootUrl);
|
2013-04-14 02:57:10 +03:00
|
|
|
|
2013-09-11 09:33:47 +03:00
|
|
|
var request = new RestRequest("/v1/update/{branch}");
|
|
|
|
|
|
|
|
request.AddParameter("version", currentVersion);
|
|
|
|
request.AddUrlSegment("branch", branch);
|
|
|
|
|
|
|
|
var update = restClient.ExecuteAndValidate<UpdatePackageAvailable>(request);
|
2013-04-14 02:57:10 +03:00
|
|
|
|
2013-08-24 05:21:12 +03:00
|
|
|
if (!update.Available) return null;
|
2013-04-14 02:57:10 +03:00
|
|
|
|
2013-08-24 05:21:12 +03:00
|
|
|
return update.UpdatePackage;
|
2013-04-15 04:41:39 +03:00
|
|
|
}
|
2013-09-28 21:48:30 +03:00
|
|
|
|
|
|
|
public List<UpdatePackage> GetRecentUpdates(string branch)
|
|
|
|
{
|
|
|
|
var restClient = new RestClient(Services.RootUrl);
|
|
|
|
|
|
|
|
var request = new RestRequest("/v1/update/{branch}/all");
|
|
|
|
|
|
|
|
request.AddUrlSegment("branch", branch);
|
|
|
|
request.AddParameter("limit", 5);
|
|
|
|
|
|
|
|
var updates = restClient.ExecuteAndValidate<List<UpdatePackage>>(request);
|
|
|
|
|
|
|
|
return updates;
|
|
|
|
}
|
2013-04-14 02:57:10 +03:00
|
|
|
}
|
|
|
|
}
|