|
| 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 | +} |
0 commit comments