You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/Update/UpdatePackageProvider.cs

60 lines
2.4 KiB

using System;
using System.Collections.Generic;
10 years ago
using NzbDrone.Common.Cloud;
using NzbDrone.Common.EnvironmentInfo;
10 years ago
using NzbDrone.Common.Http;
namespace NzbDrone.Core.Update
{
public interface IUpdatePackageProvider
{
11 years ago
UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion);
}
public class UpdatePackageProvider : IUpdatePackageProvider
{
10 years ago
private readonly IHttpClient _httpClient;
private readonly IPlatformInfo _platformInfo;
private readonly IHttpRequestBuilderFactory _requestBuilder;
public UpdatePackageProvider(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, IPlatformInfo platformInfo)
10 years ago
{
_httpClient = httpClient;
_platformInfo = platformInfo;
_requestBuilder = requestBuilder.Services;
10 years ago
}
11 years ago
10 years ago
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
{
var request = _requestBuilder.Create()
.Resource("/update/{branch}")
.AddQueryParam("version", currentVersion)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch)
.Build();
11 years ago
10 years ago
var update = _httpClient.Get<UpdatePackageAvailable>(request).Resource;
if (!update.Available) return null;
return update.UpdatePackage;
}
public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion)
{
var request = _requestBuilder.Create()
.Resource("/update/{branch}/changes")
.AddQueryParam("version", currentVersion)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch)
.Build();
10 years ago
var updates = _httpClient.Get<List<UpdatePackage>>(request);
10 years ago
return updates.Resource;
}
}
}