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

52 lines
1.8 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 IDroneServicesRequestBuilder _requestBuilder;
10 years ago
public UpdatePackageProvider(IHttpClient httpClient, IDroneServicesRequestBuilder requestBuilder)
{
_httpClient = httpClient;
_requestBuilder = requestBuilder;
}
11 years ago
10 years ago
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
{
var request = _requestBuilder.Build("/update/{branch}");
request.UriBuilder.SetQueryParam("version", currentVersion);
request.UriBuilder.SetQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddSegment("branch", branch);
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)
{
10 years ago
var request = _requestBuilder.Build("/update/{branch}/changes");
request.UriBuilder.SetQueryParam("version", currentVersion);
10 years ago
request.UriBuilder.SetQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddSegment("branch", branch);
10 years ago
var updates = _httpClient.Get<List<UpdatePackage>>(request);
10 years ago
return updates.Resource;
}
}
}