HttpClient

This commit is contained in:
Keivan Beigi
2014-09-11 16:49:41 -07:00
parent 3a287bf7e7
commit 2c1d3339d0
55 changed files with 995 additions and 582 deletions

View File

@@ -26,7 +26,7 @@ namespace NzbDrone.Core.Update
private readonly IAppFolderInfo _appFolderInfo;
private readonly IDiskProvider _diskProvider;
private readonly IHttpProvider _httpProvider;
private readonly IHttpClient _httpClient;
private readonly IArchiveService _archiveService;
private readonly IProcessProvider _processProvider;
private readonly IVerifyUpdates _updateVerifier;
@@ -36,7 +36,7 @@ namespace NzbDrone.Core.Update
public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppFolderInfo appFolderInfo,
IDiskProvider diskProvider, IHttpProvider httpProvider,
IDiskProvider diskProvider, IHttpClient httpClient,
IArchiveService archiveService, IProcessProvider processProvider,
IVerifyUpdates updateVerifier,
IConfigFileProvider configFileProvider,
@@ -51,7 +51,7 @@ namespace NzbDrone.Core.Update
_checkUpdateService = checkUpdateService;
_appFolderInfo = appFolderInfo;
_diskProvider = diskProvider;
_httpProvider = httpProvider;
_httpClient = httpClient;
_archiveService = archiveService;
_processProvider = processProvider;
_updateVerifier = updateVerifier;
@@ -79,7 +79,7 @@ namespace NzbDrone.Core.Update
_logger.ProgressInfo("Downloading update {0}", updatePackage.Version);
_logger.Debug("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
_httpClient.DownloadFile(updatePackage.Url, packageDestination);
_logger.ProgressInfo("Verifying update package");

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.Update
@@ -23,7 +24,7 @@ namespace NzbDrone.Core.Update
public List<UpdatePackage> GetRecentUpdatePackages()
{
var branch = _configFileProvider.Branch;
return _updatePackageProvider.GetRecentUpdates(branch);
return _updatePackageProvider.GetRecentUpdates(branch, BuildInfo.Version.Major);
}
}
}

View File

@@ -6,7 +6,6 @@ namespace NzbDrone.Core.Update
public class UpdatePackage
{
public Version Version { get; set; }
public String Branch { get; set; }
public DateTime ReleaseDate { get; set; }
public String FileName { get; set; }
public String Url { get; set; }

View File

@@ -1,50 +1,51 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.EnvironmentInfo;
using RestSharp;
using NzbDrone.Core.Rest;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.Update
{
public interface IUpdatePackageProvider
{
UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
List<UpdatePackage> GetRecentUpdates(string branch);
List<UpdatePackage> GetRecentUpdates(string branch, int majorVersion);
}
public class UpdatePackageProvider : IUpdatePackageProvider
{
private readonly IHttpClient _httpClient;
private readonly IDroneServicesRequestBuilder _requestBuilder;
public UpdatePackageProvider(IHttpClient httpClient, IDroneServicesRequestBuilder requestBuilder)
{
_httpClient = httpClient;
_requestBuilder = requestBuilder;
}
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
{
var restClient = RestClientFactory.BuildClient(Services.RootUrl);
var request = _requestBuilder.Build("/update/{branch}");
request.UriBuilder.SetQueryParam("version", currentVersion);
request.UriBuilder.SetQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddSegment("branch", branch);
var request = new RestRequest("/v1/update/{branch}");
request.AddParameter("version", currentVersion);
request.AddParameter("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddUrlSegment("branch", branch);
var update = restClient.ExecuteAndValidate<UpdatePackageAvailable>(request);
var update = _httpClient.Get<UpdatePackageAvailable>(request).Resource;
if (!update.Available) return null;
return update.UpdatePackage;
}
public List<UpdatePackage> GetRecentUpdates(string branch)
public List<UpdatePackage> GetRecentUpdates(string branch, int majorVersion)
{
var restClient = RestClientFactory.BuildClient(Services.RootUrl);
var request = _requestBuilder.Build("/update/{branch}/changes");
request.UriBuilder.SetQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddSegment("branch", branch);
var request = new RestRequest("/v1/update/{branch}/changes");
var updates = _httpClient.Get<List<UpdatePackage>>(request);
request.AddParameter("majorVersion", BuildInfo.Version.Major);
request.AddParameter("os", OsInfo.Os.ToString().ToLowerInvariant());
request.AddUrlSegment("branch", branch);
var updates = restClient.ExecuteAndValidate<List<UpdatePackage>>(request);
return updates;
return updates.Resource;
}
}
}