Skip to content

Commit 917f215

Browse files
algolia-bote-krebsshortcutsmillotp
committed
feat(specs): rename composition to composition-full (private) and add composition (public) (generated)
algolia/api-clients-automation#4357 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Emmanuel Krebs <[email protected]> Co-authored-by: shortcuts <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 6a9004b commit 917f215

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+7578
-0
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
//
2+
// 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.
3+
//
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net.Http;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Algolia.Search.Models.Composition;
10+
using Algolia.Search.Transport;
11+
using Algolia.Search.Http;
12+
using Algolia.Search.Utils;
13+
using Microsoft.Extensions.Logging;
14+
using Microsoft.Extensions.Logging.Abstractions;
15+
16+
namespace Algolia.Search.Clients;
17+
18+
19+
/// <summary>
20+
/// Represents a collection of functions to interact with the API endpoints
21+
/// </summary>
22+
public interface ICompositionClient
23+
{
24+
/// <summary>
25+
/// Runs a query on a single composition and returns matching results.
26+
/// </summary>
27+
///
28+
/// Required API Key ACLs:
29+
/// - search
30+
/// <param name="compositionID">Unique Composition ObjectID.</param>
31+
/// <param name="requestBody"></param>
32+
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
33+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
34+
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
35+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
36+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
37+
/// <returns>Task of SearchResponse{T}</returns>
38+
Task<SearchResponse<T>> SearchAsync<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default);
39+
40+
/// <summary>
41+
/// Runs a query on a single composition and returns matching results. (Synchronous version)
42+
/// </summary>
43+
///
44+
/// Required API Key ACLs:
45+
/// - search
46+
/// <param name="compositionID">Unique Composition ObjectID.</param>
47+
/// <param name="requestBody"></param>
48+
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
49+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
50+
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
51+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
52+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
53+
/// <returns>SearchResponse{T}</returns>
54+
SearchResponse<T> Search<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default);
55+
56+
/// <summary>
57+
/// 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**.
58+
/// </summary>
59+
///
60+
/// Required API Key ACLs:
61+
/// - search
62+
/// <param name="compositionID">Unique Composition ObjectID.</param>
63+
/// <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>
64+
/// <param name="searchForFacetValuesRequest"> (optional)</param>
65+
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
66+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
67+
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
68+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
69+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
70+
/// <returns>Task of SearchForFacetValuesResponse</returns>
71+
Task<SearchForFacetValuesResponse> SearchForFacetValuesAsync(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default);
72+
73+
/// <summary>
74+
/// 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)
75+
/// </summary>
76+
///
77+
/// Required API Key ACLs:
78+
/// - search
79+
/// <param name="compositionID">Unique Composition ObjectID.</param>
80+
/// <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>
81+
/// <param name="searchForFacetValuesRequest"> (optional)</param>
82+
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
83+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
84+
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
85+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
86+
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
87+
/// <returns>SearchForFacetValuesResponse</returns>
88+
SearchForFacetValuesResponse SearchForFacetValues(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default);
89+
90+
}
91+
92+
93+
94+
/// <summary>
95+
/// Represents a collection of functions to interact with the API endpoints
96+
/// </summary>
97+
public partial class CompositionClient : ICompositionClient
98+
{
99+
internal HttpTransport _transport;
100+
private readonly ILogger<CompositionClient> _logger;
101+
102+
/// <summary>
103+
/// Create a new Composition client for the given appID and apiKey.
104+
/// </summary>
105+
/// <param name="applicationId">Your application</param>
106+
/// <param name="apiKey">Your API key</param>
107+
/// <param name="loggerFactory">Logger factory</param>
108+
109+
public CompositionClient(string applicationId, string apiKey, ILoggerFactory loggerFactory = null) : this(new CompositionConfig(applicationId, apiKey), new AlgoliaHttpRequester(loggerFactory), loggerFactory)
110+
{
111+
}
112+
113+
/// <summary>
114+
/// Initialize a client with custom config
115+
/// </summary>
116+
/// <param name="config">Algolia configuration</param>
117+
/// <param name="loggerFactory">Logger factory</param>
118+
public CompositionClient(CompositionConfig config, ILoggerFactory loggerFactory = null) : this(config, new AlgoliaHttpRequester(loggerFactory), loggerFactory)
119+
{
120+
}
121+
122+
/// <summary>
123+
/// Initialize the client with custom config and custom Requester
124+
/// </summary>
125+
/// <param name="config">Algolia Config</param>
126+
/// <param name="httpRequester">Your Http requester implementation of <see cref="IHttpRequester"/></param>
127+
/// <param name="loggerFactory">Logger factory</param>
128+
public CompositionClient(CompositionConfig config, IHttpRequester httpRequester, ILoggerFactory loggerFactory = null)
129+
{
130+
if (httpRequester == null)
131+
{
132+
throw new ArgumentException("An httpRequester is required");
133+
}
134+
if (config == null)
135+
{
136+
throw new ArgumentException("A config is required");
137+
}
138+
if (string.IsNullOrWhiteSpace(config.AppId))
139+
{
140+
throw new ArgumentException("`AppId` is missing.");
141+
}
142+
if (string.IsNullOrWhiteSpace(config.ApiKey))
143+
{
144+
throw new ArgumentException("`ApiKey` is missing.");
145+
}
146+
147+
var factory = loggerFactory ?? NullLoggerFactory.Instance;
148+
_transport = new HttpTransport(config, httpRequester, factory);
149+
_logger = factory.CreateLogger<CompositionClient>();
150+
151+
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information))
152+
{
153+
_logger.LogInformation("Algolia Composition client is initialized.");
154+
}
155+
}
156+
157+
/// <summary>
158+
/// Helper to switch the API key sent with each request
159+
/// </summary>
160+
/// <param name="apiKey">Your new API Key</param>
161+
/// <returns></returns>
162+
public void SetClientApiKey(string apiKey)
163+
{
164+
_transport._algoliaConfig.SetClientApiKey(apiKey);
165+
}
166+
167+
168+
169+
/// <inheritdoc />
170+
public async Task<SearchResponse<T>> SearchAsync<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default)
171+
{
172+
173+
if (compositionID == null)
174+
throw new ArgumentException("Parameter `compositionID` is required when calling `Search`.");
175+
176+
177+
if (requestBody == null)
178+
throw new ArgumentException("Parameter `requestBody` is required when calling `Search`.");
179+
180+
var requestOptions = new InternalRequestOptions(options);
181+
182+
requestOptions.PathParameters.Add("compositionID", QueryStringHelper.ParameterToString(compositionID));
183+
184+
requestOptions.Data = requestBody;
185+
requestOptions.UseReadTransporter = true;
186+
return await _transport.ExecuteRequestAsync<SearchResponse<T>>(new HttpMethod("POST"), "/1/compositions/{compositionID}/run", requestOptions, cancellationToken).ConfigureAwait(false);
187+
}
188+
189+
190+
/// <inheritdoc />
191+
public SearchResponse<T> Search<T>(string compositionID, RequestBody requestBody, RequestOptions options = null, CancellationToken cancellationToken = default) =>
192+
AsyncHelper.RunSync(() => SearchAsync<T>(compositionID, requestBody, options, cancellationToken));
193+
194+
195+
/// <inheritdoc />
196+
public async Task<SearchForFacetValuesResponse> SearchForFacetValuesAsync(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default)
197+
{
198+
199+
if (compositionID == null)
200+
throw new ArgumentException("Parameter `compositionID` is required when calling `SearchForFacetValues`.");
201+
202+
203+
if (facetName == null)
204+
throw new ArgumentException("Parameter `facetName` is required when calling `SearchForFacetValues`.");
205+
206+
var requestOptions = new InternalRequestOptions(options);
207+
208+
requestOptions.PathParameters.Add("compositionID", QueryStringHelper.ParameterToString(compositionID));
209+
requestOptions.PathParameters.Add("facetName", QueryStringHelper.ParameterToString(facetName));
210+
211+
requestOptions.Data = searchForFacetValuesRequest;
212+
requestOptions.UseReadTransporter = true;
213+
return await _transport.ExecuteRequestAsync<SearchForFacetValuesResponse>(new HttpMethod("POST"), "/1/compositions/{compositionID}/facets/{facetName}/query", requestOptions, cancellationToken).ConfigureAwait(false);
214+
}
215+
216+
217+
/// <inheritdoc />
218+
public SearchForFacetValuesResponse SearchForFacetValues(string compositionID, string facetName, SearchForFacetValuesRequest searchForFacetValuesRequest = default, RequestOptions options = null, CancellationToken cancellationToken = default) =>
219+
AsyncHelper.RunSync(() => SearchForFacetValuesAsync(compositionID, facetName, searchForFacetValuesRequest, options, cancellationToken));
220+
221+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Composition API
3+
*
4+
* Composition API.
5+
*
6+
* The version of the OpenAPI document: 1.0.0
7+
* Generated by: https://github.com/openapitools/openapi-generator.git
8+
*/
9+
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using Algolia.Search.Models.Common;
14+
using Algolia.Search.Transport;
15+
using Algolia.Search.Utils;
16+
17+
namespace Algolia.Search.Clients;
18+
19+
/// <summary>
20+
/// Composition client configuration
21+
/// </summary>
22+
public sealed class CompositionConfig : AlgoliaConfig
23+
{
24+
/// <summary>
25+
/// The configuration of the Composition client
26+
/// A client should have it's own configuration ie on configuration per client instance
27+
/// </summary>
28+
/// <param name="appId">Your application ID</param>
29+
/// <param name="apiKey">Your API Key</param>
30+
public CompositionConfig(string appId, string apiKey) : base(appId, apiKey, "Composition", "7.12.0")
31+
{
32+
DefaultHosts = GetDefaultHosts(appId);
33+
Compression = CompressionType.None;
34+
ReadTimeout = TimeSpan.FromMilliseconds(5000);
35+
WriteTimeout = TimeSpan.FromMilliseconds(30000);
36+
ConnectTimeout = TimeSpan.FromMilliseconds(2000);
37+
}
38+
private static List<StatefulHost> GetDefaultHosts(string appId)
39+
{
40+
var hosts = new List<StatefulHost>
41+
{
42+
new()
43+
{
44+
Url = $"{appId}-dsn.algolia.net",
45+
Up = true,
46+
LastUse = DateTime.UtcNow,
47+
Accept = CallType.Read
48+
},
49+
new()
50+
{
51+
Url = $"{appId}.algolia.net", Up = true, LastUse = DateTime.UtcNow, Accept = CallType.Write,
52+
}
53+
};
54+
55+
var commonHosts = new List<StatefulHost>
56+
{
57+
new()
58+
{
59+
Url = $"{appId}-1.algolianet.com",
60+
Up = true,
61+
LastUse = DateTime.UtcNow,
62+
Accept = CallType.Read | CallType.Write,
63+
},
64+
new()
65+
{
66+
Url = $"{appId}-2.algolianet.com",
67+
Up = true,
68+
LastUse = DateTime.UtcNow,
69+
Accept = CallType.Read | CallType.Write,
70+
},
71+
new()
72+
{
73+
Url = $"{appId}-3.algolianet.com",
74+
Up = true,
75+
LastUse = DateTime.UtcNow,
76+
Accept = CallType.Read | CallType.Write,
77+
}
78+
}.Shuffle();
79+
80+
hosts.AddRange(commonHosts);
81+
return hosts;
82+
}
83+
}

0 commit comments

Comments
 (0)