Skip to content

Commit

Permalink
rollback a bit (generated)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
algolia-bot and millotp committed Jan 21, 2025
1 parent 660bea5 commit 9785b90
Show file tree
Hide file tree
Showing 675 changed files with 79,025 additions and 5,999 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
//
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Algolia.Search.Models.Composition;
using Algolia.Search.Transport;
using Algolia.Search.Http;
using Algolia.Search.Utils;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Algolia.Search.Clients;


/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface ICompositionClient
{
/// <summary>
/// Runs a query on a single composition and returns matching results.
/// </summary>
///
/// Required API Key ACLs:
/// - search
/// <param name="compositionID">Unique Composition ObjectID.</param>
/// <param name="requestBody"></param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>Task of SearchResponse{T}</returns>
Task<SearchResponse<T>> SearchAsync<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Runs a query on a single composition and returns matching results. (Synchronous version)
/// </summary>
///
/// Required API Key ACLs:
/// - search
/// <param name="compositionID">Unique Composition ObjectID.</param>
/// <param name="requestBody"></param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>SearchResponse{T}</returns>
SearchResponse<T> Search<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**.
/// </summary>
///
/// Required API Key ACLs:
/// - search
/// <param name="compositionID">Unique Composition ObjectID.</param>
/// <param name="facetName">Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. </param>
/// <param name="searchForFacetValuesRequest"> (optional)</param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>Task of SearchForFacetValuesResponse</returns>
Task<SearchForFacetValuesResponse> SearchForFacetValuesAsync(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default);

/// <summary>
/// Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. (Synchronous version)
/// </summary>
///
/// Required API Key ACLs:
/// - search
/// <param name="compositionID">Unique Composition ObjectID.</param>
/// <param name="facetName">Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. </param>
/// <param name="searchForFacetValuesRequest"> (optional)</param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>SearchForFacetValuesResponse</returns>
SearchForFacetValuesResponse SearchForFacetValues(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default);

}



/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public partial class CompositionClient : ICompositionClient
{
internal HttpTransport _transport;
private readonly ILogger<CompositionClient> _logger;

/// <summary>
/// Create a new Composition client for the given appID and apiKey.
/// </summary>
/// <param name="applicationId">Your application</param>
/// <param name="apiKey">Your API key</param>
/// <param name="loggerFactory">Logger factory</param>

public CompositionClient(string applicationId, string apiKey, ILoggerFactory loggerFactory = null) : this(new CompositionConfig(applicationId, apiKey), new AlgoliaHttpRequester(loggerFactory), loggerFactory)
{
}

/// <summary>
/// Initialize a client with custom config
/// </summary>
/// <param name="config">Algolia configuration</param>
/// <param name="loggerFactory">Logger factory</param>
public CompositionClient(CompositionConfig config, ILoggerFactory loggerFactory = null) : this(config, new AlgoliaHttpRequester(loggerFactory), loggerFactory)
{
}

/// <summary>
/// Initialize the client with custom config and custom Requester
/// </summary>
/// <param name="config">Algolia Config</param>
/// <param name="httpRequester">Your Http requester implementation of <see cref="IHttpRequester"/></param>
/// <param name="loggerFactory">Logger factory</param>
public CompositionClient(CompositionConfig config, IHttpRequester httpRequester, ILoggerFactory loggerFactory = null)
{
if (httpRequester == null)
{
throw new ArgumentException("An httpRequester is required");
}
if (config == null)
{
throw new ArgumentException("A config is required");
}
if (string.IsNullOrWhiteSpace(config.AppId))
{
throw new ArgumentException("`AppId` is missing.");
}
if (string.IsNullOrWhiteSpace(config.ApiKey))
{
throw new ArgumentException("`ApiKey` is missing.");
}

var factory = loggerFactory ?? NullLoggerFactory.Instance;
_transport = new HttpTransport(config, httpRequester, factory);
_logger = factory.CreateLogger<CompositionClient>();

if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information))
{
_logger.LogInformation("Algolia Composition client is initialized.");
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<SearchResponse<T>> SearchAsync<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default)
{

if (compositionID == null)
throw new ArgumentException("Parameter `compositionID` is required when calling `Search`.");


if (requestBody == null)
throw new ArgumentException("Parameter `requestBody` is required when calling `Search`.");

var requestOptions = new InternalRequestOptions(options);

requestOptions.PathParameters.Add("compositionID", QueryStringHelper.ParameterToString(compositionID));

requestOptions.Data = requestBody;
requestOptions.UseReadTransporter = true;
return await _transport.ExecuteRequestAsync<SearchResponse<T>>(new HttpMethod("POST"), "/1/compositions/{compositionID}/run", requestOptions, cancellationToken).ConfigureAwait(false);
}


