forked from loic-sharma/BaGet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Client SDK] Separate search and autocomplete clients (loic-sharma#470)
Addresses loic-sharma#468
- Loading branch information
1 parent
bd44019
commit 30aa9c2
Showing
11 changed files
with
345 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BaGet.Protocol.Models; | ||
|
||
namespace BaGet.Protocol | ||
{ | ||
public partial class NuGetClientFactory | ||
{ | ||
private class AutocompleteClient : IAutocompleteClient | ||
{ | ||
private readonly NuGetClientFactory _clientfactory; | ||
|
||
public AutocompleteClient(NuGetClientFactory clientFactory) | ||
{ | ||
_clientfactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); | ||
} | ||
|
||
public async Task<AutocompleteResponse> AutocompleteAsync( | ||
string query = null, | ||
int skip = 0, | ||
int take = 20, | ||
bool includePrerelease = true, | ||
bool includeSemVer2 = true, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
// TODO: Support search failover. | ||
// See: https://github.com/loic-sharma/BaGet/issues/314 | ||
var client = await _clientfactory.GetAutocompleteClientAsync(cancellationToken); | ||
|
||
return await client.AutocompleteAsync(query, skip, take, includePrerelease, includeSemVer2, cancellationToken); | ||
} | ||
|
||
public async Task<AutocompleteResponse> ListPackageVersionsAsync( | ||
string packageId, | ||
bool includePrerelease = true, | ||
bool includeSemVer2 = true, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
// TODO: Support search failover. | ||
// See: https://github.com/loic-sharma/BaGet/issues/314 | ||
var client = await _clientfactory.GetAutocompleteClientAsync(cancellationToken); | ||
|
||
return await client.ListPackageVersionsAsync(packageId, includePrerelease, includeSemVer2, cancellationToken); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BaGet.Protocol.Models; | ||
|
||
namespace BaGet.Protocol | ||
{ | ||
/// <summary> | ||
/// The client used to search for packages. | ||
/// | ||
/// See https://docs.microsoft.com/en-us/nuget/api/search-autocomplete-service-resource | ||
/// </summary> | ||
public interface IAutocompleteClient | ||
{ | ||
/// <summary> | ||
/// Perform an autocomplete query on package IDs. | ||
/// See: https://docs.microsoft.com/en-us/nuget/api/search-autocomplete-service-resource#search-for-package-ids | ||
/// </summary> | ||
/// <param name="query">The autocomplete query.</param> | ||
/// <param name="skip">How many results to skip.</param> | ||
/// <param name="take">How many results to return.</param> | ||
/// <param name="includePrerelease">Whether pre-release packages should be returned.</param> | ||
/// <param name="includeSemVer2">Whether packages that require SemVer 2.0.0 compatibility should be returned.</param> | ||
/// <param name="cancellationToken">A token to cancel the task.</param> | ||
/// <returns>The autocomplete response.</returns> | ||
Task<AutocompleteResponse> AutocompleteAsync( | ||
string query = null, | ||
int skip = 0, | ||
int take = 20, | ||
bool includePrerelease = true, | ||
bool includeSemVer2 = true, | ||
CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Enumerate listed package versions. | ||
/// See: https://docs.microsoft.com/en-us/nuget/api/search-autocomplete-service-resource#enumerate-package-versions | ||
/// </summary> | ||
/// <param name="packageId">The package ID.</param> | ||
/// <param name="includePrerelease">Whether pre-release packages should be returned.</param> | ||
/// <param name="includeSemVer2">Whether packages that require SemVer 2.0.0 compatibility should be returned.</param> | ||
/// <param name="cancellationToken">A token to cancel the task.</param> | ||
/// <returns>The package versions that matched the request.</returns> | ||
Task<AutocompleteResponse> ListPackageVersionsAsync( | ||
string packageId, | ||
bool includePrerelease = true, | ||
bool includeSemVer2 = true, | ||
CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.