2013-04-14 01:57:10 +02:00
|
|
|
|
using System;
|
|
|
|
|
using NzbDrone.Common;
|
2013-08-10 07:00:07 +02:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-04-14 01:57:10 +02:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-09-11 08:33:47 +02:00
|
|
|
|
using RestSharp;
|
|
|
|
|
using NzbDrone.Core.Rest;
|
2013-04-14 01:57:10 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Update
|
|
|
|
|
{
|
2013-04-15 03:41:39 +02:00
|
|
|
|
public interface IUpdatePackageProvider
|
2013-04-14 01:57:10 +02:00
|
|
|
|
{
|
2013-09-11 08:33:47 +02:00
|
|
|
|
UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
|
2013-04-14 01:57:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
public class UpdatePackageProvider : IUpdatePackageProvider
|
2013-04-14 01:57:10 +02:00
|
|
|
|
{
|
2013-09-11 08:33:47 +02:00
|
|
|
|
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
|
2013-04-14 01:57:10 +02:00
|
|
|
|
{
|
2013-09-11 08:33:47 +02:00
|
|
|
|
var restClient = new RestClient(Services.RootUrl);
|
2013-04-14 01:57:10 +02:00
|
|
|
|
|
2013-09-11 08:33:47 +02: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 01:57:10 +02:00
|
|
|
|
|
2013-08-24 04:21:12 +02:00
|
|
|
|
if (!update.Available) return null;
|
2013-04-14 01:57:10 +02:00
|
|
|
|
|
2013-08-24 04:21:12 +02:00
|
|
|
|
return update.UpdatePackage;
|
2013-04-15 03:41:39 +02:00
|
|
|
|
}
|
2013-04-14 01:57:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|