/// <inheritdoc />
public SearchResponse<T> Search<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default) =>
AsyncHelper.RunSync(() => SearchAsync<T>(compositionID, requestBody, options, cancellationToken));


/// <inheritdoc />
public async Task<SearchForFacetValuesResponse> SearchForFacetValuesAsync(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default)
{

if (compositionID == null)
throw new ArgumentException("Parameter `compositionID` is required when calling `SearchForFacetValues`.");


if (facetName == null)
throw new ArgumentException("Parameter `facetName` is required when calling `SearchForFacetValues`.");

var requestOptions = new InternalRequestOptions(options);

requestOptions.PathParameters.Add("compositionID", QueryStringHelper.ParameterToString(compositionID));
requestOptions.PathParameters.Add("facetName", QueryStringHelper.ParameterToString(facetName));

requestOptions.Data = searchForFacetValuesRequest;
requestOptions.UseReadTransporter = true;
return await _transport.ExecuteRequestAsync<SearchForFacetValuesResponse>(new HttpMethod("POST"), "/1/compositions/{compositionID}/facets/{facetName}/query", requestOptions, cancellationToken).ConfigureAwait(false);
}


/// <inheritdoc />
public SearchForFacetValuesResponse SearchForFacetValues(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default) =>
AsyncHelper.RunSync(() => SearchForFacetValuesAsync(compositionID, facetName, searchForFacetValuesRequest, options, cancellationToken));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Composition API
*
* Composition API.
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using System;
using System.Collections.Generic;
using Algolia.Search.Models.Common;
using Algolia.Search.Transport;
using Algolia.Search.Utils;

namespace Algolia.Search.Clients;

/// <summary>
/// Composition client configuration
/// </summary>
public sealed class CompositionConfig : AlgoliaConfig
{
/// <summary>
/// The configuration of the Composition client
/// A client should have it's own configuration ie on configuration per client instance
/// </summary>
/// <param name="appId">Your application ID</param>
/// <param name="apiKey">Your API Key</param>
public CompositionConfig(string appId, string apiKey) : base(appId, apiKey, "Composition", "7.12.0")
{
DefaultHosts = GetDefaultHosts(appId);
Compression = CompressionType.None;
ReadTimeout = TimeSpan.FromMilliseconds(5000);
WriteTimeout = TimeSpan.FromMilliseconds(30000);
ConnectTimeout = TimeSpan.FromMilliseconds(2000);
}
private static List<StatefulHost> GetDefaultHosts(string appId)
{
var hosts = new List<StatefulHost>
{
new()
{
Url = $"{appId}-dsn.algolia.net",
Up = true,
LastUse = DateTime.UtcNow,
Accept = CallType.Read
},
new()
{
Url = $"{appId}.algolia.net", Up = true, LastUse = DateTime.UtcNow, Accept = CallType.Write,
}
};

var commonHosts = new List<StatefulHost>
{
new()
{
Url = $"{appId}-1.algolianet.com",
Up = true,
LastUse = DateTime.UtcNow,
Accept = CallType.Read | CallType.Write,
},
new()
{
Url = $"{appId}-2.algolianet.com",
Up = true,
LastUse = DateTime.UtcNow,
Accept = CallType.Read | CallType.Write,
},
new()
{
Url = $"{appId}-3.algolianet.com",
Up = true,
LastUse = DateTime.UtcNow,
Accept = CallType.Read | CallType.Write,
}
}.Shuffle();

hosts.AddRange(commonHosts);
return hosts;
}
}
Loading

0 comments on commit 9785b90

Please sign in to comment.