From e46ac5c85b5cec3c1ba6502b8bd0e28c21bbeb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 19 Apr 2022 14:16:12 +0200 Subject: [PATCH 1/6] chore: use `Client` suffix --- .github/.cache_version | 2 +- .github/actions/cache/action.yml | 42 +- .../com/algolia/api/AbtestingApi.java | 955 --- .../com/algolia/api/AnalyticsApi.java | 3432 --------- .../com/algolia/api/InsightsApi.java | 581 -- .../com/algolia/api/PersonalizationApi.java | 878 --- .../com/algolia/api/PredictApi.java | 600 -- .../com/algolia/api/QuerySuggestionsApi.java | 1154 --- .../com/algolia/api/RecommendApi.java | 626 -- .../com/algolia/api/SearchApi.java | 6644 ----------------- .../src/algoliasearchLiteApi.ts | 305 - .../packages/algoliasearch/builds/browser.ts | 26 +- .../packages/algoliasearch/builds/node.ts | 24 +- .../client-abtesting/src/abtestingApi.ts | 503 -- .../client-analytics/src/analyticsApi.ts | 1799 ----- .../client-insights/src/insightsApi.ts | 305 - .../src/personalizationApi.ts | 434 -- .../packages/client-predict/src/predictApi.ts | 312 - .../src/querySuggestionsApi.ts | 573 -- .../packages/client-search/src/searchApi.ts | 3354 --------- .../packages/recommend/src/recommendApi.ts | 325 - .../lib/Api/AbtestingApi.php | 455 -- .../lib/Api/AnalyticsApi.php | 1771 ----- .../lib/Api/InsightsApi.php | 319 - .../lib/Api/PersonalizationApi.php | 401 - .../lib/Api/QuerySuggestionsApi.php | 510 -- .../lib/Api/RecommendApi.php | 320 - .../lib/Api/SearchApi.php | 2713 ------- .../algolia/codegen/AlgoliaJavaGenerator.java | 2 + .../codegen/AlgoliaJavascriptGenerator.java | 39 +- .../algolia/codegen/AlgoliaPhpGenerator.java | 2 + .../main/java/com/algolia/codegen/Utils.java | 3 + .../codegen/cts/AlgoliaCtsGenerator.java | 2 +- .../main/java/com/algolia/playground/App.java | 28 +- playground/javascript/browser/app.ts | 4 +- playground/javascript/node/abtesting.ts | 4 +- playground/javascript/node/analytics.ts | 4 +- playground/javascript/node/insights.ts | 4 +- playground/javascript/node/personalization.ts | 4 +- playground/javascript/node/predict.ts | 4 +- .../javascript/node/query-suggestions.ts | 4 +- playground/javascript/node/recommend.ts | 4 +- playground/javascript/node/search.ts | 4 +- playground/javascript/node/sources.ts | 4 +- playground/php/src/abtesting.php | 4 +- playground/php/src/analytics.php | 4 +- playground/php/src/insights.php | 4 +- playground/php/src/personalization.php | 4 +- playground/php/src/query-suggestions.php | 4 +- playground/php/src/recommend.php | 4 +- playground/php/src/search.php | 4 +- scripts/ci/createMatrix.ts | 2 +- scripts/cts/client/generate.ts | 2 +- .../methods/requests/abtesting.test.java | 8 +- .../methods/requests/analytics.test.java | 8 +- .../methods/requests/insights.test.java | 8 +- .../requests/personalization.test.java | 8 +- .../requests/query-suggestions.test.java | 8 +- .../methods/requests/recommend.test.java | 8 +- .../algolia/methods/requests/search.test.java | 8 +- .../javascript/src/client/abtesting.test.ts | 6 +- .../javascript/src/client/analytics.test.ts | 6 +- .../javascript/src/client/insights.test.ts | 6 +- .../src/client/personalization.test.ts | 8 +- .../src/client/query-suggestions.test.ts | 8 +- .../javascript/src/client/recommend.test.ts | 4 +- .../javascript/src/client/search.test.ts | 12 +- .../javascript/src/client/sources.test.ts | 8 +- .../src/methods/requests/abtesting.test.ts | 4 +- .../src/methods/requests/analytics.test.ts | 4 +- .../src/methods/requests/insights.test.ts | 6 +- .../methods/requests/personalization.test.ts | 4 +- .../requests/query-suggestions.test.ts | 4 +- .../src/methods/requests/recommend.test.ts | 4 +- .../src/methods/requests/search.test.ts | 4 +- .../src/methods/requests/sources.test.ts | 6 +- ...SearchApiTest.php => SearchClientTest.php} | 2 +- website/docs/addNewLanguage.md | 2 +- website/docs/gettingStarted.mdx | 8 +- 79 files changed, 227 insertions(+), 29446 deletions(-) delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java delete mode 100644 clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts delete mode 100644 clients/algoliasearch-client-php/lib/Api/AbtestingApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/InsightsApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/RecommendApi.php delete mode 100644 clients/algoliasearch-client-php/lib/Api/SearchApi.php rename tests/output/php/src/{SearchApiTest.php => SearchClientTest.php} (80%) diff --git a/.github/.cache_version b/.github/.cache_version index 50c496d20c..dcffda3e5c 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.4 +8.0.4.1 diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 5936f42cd5..9993996a16 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -384,7 +384,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/SearchApi.java', + 'clients/algoliasearch-client-java-2/api/SearchClient.java', 'clients/algoliasearch-client-java-2/model/search/**', 'specs/bundled/search.yml', 'templates/java/**', @@ -399,7 +399,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/RecommendApi.java', + 'clients/algoliasearch-client-java-2/api/RecommendClient.java', 'clients/algoliasearch-client-java-2/model/recommend/**', 'specs/bundled/recommend.yml', 'templates/java/**', @@ -414,7 +414,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/PersonalizationApi.java', + 'clients/algoliasearch-client-java-2/api/PersonalizationClient.java', 'clients/algoliasearch-client-java-2/model/personalization/**', 'specs/bundled/personalization.yml', 'templates/java/**', @@ -429,7 +429,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/AnalyticsApi.java', + 'clients/algoliasearch-client-java-2/api/AnalyticsClient.java', 'clients/algoliasearch-client-java-2/model/analytics/**', 'specs/bundled/analytics.yml', 'templates/java/**', @@ -459,7 +459,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/AbtestingApi.java', + 'clients/algoliasearch-client-java-2/api/AbtestingClient.java', 'clients/algoliasearch-client-java-2/model/abtesting/**', 'specs/bundled/abtesting.yml', 'templates/java/**', @@ -474,7 +474,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/QuerySuggestionsApi.java', + 'clients/algoliasearch-client-java-2/api/QuerySuggestionsClient.java', 'clients/algoliasearch-client-java-2/model/querySuggestions/**', 'specs/bundled/query-suggestions.yml', 'templates/java/**', @@ -489,7 +489,7 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/api/PredictApi.java', + 'clients/algoliasearch-client-java-2/api/PredictClient.java', 'clients/algoliasearch-client-java-2/model/predict/**', 'specs/bundled/predict.yml', 'templates/java/**', @@ -502,12 +502,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/SearchApi.php + clients/algoliasearch-client-php/lib/Api/SearchClient.php clients/algoliasearch-client-php/lib/Model/Search/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/SearchApi.php', + 'clients/algoliasearch-client-php/lib/Api/SearchClient.php', 'clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php', 'clients/algoliasearch-client-php/lib/Model/Search/**', 'specs/bundled/search.yml', @@ -520,12 +520,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/RecommendApi.php + clients/algoliasearch-client-php/lib/Api/RecommendClient.php clients/algoliasearch-client-php/lib/Model/Recommend/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/RecommendApi.php', + 'clients/algoliasearch-client-php/lib/Api/RecommendClient.php', 'clients/algoliasearch-client-php/lib/Configuration/RecommendConfig.php', 'clients/algoliasearch-client-php/lib/Model/Recommend/**', 'specs/bundled/recommend.yml', @@ -538,12 +538,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php + clients/algoliasearch-client-php/lib/Api/PersonalizationClient.php clients/algoliasearch-client-php/lib/Model/Personalization/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php', + 'clients/algoliasearch-client-php/lib/Api/PersonalizationClient.php', 'clients/algoliasearch-client-php/lib/Configuration/PersonalizationConfig.php', 'clients/algoliasearch-client-php/lib/Model/Personalization/**', 'specs/bundled/personalization.yml', @@ -556,12 +556,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php + clients/algoliasearch-client-php/lib/Api/AnalyticsClient.php clients/algoliasearch-client-php/lib/Model/Analytics/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php', + 'clients/algoliasearch-client-php/lib/Api/AnalyticsClient.php', 'clients/algoliasearch-client-php/lib/Configuration/AnalyticsConfig.php', 'clients/algoliasearch-client-php/lib/Model/Analytics/**', 'specs/bundled/analytics.yml', @@ -574,12 +574,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/InsightsApi.php + clients/algoliasearch-client-php/lib/Api/InsightsClient.php clients/algoliasearch-client-php/lib/Model/Insights/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/InsightsApi.php', + 'clients/algoliasearch-client-php/lib/Api/InsightsClient.php', 'clients/algoliasearch-client-php/lib/Configuration/InsightsConfig.php', 'clients/algoliasearch-client-php/lib/Model/Insights/**', 'specs/bundled/insights.yml', @@ -592,12 +592,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/AbtestingApi.php + clients/algoliasearch-client-php/lib/Api/AbtestingClient.php clients/algoliasearch-client-php/lib/Model/Abtesting/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/AbtestingApi.php', + 'clients/algoliasearch-client-php/lib/Api/AbtestingClient.php', 'clients/algoliasearch-client-php/lib/Configuration/AbtestingConfig.php', 'clients/algoliasearch-client-php/lib/Model/Abtesting/**', 'specs/bundled/abtesting.yml', @@ -610,12 +610,12 @@ runs: uses: actions/cache@v2 with: path: | - clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php + clients/algoliasearch-client-php/lib/Api/QuerySuggestionsClient.php clients/algoliasearch-client-php/lib/Model/QuerySuggestions/** key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php', + 'clients/algoliasearch-client-php/lib/Api/QuerySuggestionsClient.php', 'clients/algoliasearch-client-php/lib/Configuration/QuerySuggestionsConfig.php', 'clients/algoliasearch-client-php/lib/Model/QuerySuggestions/**', 'specs/bundled/query-suggestions.yml', diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java deleted file mode 100644 index d4180e383b..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java +++ /dev/null @@ -1,955 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.abtesting.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class AbtestingApi extends ApiClient { - - public AbtestingApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); - } - - public AbtestingApi(String appId, String apiKey, String region) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); - } - - public AbtestingApi( - String appId, - String apiKey, - String region, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(region)), - userAgentSegments - ); - } - - public AbtestingApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public AbtestingApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Abtesting", userAgentSegments); - } - - private static List getDefaultHosts(String region) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "analytics." + (region == null ? "" : region + ".") + "algolia.com", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for addABTests - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call addABTestsCall( - AddABTestsRequest addABTestsRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = addABTestsRequest; - - // create path and map variables - String requestPath = "/2/abtests"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call addABTestsValidateBeforeCall( - AddABTestsRequest addABTestsRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'addABTestsRequest' is set - if (addABTestsRequest == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'addABTestsRequest' when calling addABTests(Async)" - ); - } - - return addABTestsCall(addABTestsRequest, callback); - } - - /** - * Creates a new A/B test with provided configuration. You can set an A/B test on two different - * indices with different settings, or on the same index with different search parameters by - * providing a customSearchParameters setting on one of the variants. - * - * @param addABTestsRequest (required) - * @return ABTestResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ABTestResponse addABTests(AddABTestsRequest addABTestsRequest) - throws AlgoliaRuntimeException { - Call req = addABTestsValidateBeforeCall(addABTestsRequest, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.AddABTests(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Creates a new A/B test with provided configuration. You can set an A/B test on - * two different indices with different settings, or on the same index with different search - * parameters by providing a customSearchParameters setting on one of the variants. - * - * @param addABTestsRequest (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call addABTestsAsync( - AddABTestsRequest addABTestsRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = addABTestsValidateBeforeCall(addABTestsRequest, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteABTest - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteABTestCall( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/2/abtests/{id}".replaceAll( - "\\{id\\}", - this.escapeString(id.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteABTestValidateBeforeCall( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'id' is set - if (id == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'id' when calling deleteABTest(Async)" - ); - } - - return deleteABTestCall(id, callback); - } - - /** - * Deletes the A/B Test and removes all associated metadata & metrics. - * - * @param id The A/B test ID. (required) - * @return ABTestResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ABTestResponse deleteABTest(Integer id) - throws AlgoliaRuntimeException { - Call req = deleteABTestValidateBeforeCall(id, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.DeleteABTest(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Deletes the A/B Test and removes all associated metadata & metrics. - * - * @param id The A/B test ID. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteABTestAsync( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteABTestValidateBeforeCall(id, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getABTest - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getABTestCall(Integer id, final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/2/abtests/{id}".replaceAll( - "\\{id\\}", - this.escapeString(id.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getABTestValidateBeforeCall( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'id' is set - if (id == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'id' when calling getABTest(Async)" - ); - } - - return getABTestCall(id, callback); - } - - /** - * Returns metadata and metrics for A/B test id. Behaves in the same way as GET /2/abtests however - * the endpoint will return 403. - * - * @param id The A/B test ID. (required) - * @return ABTest - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ABTest getABTest(Integer id) throws AlgoliaRuntimeException { - Call req = getABTestValidateBeforeCall(id, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.GetABTest(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns metadata and metrics for A/B test id. Behaves in the same way as GET - * /2/abtests however the endpoint will return 403. - * - * @param id The A/B test ID. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getABTestAsync(Integer id, final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = getABTestValidateBeforeCall(id, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listABTests - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listABTestsCall( - Integer offset, - Integer limit, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/abtests"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listABTestsValidateBeforeCall( - Integer offset, - Integer limit, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listABTestsCall(offset, limit, callback); - } - - /** - * Fetch all existing A/B tests for App that are available for the current API Key. Returns an - * array of metadata and metrics. When no data has been processed, the metrics will be returned as - * null. - * - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @return ListABTestsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListABTestsResponse listABTests(Integer offset, Integer limit) - throws AlgoliaRuntimeException { - Call req = listABTestsValidateBeforeCall(offset, limit, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.ListABTests(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public ListABTestsResponse listABTests() throws AlgoliaRuntimeException { - return this.listABTests(0, 10); - } - - /** - * (asynchronously) Fetch all existing A/B tests for App that are available for the current API - * Key. Returns an array of metadata and metrics. When no data has been processed, the metrics - * will be returned as null. - * - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listABTestsAsync( - Integer offset, - Integer limit, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listABTestsValidateBeforeCall(offset, limit, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for stopABTest - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call stopABTestCall( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/2/abtests/{id}/stop".replaceAll( - "\\{id\\}", - this.escapeString(id.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call stopABTestValidateBeforeCall( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'id' is set - if (id == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'id' when calling stopABTest(Async)" - ); - } - - return stopABTestCall(id, callback); - } - - /** - * Marks the A/B test as stopped. At this point, the test is over and cannot be restarted. As a - * result, your application is back to normal: index A will perform as usual, receiving 100% of - * all search requests. Associated metadata and metrics are still stored. - * - * @param id The A/B test ID. (required) - * @return ABTestResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ABTestResponse stopABTest(Integer id) throws AlgoliaRuntimeException { - Call req = stopABTestValidateBeforeCall(id, null); - if (req instanceof CallEcho) { - return new EchoResponseAbtesting.StopABTest(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Marks the A/B test as stopped. At this point, the test is over and cannot be - * restarted. As a result, your application is back to normal: index A will perform as usual, - * receiving 100% of all search requests. Associated metadata and metrics are still stored. - * - * @param id The A/B test ID. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call stopABTestAsync( - Integer id, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = stopABTestValidateBeforeCall(id, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java deleted file mode 100644 index 533474b900..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java +++ /dev/null @@ -1,3432 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.analytics.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class AnalyticsApi extends ApiClient { - - public AnalyticsApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); - } - - public AnalyticsApi(String appId, String apiKey, String region) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); - } - - public AnalyticsApi( - String appId, - String apiKey, - String region, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(region)), - userAgentSegments - ); - } - - public AnalyticsApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public AnalyticsApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Analytics", userAgentSegments); - } - - private static List getDefaultHosts(String region) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "analytics." + (region == null ? "" : region + ".") + "algolia.com", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getAverageClickPosition - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getAverageClickPositionCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/clicks/averageClickPosition"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getAverageClickPositionValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getAverageClickPosition(Async)" - ); - } - - return getAverageClickPositionCall( - index, - startDate, - endDate, - tags, - callback - ); - } - - /** - * Returns the average click position. The endpoint returns a value for the complete given time - * range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetAverageClickPositionResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetAverageClickPositionResponse getAverageClickPosition( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getAverageClickPositionValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetAverageClickPosition( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetAverageClickPositionResponse getAverageClickPosition(String index) - throws AlgoliaRuntimeException { - return this.getAverageClickPosition(index, null, null, null); - } - - /** - * (asynchronously) Returns the average click position. The endpoint returns a value for the - * complete given time range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAverageClickPositionAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getAverageClickPositionValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getClickPositions - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getClickPositionsCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/clicks/positions"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getClickPositionsValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getClickPositions(Async)" - ); - } - - return getClickPositionsCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns the distribution of clicks per range of positions. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetClickPositionsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetClickPositionsResponse getClickPositions( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getClickPositionsValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetClickPositions( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetClickPositionsResponse getClickPositions(String index) - throws AlgoliaRuntimeException { - return this.getClickPositions(index, null, null, null); - } - - /** - * (asynchronously) Returns the distribution of clicks per range of positions. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getClickPositionsAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getClickPositionsValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getClickThroughRate - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getClickThroughRateCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/clicks/clickThroughRate"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getClickThroughRateValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getClickThroughRate(Async)" - ); - } - - return getClickThroughRateCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns a click-through rate (CTR). The endpoint returns a value for the complete given time - * range, as well as a value per day. It also returns the count of clicks and searches used to - * compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetClickThroughRateResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetClickThroughRateResponse getClickThroughRate( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getClickThroughRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetClickThroughRate( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetClickThroughRateResponse getClickThroughRate(String index) - throws AlgoliaRuntimeException { - return this.getClickThroughRate(index, null, null, null); - } - - /** - * (asynchronously) Returns a click-through rate (CTR). The endpoint returns a value for the - * complete given time range, as well as a value per day. It also returns the count of clicks and - * searches used to compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getClickThroughRateAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getClickThroughRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getConversationRate - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getConversationRateCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/conversions/conversionRate"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getConversationRateValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getConversationRate(Async)" - ); - } - - return getConversationRateCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns a conversion rate (CR). The endpoint returns a value for the complete given time range, - * as well as a value per day. It also returns the count of conversion and searches used to - * compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetConversationRateResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetConversationRateResponse getConversationRate( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getConversationRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetConversationRate( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetConversationRateResponse getConversationRate(String index) - throws AlgoliaRuntimeException { - return this.getConversationRate(index, null, null, null); - } - - /** - * (asynchronously) Returns a conversion rate (CR). The endpoint returns a value for the complete - * given time range, as well as a value per day. It also returns the count of conversion and - * searches used to compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getConversationRateAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getConversationRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getNoClickRate - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getNoClickRateCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches/noClickRate"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getNoClickRateValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getNoClickRate(Async)" - ); - } - - return getNoClickRateCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns the rate at which searches didn't lead to any clicks. The endpoint returns a value for - * the complete given time range, as well as a value per day. It also returns the count of - * searches and searches without clicks. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetNoClickRateResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetNoClickRateResponse getNoClickRate( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getNoClickRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetNoClickRate( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetNoClickRateResponse getNoClickRate(String index) - throws AlgoliaRuntimeException { - return this.getNoClickRate(index, null, null, null); - } - - /** - * (asynchronously) Returns the rate at which searches didn't lead to any clicks. The endpoint - * returns a value for the complete given time range, as well as a value per day. It also returns - * the count of searches and searches without clicks. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getNoClickRateAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getNoClickRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getNoResultsRate - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getNoResultsRateCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches/noResultRate"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getNoResultsRateValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getNoResultsRate(Async)" - ); - } - - return getNoResultsRateCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns the rate at which searches didn't return any results. The endpoint returns a value for - * the complete given time range, as well as a value per day. It also returns the count of - * searches and searches without results used to compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetNoResultsRateResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetNoResultsRateResponse getNoResultsRate( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getNoResultsRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetNoResultsRate( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetNoResultsRateResponse getNoResultsRate(String index) - throws AlgoliaRuntimeException { - return this.getNoResultsRate(index, null, null, null); - } - - /** - * (asynchronously) Returns the rate at which searches didn't return any results. The endpoint - * returns a value for the complete given time range, as well as a value per day. It also returns - * the count of searches and searches without results used to compute the rates. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getNoResultsRateAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getNoResultsRateValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSearchesCount - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSearchesCountCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches/count"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSearchesCountValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getSearchesCount(Async)" - ); - } - - return getSearchesCountCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns the number of searches across the given time range. The endpoint returns a value for - * the complete given time range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetSearchesCountResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetSearchesCountResponse getSearchesCount( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getSearchesCountValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetSearchesCount( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetSearchesCountResponse getSearchesCount(String index) - throws AlgoliaRuntimeException { - return this.getSearchesCount(index, null, null, null); - } - - /** - * (asynchronously) Returns the number of searches across the given time range. The endpoint - * returns a value for the complete given time range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSearchesCountAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSearchesCountValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSearchesNoClicks - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSearchesNoClicksCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches/noClicks"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSearchesNoClicksValidateBeforeCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getSearchesNoClicks(Async)" - ); - } - - return getSearchesNoClicksCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top searches that didn't lead to any clicks. Limited to the 1000 most frequent ones. - * For each search, also returns the average number of found hits. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetSearchesNoClicksResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetSearchesNoClicksResponse getSearchesNoClicks( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getSearchesNoClicksValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetSearchesNoClicks( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetSearchesNoClicksResponse getSearchesNoClicks(String index) - throws AlgoliaRuntimeException { - return this.getSearchesNoClicks(index, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top searches that didn't lead to any clicks. Limited to the 1000 - * most frequent ones. For each search, also returns the average number of found hits. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSearchesNoClicksAsync( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSearchesNoClicksValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSearchesNoResults - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSearchesNoResultsCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches/noResults"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSearchesNoResultsValidateBeforeCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getSearchesNoResults(Async)" - ); - } - - return getSearchesNoResultsCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top searches that didn't return any results. Limited to the 1000 most frequent ones. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetSearchesNoResultsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetSearchesNoResultsResponse getSearchesNoResults( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getSearchesNoResultsValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetSearchesNoResults( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetSearchesNoResultsResponse getSearchesNoResults(String index) - throws AlgoliaRuntimeException { - return this.getSearchesNoResults(index, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top searches that didn't return any results. Limited to the 1000 - * most frequent ones. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSearchesNoResultsAsync( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSearchesNoResultsValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getStatus - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getStatusCall( - String index, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/status"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getStatusValidateBeforeCall( - String index, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getStatus(Async)" - ); - } - - return getStatusCall(index, callback); - } - - /** - * Returns the latest update time of the analytics API for a given index. If the index has been - * recently created and/or no search has been performed yet the updated time will be null. - * - * @param index The index name to target. (required) - * @return GetStatusResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetStatusResponse getStatus(String index) - throws AlgoliaRuntimeException { - Call req = getStatusValidateBeforeCall(index, null); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetStatus(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns the latest update time of the analytics API for a given index. If the - * index has been recently created and/or no search has been performed yet the updated time will - * be null. - * - * @param index The index name to target. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getStatusAsync( - String index, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getStatusValidateBeforeCall(index, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopCountries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopCountriesCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/countries"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopCountriesValidateBeforeCall( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopCountries(Async)" - ); - } - - return getTopCountriesCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top countries. Limited to the 1000 most frequent ones. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopCountriesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopCountriesResponse getTopCountries( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopCountriesValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopCountries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetTopCountriesResponse getTopCountries(String index) - throws AlgoliaRuntimeException { - return this.getTopCountries(index, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top countries. Limited to the 1000 most frequent ones. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopCountriesAsync( - String index, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopCountriesValidateBeforeCall( - index, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopFilterAttributes - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopFilterAttributesCall( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/filters"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (search != null) { - queryParams.addAll(this.parameterToPair("search", search)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopFilterAttributesValidateBeforeCall( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopFilterAttributes(Async)" - ); - } - - return getTopFilterAttributesCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top filter attributes. Limited to the 1000 most used filters. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopFilterAttributesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopFilterAttributesResponse getTopFilterAttributes( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopFilterAttributesValidateBeforeCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopFilterAttributes( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetTopFilterAttributesResponse getTopFilterAttributes(String index) - throws AlgoliaRuntimeException { - return this.getTopFilterAttributes(index, null, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top filter attributes. Limited to the 1000 most used filters. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopFilterAttributesAsync( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopFilterAttributesValidateBeforeCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopFilterForAttribute - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopFilterForAttributeCall( - String attribute, - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/2/filters/{attribute}".replaceAll( - "\\{attribute\\}", - this.escapeString(attribute.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (search != null) { - queryParams.addAll(this.parameterToPair("search", search)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopFilterForAttributeValidateBeforeCall( - String attribute, - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'attribute' is set - if (attribute == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'attribute' when calling" + - " getTopFilterForAttribute(Async)" - ); - } - - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopFilterForAttribute(Async)" - ); - } - - return getTopFilterForAttributeCall( - attribute, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top filters for the given attribute. Limited to the 1000 most used filters. - * - * @param attribute The exact name of the attribute. (required) - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopFilterForAttributeResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopFilterForAttributeResponse getTopFilterForAttribute( - String attribute, - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopFilterForAttributeValidateBeforeCall( - attribute, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopFilterForAttribute( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetTopFilterForAttributeResponse getTopFilterForAttribute( - String attribute, - String index - ) throws AlgoliaRuntimeException { - return this.getTopFilterForAttribute( - attribute, - index, - null, - null, - null, - 10, - 0, - null - ); - } - - /** - * (asynchronously) Returns top filters for the given attribute. Limited to the 1000 most used - * filters. - * - * @param attribute The exact name of the attribute. (required) - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopFilterForAttributeAsync( - String attribute, - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopFilterForAttributeValidateBeforeCall( - attribute, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopFiltersNoResults - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopFiltersNoResultsCall( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/filters/noResults"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (search != null) { - queryParams.addAll(this.parameterToPair("search", search)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopFiltersNoResultsValidateBeforeCall( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopFiltersNoResults(Async)" - ); - } - - return getTopFiltersNoResultsCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top filters with no results. Limited to the 1000 most used filters. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopFiltersNoResultsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopFiltersNoResultsResponse getTopFiltersNoResults( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopFiltersNoResultsValidateBeforeCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopFiltersNoResults( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public GetTopFiltersNoResultsResponse getTopFiltersNoResults(String index) - throws AlgoliaRuntimeException { - return this.getTopFiltersNoResults(index, null, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top filters with no results. Limited to the 1000 most used filters. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopFiltersNoResultsAsync( - String index, - String search, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopFiltersNoResultsValidateBeforeCall( - index, - search, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopHits - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopHitsCall( - String index, - String search, - Boolean clickAnalytics, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/hits"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (search != null) { - queryParams.addAll(this.parameterToPair("search", search)); - } - - if (clickAnalytics != null) { - queryParams.addAll( - this.parameterToPair("clickAnalytics", clickAnalytics) - ); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopHitsValidateBeforeCall( - String index, - String search, - Boolean clickAnalytics, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopHits(Async)" - ); - } - - return getTopHitsCall( - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top hits. Limited to the 1000 most frequent ones. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param clickAnalytics Whether to include the click-through and conversion rates for a search. - * (optional, default to false) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopHitsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopHitsResponse getTopHits( - String index, - String search, - Boolean clickAnalytics, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopHitsValidateBeforeCall( - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopHits(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetTopHitsResponse getTopHits(String index) - throws AlgoliaRuntimeException { - return this.getTopHits(index, null, false, null, null, 10, 0, null); - } - - /** - * (asynchronously) Returns top hits. Limited to the 1000 most frequent ones. - * - * @param index The index name to target. (required) - * @param search The query term to search for. Must match the exact user input. (optional) - * @param clickAnalytics Whether to include the click-through and conversion rates for a search. - * (optional, default to false) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopHitsAsync( - String index, - String search, - Boolean clickAnalytics, - String startDate, - String endDate, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopHitsValidateBeforeCall( - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopSearches - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopSearchesCall( - String index, - Boolean clickAnalytics, - String startDate, - String endDate, - OrderBy orderBy, - Direction direction, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/searches"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (clickAnalytics != null) { - queryParams.addAll( - this.parameterToPair("clickAnalytics", clickAnalytics) - ); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (orderBy != null) { - queryParams.addAll(this.parameterToPair("orderBy", orderBy)); - } - - if (direction != null) { - queryParams.addAll(this.parameterToPair("direction", direction)); - } - - if (limit != null) { - queryParams.addAll(this.parameterToPair("limit", limit)); - } - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopSearchesValidateBeforeCall( - String index, - Boolean clickAnalytics, - String startDate, - String endDate, - OrderBy orderBy, - Direction direction, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getTopSearches(Async)" - ); - } - - return getTopSearchesCall( - index, - clickAnalytics, - startDate, - endDate, - orderBy, - direction, - limit, - offset, - tags, - callback - ); - } - - /** - * Returns top searches. Limited to the 1000 most frequent ones. For each search, also returns the - * average number of hits returned. - * - * @param index The index name to target. (required) - * @param clickAnalytics Whether to include the click-through and conversion rates for a search. - * (optional, default to false) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param orderBy Reorder the results. (optional, default to searchCount) - * @param direction The sorting of the result. (optional, default to asc) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetTopSearchesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopSearchesResponse getTopSearches( - String index, - Boolean clickAnalytics, - String startDate, - String endDate, - OrderBy orderBy, - Direction direction, - Integer limit, - Integer offset, - String tags - ) throws AlgoliaRuntimeException { - Call req = getTopSearchesValidateBeforeCall( - index, - clickAnalytics, - startDate, - endDate, - orderBy, - direction, - limit, - offset, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetTopSearches( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetTopSearchesResponse getTopSearches(String index) - throws AlgoliaRuntimeException { - return this.getTopSearches( - index, - false, - null, - null, - OrderBy.SEARCH_COUNT, - Direction.ASC, - 10, - 0, - null - ); - } - - /** - * (asynchronously) Returns top searches. Limited to the 1000 most frequent ones. For each search, - * also returns the average number of hits returned. - * - * @param index The index name to target. (required) - * @param clickAnalytics Whether to include the click-through and conversion rates for a search. - * (optional, default to false) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param orderBy Reorder the results. (optional, default to searchCount) - * @param direction The sorting of the result. (optional, default to asc) - * @param limit Number of records to return. Limit is the size of the page. (optional, default to - * 10) - * @param offset Position of the starting record. Used for paging. 0 is the first record. - * (optional, default to 0) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopSearchesAsync( - String index, - Boolean clickAnalytics, - String startDate, - String endDate, - OrderBy orderBy, - Direction direction, - Integer limit, - Integer offset, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopSearchesValidateBeforeCall( - index, - clickAnalytics, - startDate, - endDate, - orderBy, - direction, - limit, - offset, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getUsersCount - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getUsersCountCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/2/users/count"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (index != null) { - queryParams.addAll(this.parameterToPair("index", index)); - } - - if (startDate != null) { - queryParams.addAll(this.parameterToPair("startDate", startDate)); - } - - if (endDate != null) { - queryParams.addAll(this.parameterToPair("endDate", endDate)); - } - - if (tags != null) { - queryParams.addAll(this.parameterToPair("tags", tags)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getUsersCountValidateBeforeCall( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'index' is set - if (index == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'index' when calling getUsersCount(Async)" - ); - } - - return getUsersCountCall(index, startDate, endDate, tags, callback); - } - - /** - * Returns the distinct count of users across the given time range. The endpoint returns a value - * for the complete given time range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @return GetUsersCountResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetUsersCountResponse getUsersCount( - String index, - String startDate, - String endDate, - String tags - ) throws AlgoliaRuntimeException { - Call req = getUsersCountValidateBeforeCall( - index, - startDate, - endDate, - tags, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.GetUsersCount( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetUsersCountResponse getUsersCount(String index) - throws AlgoliaRuntimeException { - return this.getUsersCount(index, null, null, null); - } - - /** - * (asynchronously) Returns the distinct count of users across the given time range. The endpoint - * returns a value for the complete given time range, as well as a value per day. - * - * @param index The index name to target. (required) - * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period - * to analyze. (optional) - * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags - * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag - * contains characters like spaces or parentheses, it should be URL encoded. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getUsersCountAsync( - String index, - String startDate, - String endDate, - String tags, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getUsersCountValidateBeforeCall( - index, - startDate, - endDate, - tags, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseAnalytics.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java deleted file mode 100644 index 1f333b2336..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java +++ /dev/null @@ -1,581 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.insights.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class InsightsApi extends ApiClient { - - public InsightsApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); - } - - public InsightsApi(String appId, String apiKey, String region) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); - } - - public InsightsApi( - String appId, - String apiKey, - String region, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(region)), - userAgentSegments - ); - } - - public InsightsApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public InsightsApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Insights", userAgentSegments); - } - - private static List getDefaultHosts(String region) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "insights." + (region == null ? "" : region + ".") + "algolia.io", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseInsights.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseInsights.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseInsights.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for pushEvents - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call pushEventsCall( - InsightEvents insightEvents, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = insightEvents; - - // create path and map variables - String requestPath = "/1/events"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call pushEventsValidateBeforeCall( - InsightEvents insightEvents, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'insightEvents' is set - if (insightEvents == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'insightEvents' when calling pushEvents(Async)" - ); - } - - return pushEventsCall(insightEvents, callback); - } - - /** - * This command pushes an array of events. - * - * @param insightEvents (required) - * @return PushEventsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public PushEventsResponse pushEvents(InsightEvents insightEvents) - throws AlgoliaRuntimeException { - Call req = pushEventsValidateBeforeCall(insightEvents, null); - if (req instanceof CallEcho) { - return new EchoResponseInsights.PushEvents(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) This command pushes an array of events. - * - * @param insightEvents (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call pushEventsAsync( - InsightEvents insightEvents, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = pushEventsValidateBeforeCall(insightEvents, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseInsights.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java deleted file mode 100644 index 69a2f7dc53..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java +++ /dev/null @@ -1,878 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.personalization.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class PersonalizationApi extends ApiClient { - - public PersonalizationApi(String appId, String apiKey, String region) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); - } - - public PersonalizationApi( - String appId, - String apiKey, - String region, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(region)), - userAgentSegments - ); - } - - public PersonalizationApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public PersonalizationApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Personalization", userAgentSegments); - } - - private static List getDefaultHosts(String region) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "personalization." + - (region == null ? "" : region + ".") + - "algolia.com", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteUserProfile - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteUserProfileCall( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/profiles/{userToken}".replaceAll( - "\\{userToken\\}", - this.escapeString(userToken.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteUserProfileValidateBeforeCall( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userToken' is set - if (userToken == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userToken' when calling deleteUserProfile(Async)" - ); - } - - return deleteUserProfileCall(userToken, callback); - } - - /** - * Returns, as part of the response, a date until which the data can safely be considered as - * deleted for the given user. This means that if you send events for the given user before this - * date, they will be ignored. Any data received after the deletedUntil date will start building a - * new user profile. It might take a couple hours before for the deletion request to be fully - * processed. - * - * @param userToken userToken representing the user for which to fetch the Personalization - * profile. (required) - * @return DeleteUserProfileResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeleteUserProfileResponse deleteUserProfile(String userToken) - throws AlgoliaRuntimeException { - Call req = deleteUserProfileValidateBeforeCall(userToken, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.DeleteUserProfile( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns, as part of the response, a date until which the data can safely be - * considered as deleted for the given user. This means that if you send events for the given user - * before this date, they will be ignored. Any data received after the deletedUntil date will - * start building a new user profile. It might take a couple hours before for the deletion request - * to be fully processed. - * - * @param userToken userToken representing the user for which to fetch the Personalization - * profile. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteUserProfileAsync( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteUserProfileValidateBeforeCall(userToken, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getPersonalizationStrategy - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getPersonalizationStrategyCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/strategies/personalization"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getPersonalizationStrategyValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getPersonalizationStrategyCall(callback); - } - - /** - * The strategy contains information on the events and facets that impact user profiles and - * personalized search results. - * - * @return PersonalizationStrategyParams - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public PersonalizationStrategyParams getPersonalizationStrategy() - throws AlgoliaRuntimeException { - Call req = getPersonalizationStrategyValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.GetPersonalizationStrategy( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) The strategy contains information on the events and facets that impact user - * profiles and personalized search results. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getPersonalizationStrategyAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getPersonalizationStrategyValidateBeforeCall(callback); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getUserTokenProfile - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getUserTokenProfileCall( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/profiles/personalization/{userToken}".replaceAll( - "\\{userToken\\}", - this.escapeString(userToken.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getUserTokenProfileValidateBeforeCall( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userToken' is set - if (userToken == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userToken' when calling getUserTokenProfile(Async)" - ); - } - - return getUserTokenProfileCall(userToken, callback); - } - - /** - * The profile is structured by facet name used in the strategy. Each facet value is mapped to its - * score. Each score represents the user affinity for a specific facet value given the userToken - * past events and the Personalization strategy defined. Scores are bounded to 20. The last - * processed event timestamp is provided using the ISO 8601 format for debugging purposes. - * - * @param userToken userToken representing the user for which to fetch the Personalization - * profile. (required) - * @return GetUserTokenResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetUserTokenResponse getUserTokenProfile(String userToken) - throws AlgoliaRuntimeException { - Call req = getUserTokenProfileValidateBeforeCall(userToken, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.GetUserTokenProfile( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) The profile is structured by facet name used in the strategy. Each facet value - * is mapped to its score. Each score represents the user affinity for a specific facet value - * given the userToken past events and the Personalization strategy defined. Scores are bounded to - * 20. The last processed event timestamp is provided using the ISO 8601 format for debugging - * purposes. - * - * @param userToken userToken representing the user for which to fetch the Personalization - * profile. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getUserTokenProfileAsync( - String userToken, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getUserTokenProfileValidateBeforeCall(userToken, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for setPersonalizationStrategy - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call setPersonalizationStrategyCall( - PersonalizationStrategyParams personalizationStrategyParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = personalizationStrategyParams; - - // create path and map variables - String requestPath = "/1/strategies/personalization"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call setPersonalizationStrategyValidateBeforeCall( - PersonalizationStrategyParams personalizationStrategyParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'personalizationStrategyParams' is set - if (personalizationStrategyParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'personalizationStrategyParams' when calling" + - " setPersonalizationStrategy(Async)" - ); - } - - return setPersonalizationStrategyCall( - personalizationStrategyParams, - callback - ); - } - - /** - * A strategy defines the events and facets that impact user profiles and personalized search - * results. - * - * @param personalizationStrategyParams (required) - * @return SetPersonalizationStrategyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SetPersonalizationStrategyResponse setPersonalizationStrategy( - PersonalizationStrategyParams personalizationStrategyParams - ) throws AlgoliaRuntimeException { - Call req = setPersonalizationStrategyValidateBeforeCall( - personalizationStrategyParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponsePersonalization.SetPersonalizationStrategy( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) A strategy defines the events and facets that impact user profiles and - * personalized search results. - * - * @param personalizationStrategyParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call setPersonalizationStrategyAsync( - PersonalizationStrategyParams personalizationStrategyParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = setPersonalizationStrategyValidateBeforeCall( - personalizationStrategyParams, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java deleted file mode 100644 index 902fabbf61..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java +++ /dev/null @@ -1,600 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.predict.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class PredictApi extends ApiClient { - - public PredictApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts()), null); - } - - public PredictApi( - String appId, - String apiKey, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts()), - userAgentSegments - ); - } - - public PredictApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public PredictApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Predict", userAgentSegments); - } - - private static List getDefaultHosts() { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "predict-api-oslcbws3zq-ew.a.run.app", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponsePredict.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for fetchUserProfile - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call fetchUserProfileCall( - String userID, - Params params, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = params; - - // create path and map variables - String requestPath = - "/1/users/{userID}/fetch".replaceAll( - "\\{userID\\}", - this.escapeString(userID.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call fetchUserProfileValidateBeforeCall( - String userID, - Params params, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userID' is set - if (userID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userID' when calling fetchUserProfile(Async)" - ); - } - - // verify the required parameter 'params' is set - if (params == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'params' when calling fetchUserProfile(Async)" - ); - } - - return fetchUserProfileCall(userID, params, callback); - } - - /** - * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a - * user profile. - * - * @param userID User ID for authenticated users or cookie ID for non-authenticated repeated users - * (visitors). (required) - * @param params (required) - * @return FetchUserProfileResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public FetchUserProfileResponse fetchUserProfile( - String userID, - Params params - ) throws AlgoliaRuntimeException { - Call req = fetchUserProfileValidateBeforeCall(userID, params, null); - if (req instanceof CallEcho) { - return new EchoResponsePredict.FetchUserProfile( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get predictions, properties (raw, computed or custom) and segments (computed - * or custom) for a user profile. - * - * @param userID User ID for authenticated users or cookie ID for non-authenticated repeated users - * (visitors). (required) - * @param params (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call fetchUserProfileAsync( - String userID, - Params params, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = fetchUserProfileValidateBeforeCall(userID, params, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponsePredict.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponsePredict.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponsePredict.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java deleted file mode 100644 index ceac70029c..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java +++ /dev/null @@ -1,1154 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.querySuggestions.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import okhttp3.Call; - -public class QuerySuggestionsApi extends ApiClient { - - public QuerySuggestionsApi(String appId, String apiKey, String region) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); - } - - public QuerySuggestionsApi( - String appId, - String apiKey, - String region, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(region)), - userAgentSegments - ); - } - - public QuerySuggestionsApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public QuerySuggestionsApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "QuerySuggestions", userAgentSegments); - } - - private static List getDefaultHosts(String region) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - "query-suggestions." + - (region == null ? "" : region + ".") + - "algolia.com", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - return hosts; - } - - /** - * Build call for createConfig - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call createConfigCall( - QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = querySuggestionsIndexWithIndexParam; - - // create path and map variables - String requestPath = "/1/configs"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call createConfigValidateBeforeCall( - QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'querySuggestionsIndexWithIndexParam' is set - if (querySuggestionsIndexWithIndexParam == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'querySuggestionsIndexWithIndexParam' when calling" + - " createConfig(Async)" - ); - } - - return createConfigCall(querySuggestionsIndexWithIndexParam, callback); - } - - /** - * Create a configuration of a Query Suggestions index. There's a limit of 100 configurations per - * application. - * - * @param querySuggestionsIndexWithIndexParam (required) - * @return SucessResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SucessResponse createConfig( - QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam - ) throws AlgoliaRuntimeException { - Call req = createConfigValidateBeforeCall( - querySuggestionsIndexWithIndexParam, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.CreateConfig( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Create a configuration of a Query Suggestions index. There's a limit of - * 100 configurations per application. - * - * @param querySuggestionsIndexWithIndexParam (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call createConfigAsync( - QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = createConfigValidateBeforeCall( - querySuggestionsIndexWithIndexParam, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteConfig - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteConfigCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/configs/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteConfigValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteConfig(Async)" - ); - } - - return deleteConfigCall(indexName, callback); - } - - /** - * Delete a configuration of a Query Suggestion's index. By deleting a configuraton, you stop all - * updates to the underlying query suggestion index. Note that when doing this, the underlying - * index does not change - existing suggestions remain untouched. - * - * @param indexName The index in which to perform the request. (required) - * @return SucessResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SucessResponse deleteConfig(String indexName) - throws AlgoliaRuntimeException { - Call req = deleteConfigValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.DeleteConfig( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete a configuration of a Query Suggestion's index. By deleting a - * configuraton, you stop all updates to the underlying query suggestion index. Note that when - * doing this, the underlying index does not change - existing suggestions remain untouched. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteConfigAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteConfigValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getAllConfigs - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getAllConfigsCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/configs"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getAllConfigsValidateBeforeCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - return getAllConfigsCall(callback); - } - - /** - * Get all the configurations of Query Suggestions. For each index, you get a block of JSON with a - * list of its configuration settings. - * - * @return List<QuerySuggestionsIndex> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public List getAllConfigs() - throws AlgoliaRuntimeException { - Call req = getAllConfigsValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.GetAllConfigs( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get all the configurations of Query Suggestions. For each index, you get a - * block of JSON with a list of its configuration settings. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAllConfigsAsync( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getAllConfigsValidateBeforeCall(callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getConfig - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getConfigCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/configs/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getConfigValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getConfig(Async)" - ); - } - - return getConfigCall(indexName, callback); - } - - /** - * Get the configuration of a single Query Suggestions index. - * - * @param indexName The index in which to perform the request. (required) - * @return QuerySuggestionsIndex - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public QuerySuggestionsIndex getConfig(String indexName) - throws AlgoliaRuntimeException { - Call req = getConfigValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.GetConfig( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the configuration of a single Query Suggestions index. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getConfigAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getConfigValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getConfigStatus - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getConfigStatusCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/configs/{indexName}/status".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getConfigStatusValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getConfigStatus(Async)" - ); - } - - return getConfigStatusCall(indexName, callback); - } - - /** - * Get the status of a Query Suggestion's index. The status includes whether the Query Suggestions - * index is currently in the process of being built, and the last build time. - * - * @param indexName The index in which to perform the request. (required) - * @return Status - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Status getConfigStatus(String indexName) - throws AlgoliaRuntimeException { - Call req = getConfigStatusValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.GetConfigStatus( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the status of a Query Suggestion's index. The status includes whether - * the Query Suggestions index is currently in the process of being built, and the last build - * time. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getConfigStatusAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getConfigStatusValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getLogFile - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getLogFileCall( - String indexName, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/logs/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getLogFileValidateBeforeCall( - String indexName, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getLogFile(Async)" - ); - } - - return getLogFileCall(indexName, callback); - } - - /** - * Get the log file of the last build of a single Query Suggestion index. - * - * @param indexName The index in which to perform the request. (required) - * @return List<LogFile> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public List getLogFile(String indexName) - throws AlgoliaRuntimeException { - Call req = getLogFileValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.GetLogFile( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the log file of the last build of a single Query Suggestion index. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getLogFileAsync( - String indexName, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getLogFileValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for updateConfig - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call updateConfigCall( - String indexName, - QuerySuggestionsIndexParam querySuggestionsIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = querySuggestionsIndexParam; - - // create path and map variables - String requestPath = - "/1/configs/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call updateConfigValidateBeforeCall( - String indexName, - QuerySuggestionsIndexParam querySuggestionsIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling updateConfig(Async)" - ); - } - - // verify the required parameter 'querySuggestionsIndexParam' is set - if (querySuggestionsIndexParam == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'querySuggestionsIndexParam' when calling" + - " updateConfig(Async)" - ); - } - - return updateConfigCall(indexName, querySuggestionsIndexParam, callback); - } - - /** - * Update the configuration of a Query Suggestions index. - * - * @param indexName The index in which to perform the request. (required) - * @param querySuggestionsIndexParam (required) - * @return SucessResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SucessResponse updateConfig( - String indexName, - QuerySuggestionsIndexParam querySuggestionsIndexParam - ) throws AlgoliaRuntimeException { - Call req = updateConfigValidateBeforeCall( - indexName, - querySuggestionsIndexParam, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseQuerySuggestions.UpdateConfig( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Update the configuration of a Query Suggestions index. - * - * @param indexName The index in which to perform the request. (required) - * @param querySuggestionsIndexParam (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call updateConfigAsync( - String indexName, - QuerySuggestionsIndexParam querySuggestionsIndexParam, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = updateConfigValidateBeforeCall( - indexName, - querySuggestionsIndexParam, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java deleted file mode 100644 index d9f91ad1f4..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java +++ /dev/null @@ -1,626 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.recommend.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import okhttp3.Call; - -public class RecommendApi extends ApiClient { - - public RecommendApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); - } - - public RecommendApi( - String appId, - String apiKey, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(appId)), - userAgentSegments - ); - } - - public RecommendApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public RecommendApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Recommend", userAgentSegments); - } - - private static List getDefaultHosts(String appId) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-dsn.algolia.net", - "https", - EnumSet.of(CallType.READ) - ) - ); - hosts.add( - new StatefulHost( - appId + ".algolia.net", - "https", - EnumSet.of(CallType.WRITE) - ) - ); - - List commonHosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-1.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-2.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-3.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - - Collections.shuffle(commonHosts, new Random()); - - return Stream - .concat(hosts.stream(), commonHosts.stream()) - .collect(Collectors.toList()); - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseRecommend.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseRecommend.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getRecommendations - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getRecommendationsCall( - GetRecommendationsParams getRecommendationsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = getRecommendationsParams; - - // create path and map variables - String requestPath = "/1/indexes/*/recommendations"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getRecommendationsValidateBeforeCall( - GetRecommendationsParams getRecommendationsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'getRecommendationsParams' is set - if (getRecommendationsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'getRecommendationsParams' when calling" + - " getRecommendations(Async)" - ); - } - - return getRecommendationsCall(getRecommendationsParams, callback); - } - - /** - * Returns recommendations for a specific model and objectID. - * - * @param getRecommendationsParams (required) - * @return GetRecommendationsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetRecommendationsResponse getRecommendations( - GetRecommendationsParams getRecommendationsParams - ) throws AlgoliaRuntimeException { - Call req = getRecommendationsValidateBeforeCall( - getRecommendationsParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseRecommend.GetRecommendations( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns recommendations for a specific model and objectID. - * - * @param getRecommendationsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getRecommendationsAsync( - GetRecommendationsParams getRecommendationsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getRecommendationsValidateBeforeCall( - getRecommendationsParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseRecommend.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseRecommend.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java deleted file mode 100644 index 57dbffd4ea..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java +++ /dev/null @@ -1,6644 +0,0 @@ -package com.algolia.api; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.search.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import okhttp3.Call; - -public class SearchApi extends ApiClient { - - public SearchApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); - } - - public SearchApi( - String appId, - String apiKey, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(appId)), - userAgentSegments - ); - } - - public SearchApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public SearchApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Search", userAgentSegments); - } - - private static List getDefaultHosts(String appId) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-dsn.algolia.net", - "https", - EnumSet.of(CallType.READ) - ) - ); - hosts.add( - new StatefulHost( - appId + ".algolia.net", - "https", - EnumSet.of(CallType.WRITE) - ) - ); - - List commonHosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-1.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-2.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-3.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - - Collections.shuffle(commonHosts, new Random()); - - return Stream - .concat(hosts.stream(), commonHosts.stream()) - .collect(Collectors.toList()); - } - - /** - * Build call for addApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call addApiKeyCall( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = apiKey; - - // create path and map variables - String requestPath = "/1/keys"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call addApiKeyValidateBeforeCall( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'apiKey' is set - if (apiKey == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'apiKey' when calling addApiKey(Async)" - ); - } - - return addApiKeyCall(apiKey, callback); - } - - /** - * Add a new API Key with specific permissions/restrictions. - * - * @param apiKey (required) - * @return AddApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public AddApiKeyResponse addApiKey(ApiKey apiKey) - throws AlgoliaRuntimeException { - Call req = addApiKeyValidateBeforeCall(apiKey, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.AddApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add a new API Key with specific permissions/restrictions. - * - * @param apiKey (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call addApiKeyAsync( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = addApiKeyValidateBeforeCall(apiKey, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for addOrUpdateObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call addOrUpdateObjectCall( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call addOrUpdateObjectValidateBeforeCall( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling addOrUpdateObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling addOrUpdateObject(Async)" - ); - } - - // verify the required parameter 'body' is set - if (body == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'body' when calling addOrUpdateObject(Async)" - ); - } - - return addOrUpdateObjectCall(indexName, objectID, body, callback); - } - - /** - * Add or replace an object with a given object ID. If the object does not exist, it will be - * created. If it already exists, it will be replaced. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param body The Algolia object. (required) - * @return UpdatedAtWithObjectIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtWithObjectIdResponse addOrUpdateObject( - String indexName, - String objectID, - Object body - ) throws AlgoliaRuntimeException { - Call req = addOrUpdateObjectValidateBeforeCall( - indexName, - objectID, - body, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.AddOrUpdateObject( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add or replace an object with a given object ID. If the object does not exist, - * it will be created. If it already exists, it will be replaced. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param body The Algolia object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call addOrUpdateObjectAsync( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = addOrUpdateObjectValidateBeforeCall( - indexName, - objectID, - body, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for appendSource - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call appendSourceCall( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = source; - - // create path and map variables - String requestPath = "/1/security/sources/append"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call appendSourceValidateBeforeCall( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling appendSource(Async)" - ); - } - - return appendSourceCall(source, callback); - } - - /** - * Add a single source to the list of allowed sources. - * - * @param source The source to add. (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse appendSource(Source source) - throws AlgoliaRuntimeException { - Call req = appendSourceValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.AppendSource(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add a single source to the list of allowed sources. - * - * @param source The source to add. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call appendSourceAsync( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = appendSourceValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for assignUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call assignUserIdCall( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = assignUserIdParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (xAlgoliaUserID != null) { - queryParams.addAll( - this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call assignUserIdValidateBeforeCall( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'xAlgoliaUserID' is set - if (xAlgoliaUserID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'xAlgoliaUserID' when calling assignUserId(Async)" - ); - } - - // verify the required parameter 'assignUserIdParams' is set - if (assignUserIdParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'assignUserIdParams' when calling assignUserId(Async)" - ); - } - - return assignUserIdCall(xAlgoliaUserID, assignUserIdParams, callback); - } - - /** - * Assign or Move a userID to a cluster. The time it takes to migrate (move) a user is - * proportional to the amount of data linked to the userID. Upon success, the response is 200 OK. - * A successful response indicates that the operation has been taken into account, and the userID - * is directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param assignUserIdParams (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse assignUserId( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams - ) throws AlgoliaRuntimeException { - Call req = assignUserIdValidateBeforeCall( - xAlgoliaUserID, - assignUserIdParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.AssignUserId(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Assign or Move a userID to a cluster. The time it takes to migrate (move) a - * user is proportional to the amount of data linked to the userID. Upon success, the response is - * 200 OK. A successful response indicates that the operation has been taken into account, and the - * userID is directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param assignUserIdParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call assignUserIdAsync( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = assignUserIdValidateBeforeCall( - xAlgoliaUserID, - assignUserIdParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batch - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchCall( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchWriteParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchValidateBeforeCall( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling batch(Async)" - ); - } - - // verify the required parameter 'batchWriteParams' is set - if (batchWriteParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchWriteParams' when calling batch(Async)" - ); - } - - return batchCall(indexName, batchWriteParams, callback); - } - - /** - * Performs multiple write operations in a single API call. - * - * @param indexName The index in which to perform the request. (required) - * @param batchWriteParams (required) - * @return BatchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public BatchResponse batch( - String indexName, - BatchWriteParams batchWriteParams - ) throws AlgoliaRuntimeException { - Call req = batchValidateBeforeCall(indexName, batchWriteParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Batch(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Performs multiple write operations in a single API call. - * - * @param indexName The index in which to perform the request. (required) - * @param batchWriteParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchAsync( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchValidateBeforeCall(indexName, batchWriteParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchAssignUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchAssignUserIdsCall( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchAssignUserIdsParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping/batch"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (xAlgoliaUserID != null) { - queryParams.addAll( - this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchAssignUserIdsValidateBeforeCall( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'xAlgoliaUserID' is set - if (xAlgoliaUserID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'xAlgoliaUserID' when calling batchAssignUserIds(Async)" - ); - } - - // verify the required parameter 'batchAssignUserIdsParams' is set - if (batchAssignUserIdsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchAssignUserIdsParams' when calling" + - " batchAssignUserIds(Async)" - ); - } - - return batchAssignUserIdsCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - callback - ); - } - - /** - * Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A successful - * response indicates that the operation has been taken into account, and the userIDs are directly - * usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param batchAssignUserIdsParams (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse batchAssignUserIds( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams - ) throws AlgoliaRuntimeException { - Call req = batchAssignUserIdsValidateBeforeCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.BatchAssignUserIds( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A - * successful response indicates that the operation has been taken into account, and the userIDs - * are directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param batchAssignUserIdsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchAssignUserIdsAsync( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchAssignUserIdsValidateBeforeCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchDictionaryEntries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchDictionaryEntriesCall( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchDictionaryEntriesParams; - - // create path and map variables - String requestPath = - "/1/dictionaries/{dictionaryName}/batch".replaceAll( - "\\{dictionaryName\\}", - this.escapeString(dictionaryName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchDictionaryEntriesValidateBeforeCall( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionaryName' is set - if (dictionaryName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionaryName' when calling" + - " batchDictionaryEntries(Async)" - ); - } - - // verify the required parameter 'batchDictionaryEntriesParams' is set - if (batchDictionaryEntriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchDictionaryEntriesParams' when calling" + - " batchDictionaryEntries(Async)" - ); - } - - return batchDictionaryEntriesCall( - dictionaryName, - batchDictionaryEntriesParams, - callback - ); - } - - /** - * Send a batch of dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param batchDictionaryEntriesParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse batchDictionaryEntries( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams - ) throws AlgoliaRuntimeException { - Call req = batchDictionaryEntriesValidateBeforeCall( - dictionaryName, - batchDictionaryEntriesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.BatchDictionaryEntries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Send a batch of dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param batchDictionaryEntriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchDictionaryEntriesAsync( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchDictionaryEntriesValidateBeforeCall( - dictionaryName, - batchDictionaryEntriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchRulesCall( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = rule; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - if (clearExistingRules != null) { - queryParams.addAll( - this.parameterToPair("clearExistingRules", clearExistingRules) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchRulesValidateBeforeCall( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling batchRules(Async)" - ); - } - - // verify the required parameter 'rule' is set - if (rule == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'rule' when calling batchRules(Async)" - ); - } - - return batchRulesCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - callback - ); - } - - /** - * Create or update a batch of Rules. - * - * @param indexName The index in which to perform the request. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When - * false, existing Rules are kept. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse batchRules( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules - ) throws AlgoliaRuntimeException { - Call req = batchRulesValidateBeforeCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.BatchRules(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse batchRules(String indexName, List rule) - throws AlgoliaRuntimeException { - return this.batchRules(indexName, rule, null, null); - } - - /** - * (asynchronously) Create or update a batch of Rules. - * - * @param indexName The index in which to perform the request. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When - * false, existing Rules are kept. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchRulesAsync( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchRulesValidateBeforeCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for browse - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call browseCall( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = browseRequest; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/browse".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call browseValidateBeforeCall( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling browse(Async)" - ); - } - - return browseCall(indexName, browseRequest, callback); - } - - /** - * This method allows you to retrieve all index content. It can retrieve up to 1,000 records per - * call and supports full text search and filters. For performance reasons, some features are not - * supported, including `distinct`, sorting by `typos`, `words` or `geo distance`. When there is - * more content to be browsed, the response contains a cursor field. This cursor has to be passed - * to the subsequent call to browse in order to get the next page of results. When the end of the - * index has been reached, the cursor field is absent from the response. - * - * @param indexName The index in which to perform the request. (required) - * @param browseRequest (optional) - * @return BrowseResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public BrowseResponse browse(String indexName, BrowseRequest browseRequest) - throws AlgoliaRuntimeException { - Call req = browseValidateBeforeCall(indexName, browseRequest, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Browse(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public BrowseResponse browse(String indexName) - throws AlgoliaRuntimeException { - return this.browse(indexName, null); - } - - /** - * (asynchronously) This method allows you to retrieve all index content. It can retrieve up to - * 1,000 records per call and supports full text search and filters. For performance reasons, some - * features are not supported, including `distinct`, sorting by `typos`, - * `words` or `geo distance`. When there is more content to be browsed, the - * response contains a cursor field. This cursor has to be passed to the subsequent call to browse - * in order to get the next page of results. When the end of the index has been reached, the - * cursor field is absent from the response. - * - * @param indexName The index in which to perform the request. (required) - * @param browseRequest (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call browseAsync( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = browseValidateBeforeCall(indexName, browseRequest, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearAllSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearAllSynonymsCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearAllSynonymsValidateBeforeCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearAllSynonyms(Async)" - ); - } - - return clearAllSynonymsCall(indexName, forwardToReplicas, callback); - } - - /** - * Remove all synonyms from an index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearAllSynonyms( - String indexName, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = clearAllSynonymsValidateBeforeCall( - indexName, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ClearAllSynonyms( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse clearAllSynonyms(String indexName) - throws AlgoliaRuntimeException { - return this.clearAllSynonyms(indexName, null); - } - - /** - * (asynchronously) Remove all synonyms from an index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearAllSynonymsAsync( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearAllSynonymsValidateBeforeCall( - indexName, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearObjects - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearObjectsCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearObjectsValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearObjects(Async)" - ); - } - - return clearObjectsCall(indexName, callback); - } - - /** - * Delete an index's content, but leave settings and index-specific API keys untouched. - * - * @param indexName The index in which to perform the request. (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearObjects(String indexName) - throws AlgoliaRuntimeException { - Call req = clearObjectsValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ClearObjects(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an index's content, but leave settings and index-specific API keys - * untouched. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearObjectsAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearObjectsValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearRulesCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearRulesValidateBeforeCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearRules(Async)" - ); - } - - return clearRulesCall(indexName, forwardToReplicas, callback); - } - - /** - * Delete all Rules in the index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearRules( - String indexName, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = clearRulesValidateBeforeCall(indexName, forwardToReplicas, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ClearRules(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse clearRules(String indexName) - throws AlgoliaRuntimeException { - return this.clearRules(indexName, null); - } - - /** - * (asynchronously) Delete all Rules in the index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearRulesAsync( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearRulesValidateBeforeCall( - indexName, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteApiKeyCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling deleteApiKey(Async)" - ); - } - - return deleteApiKeyCall(key, callback); - } - - /** - * Delete an existing API Key. - * - * @param key API Key string. (required) - * @return DeleteApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeleteApiKeyResponse deleteApiKey(String key) - throws AlgoliaRuntimeException { - Call req = deleteApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing API Key. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteApiKeyAsync( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteBy - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteByCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/deleteByQuery".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteByValidateBeforeCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteBy(Async)" - ); - } - - // verify the required parameter 'searchParams' is set - if (searchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchParams' when calling deleteBy(Async)" - ); - } - - return deleteByCall(indexName, searchParams, callback); - } - - /** - * Remove all objects matching a filter (including geo filters). This method enables you to delete - * one or more objects based on filters (numeric, facet, tag or geo queries). It doesn't accept - * empty filters or a query. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteBy( - String indexName, - SearchParams searchParams - ) throws AlgoliaRuntimeException { - Call req = deleteByValidateBeforeCall(indexName, searchParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteBy(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove all objects matching a filter (including geo filters). This method - * enables you to delete one or more objects based on filters (numeric, facet, tag or geo - * queries). It doesn't accept empty filters or a query. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteByAsync( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteByValidateBeforeCall(indexName, searchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteIndex - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteIndexCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteIndexValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteIndex(Async)" - ); - } - - return deleteIndexCall(indexName, callback); - } - - /** - * Delete an existing index. - * - * @param indexName The index in which to perform the request. (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteIndex(String indexName) - throws AlgoliaRuntimeException { - Call req = deleteIndexValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteIndex(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing index. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteIndexAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteIndexValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteObjectCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteObjectValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteObject(Async)" - ); - } - - return deleteObjectCall(indexName, objectID, callback); - } - - /** - * Delete an existing object. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteObject(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = deleteObjectValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteObject(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing object. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteObjectAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteObjectValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteRuleCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteRuleValidateBeforeCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteRule(Async)" - ); - } - - return deleteRuleCall(indexName, objectID, forwardToReplicas, callback); - } - - /** - * Delete the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse deleteRule( - String indexName, - String objectID, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = deleteRuleValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse deleteRule(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.deleteRule(indexName, objectID, null); - } - - /** - * (asynchronously) Delete the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteRuleAsync( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteRuleValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteSource - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteSourceCall( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/security/sources/{source}".replaceAll( - "\\{source\\}", - this.escapeString(source.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteSourceValidateBeforeCall( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling deleteSource(Async)" - ); - } - - return deleteSourceCall(source, callback); - } - - /** - * Remove a single source from the list of allowed sources. - * - * @param source The IP range of the source. (required) - * @return DeleteSourceResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeleteSourceResponse deleteSource(String source) - throws AlgoliaRuntimeException { - Call req = deleteSourceValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteSource(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove a single source from the list of allowed sources. - * - * @param source The IP range of the source. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteSourceAsync( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteSourceValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteSynonymCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteSynonymValidateBeforeCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteSynonym(Async)" - ); - } - - return deleteSynonymCall(indexName, objectID, forwardToReplicas, callback); - } - - /** - * Delete a single synonyms set, identified by the given objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteSynonym( - String indexName, - String objectID, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = deleteSynonymValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.DeleteSynonym(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public DeletedAtResponse deleteSynonym(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.deleteSynonym(indexName, objectID, null); - } - - /** - * (asynchronously) Delete a single synonyms set, identified by the given objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteSynonymAsync( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteSynonymValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getApiKeyCall(String key, final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling getApiKey(Async)" - ); - } - - return getApiKeyCall(key, callback); - } - - /** - * Get the permissions of an API key. - * - * @param key API Key string. (required) - * @return Key - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Key getApiKey(String key) throws AlgoliaRuntimeException { - Call req = getApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the permissions of an API key. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getApiKeyAsync(String key, final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = getApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getDictionaryLanguages - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getDictionaryLanguagesCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/dictionaries/*/languages"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getDictionaryLanguagesValidateBeforeCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - return getDictionaryLanguagesCall(callback); - } - - /** - * List dictionaries supported per language. - * - * @return Map<String, Languages> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Map getDictionaryLanguages() - throws AlgoliaRuntimeException { - Call req = getDictionaryLanguagesValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetDictionaryLanguages( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List dictionaries supported per language. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getDictionaryLanguagesAsync( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getDictionaryLanguagesValidateBeforeCall(callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getDictionarySettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getDictionarySettingsCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/dictionaries/*/settings"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getDictionarySettingsValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getDictionarySettingsCall(callback); - } - - /** - * Retrieve dictionaries settings. - * - * @return GetDictionarySettingsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetDictionarySettingsResponse getDictionarySettings() - throws AlgoliaRuntimeException { - Call req = getDictionarySettingsValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetDictionarySettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve dictionaries settings. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getDictionarySettingsAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getDictionarySettingsValidateBeforeCall(callback); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getLogs - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getLogsCall( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/logs"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (length != null) { - queryParams.addAll(this.parameterToPair("length", length)); - } - - if (indexName != null) { - queryParams.addAll(this.parameterToPair("indexName", indexName)); - } - - if (type != null) { - queryParams.addAll(this.parameterToPair("type", type)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getLogsValidateBeforeCall( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getLogsCall(offset, length, indexName, type, callback); - } - - /** - * Return the lastest log entries. - * - * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, - * therefore 0 designates the most recent log entry. (optional, default to 0) - * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. - * (optional, default to 10) - * @param indexName Index for which log entries should be retrieved. When omitted, log entries are - * retrieved across all indices. (optional) - * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. - * (optional, default to all) - * @return GetLogsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetLogsResponse getLogs( - Integer offset, - Integer length, - String indexName, - LogType type - ) throws AlgoliaRuntimeException { - Call req = getLogsValidateBeforeCall(offset, length, indexName, type, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetLogs(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetLogsResponse getLogs() throws AlgoliaRuntimeException { - return this.getLogs(0, 10, null, LogType.ALL); - } - - /** - * (asynchronously) Return the lastest log entries. - * - * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, - * therefore 0 designates the most recent log entry. (optional, default to 0) - * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. - * (optional, default to 10) - * @param indexName Index for which log entries should be retrieved. When omitted, log entries are - * retrieved across all indices. (optional) - * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. - * (optional, default to all) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getLogsAsync( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getLogsValidateBeforeCall( - offset, - length, - indexName, - type, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getObjectCall( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (attributesToRetrieve != null) { - queryParams.addAll( - this.parameterToPair("attributesToRetrieve", attributesToRetrieve) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getObjectValidateBeforeCall( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getObject(Async)" - ); - } - - return getObjectCall(indexName, objectID, attributesToRetrieve, callback); - } - - /** - * Retrieve one object from the index. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable - * attributes are returned. (optional) - * @return Map<String, String> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Map getObject( - String indexName, - String objectID, - List attributesToRetrieve - ) throws AlgoliaRuntimeException { - Call req = getObjectValidateBeforeCall( - indexName, - objectID, - attributesToRetrieve, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetObject(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - public Map getObject(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.getObject(indexName, objectID, new ArrayList<>()); - } - - /** - * (asynchronously) Retrieve one object from the index. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable - * attributes are returned. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getObjectAsync( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getObjectValidateBeforeCall( - indexName, - objectID, - attributesToRetrieve, - callback - ); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getObjects - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getObjectsCall( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = getObjectsParams; - - // create path and map variables - String requestPath = "/1/indexes/*/objects"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getObjectsValidateBeforeCall( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'getObjectsParams' is set - if (getObjectsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'getObjectsParams' when calling getObjects(Async)" - ); - } - - return getObjectsCall(getObjectsParams, callback); - } - - /** - * Retrieve one or more objects, potentially from different indices, in a single API call. - * - * @param getObjectsParams (required) - * @return GetObjectsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetObjectsResponse getObjects(GetObjectsParams getObjectsParams) - throws AlgoliaRuntimeException { - Call req = getObjectsValidateBeforeCall(getObjectsParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetObjects(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve one or more objects, potentially from different indices, in a single - * API call. - * - * @param getObjectsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getObjectsAsync( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getObjectsValidateBeforeCall(getObjectsParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getRuleCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getRuleValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getRule(Async)" - ); - } - - return getRuleCall(indexName, objectID, callback); - } - - /** - * Retrieve the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return Rule - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Rule getRule(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = getRuleValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getRuleAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getRuleValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSettingsCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/settings".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSettingsValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getSettings(Async)" - ); - } - - return getSettingsCall(indexName, callback); - } - - /** - * Retrieve settings of a given indexName. - * - * @param indexName The index in which to perform the request. (required) - * @return IndexSettings - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public IndexSettings getSettings(String indexName) - throws AlgoliaRuntimeException { - Call req = getSettingsValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetSettings(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve settings of a given indexName. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSettingsAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSettingsValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSources - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSourcesCall(final ApiCallback> callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/security/sources"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSourcesValidateBeforeCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - return getSourcesCall(callback); - } - - /** - * List all allowed sources. - * - * @return List<Source> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public List getSources() throws AlgoliaRuntimeException { - Call req = getSourcesValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetSources(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List all allowed sources. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSourcesAsync(final ApiCallback> callback) - throws AlgoliaRuntimeException { - Call call = getSourcesValidateBeforeCall(callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSynonymCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSynonymValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getSynonym(Async)" - ); - } - - return getSynonymCall(indexName, objectID, callback); - } - - /** - * Fetch a synonym object identified by its objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return SynonymHit - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SynonymHit getSynonym(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = getSynonymValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetSynonym(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Fetch a synonym object identified by its objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSynonymAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSynonymValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTask - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTaskCall( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/task/{taskID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{taskID\\}", this.escapeString(taskID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTaskValidateBeforeCall( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getTask(Async)" - ); - } - - // verify the required parameter 'taskID' is set - if (taskID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'taskID' when calling getTask(Async)" - ); - } - - return getTaskCall(indexName, taskID, callback); - } - - /** - * Check the current status of a given task. - * - * @param indexName The index in which to perform the request. (required) - * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) - * @return GetTaskResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTaskResponse getTask(String indexName, Integer taskID) - throws AlgoliaRuntimeException { - Call req = getTaskValidateBeforeCall(indexName, taskID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetTask(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Check the current status of a given task. - * - * @param indexName The index in which to perform the request. (required) - * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTaskAsync( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTaskValidateBeforeCall(indexName, taskID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopUserIdsCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping/top"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopUserIdsValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getTopUserIdsCall(callback); - } - - /** - * Get the top 10 userIDs with the highest number of records per cluster. The data returned will - * usually be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following array of userIDs and clusters. - * - * @return GetTopUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopUserIdsResponse getTopUserIds() throws AlgoliaRuntimeException { - Call req = getTopUserIdsValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetTopUserIds(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the top 10 userIDs with the highest number of records per cluster. The - * data returned will usually be a few seconds behind real time, because userID usage may take up - * to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK - * and contains the following array of userIDs and clusters. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopUserIdsAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopUserIdsValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getUserIdCall(String userID, final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/clusters/mapping/{userID}".replaceAll( - "\\{userID\\}", - this.escapeString(userID.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getUserIdValidateBeforeCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userID' is set - if (userID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userID' when calling getUserId(Async)" - ); - } - - return getUserIdCall(userID, callback); - } - - /** - * Returns the userID data stored in the mapping. The data returned will usually be a few seconds - * behind real time, because userID usage may take up to a few seconds to propagate to the - * different clusters. Upon success, the response is 200 OK and contains the following userID - * data. - * - * @param userID userID to assign. (required) - * @return UserId - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UserId getUserId(String userID) throws AlgoliaRuntimeException { - Call req = getUserIdValidateBeforeCall(userID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.GetUserId(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns the userID data stored in the mapping. The data returned will usually - * be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following userID data. - * - * @param userID userID to assign. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getUserIdAsync(String userID, final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = getUserIdValidateBeforeCall(userID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for hasPendingMappings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call hasPendingMappingsCall( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping/pending"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (getClusters != null) { - queryParams.addAll(this.parameterToPair("getClusters", getClusters)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call hasPendingMappingsValidateBeforeCall( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return hasPendingMappingsCall(getClusters, callback); - } - - /** - * Get the status of your clusters' migrations or user creations. Creating a large batch of users - * or migrating your multi-cluster may take quite some time. This method lets you retrieve the - * status of the migration, so you can know when it's done. Upon success, the response is 200 OK. - * A successful response indicates that the operation has been taken into account, and the userIDs - * are directly usable. - * - * @param getClusters Whether to get clusters or not. (optional) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse hasPendingMappings(Boolean getClusters) - throws AlgoliaRuntimeException { - Call req = hasPendingMappingsValidateBeforeCall(getClusters, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.HasPendingMappings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public CreatedAtResponse hasPendingMappings() throws AlgoliaRuntimeException { - return this.hasPendingMappings(null); - } - - /** - * (asynchronously) Get the status of your clusters' migrations or user creations. Creating a - * large batch of users or migrating your multi-cluster may take quite some time. This method lets - * you retrieve the status of the migration, so you can know when it's done. Upon success, the - * response is 200 OK. A successful response indicates that the operation has been taken into - * account, and the userIDs are directly usable. - * - * @param getClusters Whether to get clusters or not. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call hasPendingMappingsAsync( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = hasPendingMappingsValidateBeforeCall(getClusters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listApiKeys - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listApiKeysCall(final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/keys"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listApiKeysValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listApiKeysCall(callback); - } - - /** - * List API keys, along with their associated rights. - * - * @return ListApiKeysResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListApiKeysResponse listApiKeys() throws AlgoliaRuntimeException { - Call req = listApiKeysValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ListApiKeys(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List API keys, along with their associated rights. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listApiKeysAsync(final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = listApiKeysValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listClusters - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listClustersCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listClustersValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listClustersCall(callback); - } - - /** - * List the clusters available in a multi-clusters setup for a single appID. Upon success, the - * response is 200 OK and contains the following clusters. - * - * @return ListClustersResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListClustersResponse listClusters() throws AlgoliaRuntimeException { - Call req = listClustersValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ListClusters(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List the clusters available in a multi-clusters setup for a single appID. Upon - * success, the response is 200 OK and contains the following clusters. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listClustersAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listClustersValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listIndices - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listIndicesCall( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/indexes"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listIndicesValidateBeforeCall( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listIndicesCall(page, callback); - } - - /** - * List existing indexes from an application. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @return ListIndicesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListIndicesResponse listIndices(Integer page) - throws AlgoliaRuntimeException { - Call req = listIndicesValidateBeforeCall(page, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ListIndices(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public ListIndicesResponse listIndices() throws AlgoliaRuntimeException { - return this.listIndices(null); - } - - /** - * (asynchronously) List existing indexes from an application. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listIndicesAsync( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listIndicesValidateBeforeCall(page, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listUserIdsCall( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - if (hitsPerPage != null) { - queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listUserIdsValidateBeforeCall( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listUserIdsCall(page, hitsPerPage, callback); - } - - /** - * List the userIDs assigned to a multi-clusters appID. The data returned will usually be a few - * seconds behind real time, because userID usage may take up to a few seconds to propagate to the - * different clusters. Upon success, the response is 200 OK and contains the following userIDs - * data. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @return ListUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListUserIdsResponse listUserIds(Integer page, Integer hitsPerPage) - throws AlgoliaRuntimeException { - Call req = listUserIdsValidateBeforeCall(page, hitsPerPage, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ListUserIds(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public ListUserIdsResponse listUserIds() throws AlgoliaRuntimeException { - return this.listUserIds(null, 100); - } - - /** - * (asynchronously) List the userIDs assigned to a multi-clusters appID. The data returned will - * usually be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following userIDs data. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listUserIdsAsync( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listUserIdsValidateBeforeCall(page, hitsPerPage, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for multipleBatch - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call multipleBatchCall( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchParams; - - // create path and map variables - String requestPath = "/1/indexes/*/batch"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call multipleBatchValidateBeforeCall( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'batchParams' is set - if (batchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchParams' when calling multipleBatch(Async)" - ); - } - - return multipleBatchCall(batchParams, callback); - } - - /** - * Perform multiple write operations, potentially targeting multiple indices, in a single API - * call. - * - * @param batchParams (required) - * @return MultipleBatchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public MultipleBatchResponse multipleBatch(BatchParams batchParams) - throws AlgoliaRuntimeException { - Call req = multipleBatchValidateBeforeCall(batchParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.MultipleBatch(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Perform multiple write operations, potentially targeting multiple indices, in - * a single API call. - * - * @param batchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call multipleBatchAsync( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = multipleBatchValidateBeforeCall(batchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for multipleQueries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call multipleQueriesCall( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = multipleQueriesParams; - - // create path and map variables - String requestPath = "/1/indexes/*/queries"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call multipleQueriesValidateBeforeCall( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'multipleQueriesParams' is set - if (multipleQueriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'multipleQueriesParams' when calling" + - " multipleQueries(Async)" - ); - } - - return multipleQueriesCall(multipleQueriesParams, callback); - } - - /** - * Get search results for the given requests. - * - * @param multipleQueriesParams (required) - * @return MultipleQueriesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public MultipleQueriesResponse multipleQueries( - MultipleQueriesParams multipleQueriesParams - ) throws AlgoliaRuntimeException { - Call req = multipleQueriesValidateBeforeCall(multipleQueriesParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.MultipleQueries(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get search results for the given requests. - * - * @param multipleQueriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call multipleQueriesAsync( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = multipleQueriesValidateBeforeCall( - multipleQueriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for operationIndex - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call operationIndexCall( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = operationIndexParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/operation".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call operationIndexValidateBeforeCall( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling operationIndex(Async)" - ); - } - - // verify the required parameter 'operationIndexParams' is set - if (operationIndexParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'operationIndexParams' when calling" + - " operationIndex(Async)" - ); - } - - return operationIndexCall(indexName, operationIndexParams, callback); - } - - /** - * Peforms a copy or a move operation on a index. - * - * @param indexName The index in which to perform the request. (required) - * @param operationIndexParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse operationIndex( - String indexName, - OperationIndexParams operationIndexParams - ) throws AlgoliaRuntimeException { - Call req = operationIndexValidateBeforeCall( - indexName, - operationIndexParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.OperationIndex(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Peforms a copy or a move operation on a index. - * - * @param indexName The index in which to perform the request. (required) - * @param operationIndexParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call operationIndexAsync( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = operationIndexValidateBeforeCall( - indexName, - operationIndexParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for partialUpdateObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call partialUpdateObjectCall( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = attributeOrBuiltInOperation; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}/partial".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (createIfNotExists != null) { - queryParams.addAll( - this.parameterToPair("createIfNotExists", createIfNotExists) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call partialUpdateObjectValidateBeforeCall( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling partialUpdateObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling partialUpdateObject(Async)" - ); - } - - // verify the required parameter 'attributeOrBuiltInOperation' is set - if (attributeOrBuiltInOperation == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'attributeOrBuiltInOperation' when calling" + - " partialUpdateObject(Async)" - ); - } - - return partialUpdateObjectCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - callback - ); - } - - /** - * Update one or more attributes of an existing object. This method lets you update only a part of - * an existing object, either by adding new attributes or updating existing ones. You can - * partially update several objects in a single method call. If the index targeted by this - * operation doesn't exist yet, it's automatically created. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributeOrBuiltInOperation List of attributes to update. (required) - * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to - * true) - * @return UpdatedAtWithObjectIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtWithObjectIdResponse partialUpdateObject( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists - ) throws AlgoliaRuntimeException { - Call req = partialUpdateObjectValidateBeforeCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.PartialUpdateObject( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtWithObjectIdResponse partialUpdateObject( - String indexName, - String objectID, - List> attributeOrBuiltInOperation - ) throws AlgoliaRuntimeException { - return this.partialUpdateObject( - indexName, - objectID, - attributeOrBuiltInOperation, - true - ); - } - - /** - * (asynchronously) Update one or more attributes of an existing object. This method lets you - * update only a part of an existing object, either by adding new attributes or updating existing - * ones. You can partially update several objects in a single method call. If the index targeted - * by this operation doesn't exist yet, it's automatically created. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributeOrBuiltInOperation List of attributes to update. (required) - * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to - * true) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call partialUpdateObjectAsync( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = partialUpdateObjectValidateBeforeCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair(parameter.getKey(), parameter.getValue()) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for removeUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call removeUserIdCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/clusters/mapping/{userID}".replaceAll( - "\\{userID\\}", - this.escapeString(userID.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call removeUserIdValidateBeforeCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userID' is set - if (userID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userID' when calling removeUserId(Async)" - ); - } - - return removeUserIdCall(userID, callback); - } - - /** - * Remove a userID and its associated data from the multi-clusters. Upon success, the response is - * 200 OK and a task is created to remove the userID data and mapping. - * - * @param userID userID to assign. (required) - * @return RemoveUserIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public RemoveUserIdResponse removeUserId(String userID) - throws AlgoliaRuntimeException { - Call req = removeUserIdValidateBeforeCall(userID, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.RemoveUserId(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove a userID and its associated data from the multi-clusters. Upon success, - * the response is 200 OK and a task is created to remove the userID data and mapping. - * - * @param userID userID to assign. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call removeUserIdAsync( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = removeUserIdValidateBeforeCall(userID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for replaceSources - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call replaceSourcesCall( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = source; - - // create path and map variables - String requestPath = "/1/security/sources"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call replaceSourcesValidateBeforeCall( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling replaceSources(Async)" - ); - } - - return replaceSourcesCall(source, callback); - } - - /** - * Replace all allowed sources. - * - * @param source The sources to allow. (required) - * @return ReplaceSourceResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ReplaceSourceResponse replaceSources(List source) - throws AlgoliaRuntimeException { - Call req = replaceSourcesValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.ReplaceSources(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Replace all allowed sources. - * - * @param source The sources to allow. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call replaceSourcesAsync( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = replaceSourcesValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for restoreApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call restoreApiKeyCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}/restore".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call restoreApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling restoreApiKey(Async)" - ); - } - - return restoreApiKeyCall(key, callback); - } - - /** - * Restore a deleted API key, along with its associated rights. - * - * @param key API Key string. (required) - * @return AddApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public AddApiKeyResponse restoreApiKey(String key) - throws AlgoliaRuntimeException { - Call req = restoreApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.RestoreApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Restore a deleted API key, along with its associated rights. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call restoreApiKeyAsync( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = restoreApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveObjectCall( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveObjectValidateBeforeCall( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveObject(Async)" - ); - } - - // verify the required parameter 'body' is set - if (body == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'body' when calling saveObject(Async)" - ); - } - - return saveObjectCall(indexName, body, callback); - } - - /** - * Add an object to the index, automatically assigning it an object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param body The Algolia record. (required) - * @return SaveObjectResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SaveObjectResponse saveObject(String indexName, Object body) - throws AlgoliaRuntimeException { - Call req = saveObjectValidateBeforeCall(indexName, body, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SaveObject(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add an object to the index, automatically assigning it an object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param body The Algolia record. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveObjectAsync( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveObjectValidateBeforeCall(indexName, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveRuleCall( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = rule; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveRuleValidateBeforeCall( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling saveRule(Async)" - ); - } - - // verify the required parameter 'rule' is set - if (rule == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'rule' when calling saveRule(Async)" - ); - } - - return saveRuleCall(indexName, objectID, rule, forwardToReplicas, callback); - } - - /** - * Create or update the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedRuleResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedRuleResponse saveRule( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = saveRuleValidateBeforeCall( - indexName, - objectID, - rule, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SaveRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedRuleResponse saveRule( - String indexName, - String objectID, - Rule rule - ) throws AlgoliaRuntimeException { - return this.saveRule(indexName, objectID, rule, null); - } - - /** - * (asynchronously) Create or update the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveRuleAsync( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveRuleValidateBeforeCall( - indexName, - objectID, - rule, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveSynonymCall( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = synonymHit; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveSynonymValidateBeforeCall( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling saveSynonym(Async)" - ); - } - - // verify the required parameter 'synonymHit' is set - if (synonymHit == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'synonymHit' when calling saveSynonym(Async)" - ); - } - - return saveSynonymCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - callback - ); - } - - /** - * Create a new synonym object or update the existing synonym object with the given object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return SaveSynonymResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SaveSynonymResponse saveSynonym( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = saveSynonymValidateBeforeCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SaveSynonym(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public SaveSynonymResponse saveSynonym( - String indexName, - String objectID, - SynonymHit synonymHit - ) throws AlgoliaRuntimeException { - return this.saveSynonym(indexName, objectID, synonymHit, null); - } - - /** - * (asynchronously) Create a new synonym object or update the existing synonym object with the - * given object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveSynonymAsync( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveSynonymValidateBeforeCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveSynonymsCall( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = synonymHit; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - if (replaceExistingSynonyms != null) { - queryParams.addAll( - this.parameterToPair("replaceExistingSynonyms", replaceExistingSynonyms) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveSynonymsValidateBeforeCall( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveSynonyms(Async)" - ); - } - - // verify the required parameter 'synonymHit' is set - if (synonymHit == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'synonymHit' when calling saveSynonyms(Async)" - ); - } - - return saveSynonymsCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - callback - ); - } - - /** - * Create/update multiple synonym objects at once, potentially replacing the entire list of - * synonyms if replaceExistingSynonyms is true. - * - * @param indexName The index in which to perform the request. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this - * request. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse saveSynonyms( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms - ) throws AlgoliaRuntimeException { - Call req = saveSynonymsValidateBeforeCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SaveSynonyms(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse saveSynonyms( - String indexName, - List synonymHit - ) throws AlgoliaRuntimeException { - return this.saveSynonyms(indexName, synonymHit, null, null); - } - - /** - * (asynchronously) Create/update multiple synonym objects at once, potentially replacing the - * entire list of synonyms if replaceExistingSynonyms is true. - * - * @param indexName The index in which to perform the request. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this - * request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveSynonymsAsync( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveSynonymsValidateBeforeCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for search - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/query".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchValidateBeforeCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling search(Async)" - ); - } - - // verify the required parameter 'searchParams' is set - if (searchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchParams' when calling search(Async)" - ); - } - - return searchCall(indexName, searchParams, callback); - } - - /** - * Get search results. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @return SearchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchResponse search(String indexName, SearchParams searchParams) - throws AlgoliaRuntimeException { - Call req = searchValidateBeforeCall(indexName, searchParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.Search(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get search results. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchAsync( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchValidateBeforeCall(indexName, searchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchDictionaryEntries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchDictionaryEntriesCall( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchDictionaryEntriesParams; - - // create path and map variables - String requestPath = - "/1/dictionaries/{dictionaryName}/search".replaceAll( - "\\{dictionaryName\\}", - this.escapeString(dictionaryName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchDictionaryEntriesValidateBeforeCall( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionaryName' is set - if (dictionaryName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionaryName' when calling" + - " searchDictionaryEntries(Async)" - ); - } - - // verify the required parameter 'searchDictionaryEntriesParams' is set - if (searchDictionaryEntriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchDictionaryEntriesParams' when calling" + - " searchDictionaryEntries(Async)" - ); - } - - return searchDictionaryEntriesCall( - dictionaryName, - searchDictionaryEntriesParams, - callback - ); - } - - /** - * Search the dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param searchDictionaryEntriesParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse searchDictionaryEntries( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams - ) throws AlgoliaRuntimeException { - Call req = searchDictionaryEntriesValidateBeforeCall( - dictionaryName, - searchDictionaryEntriesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SearchDictionaryEntries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search the dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param searchDictionaryEntriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchDictionaryEntriesAsync( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchDictionaryEntriesValidateBeforeCall( - dictionaryName, - searchDictionaryEntriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchForFacetValues - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchForFacetValuesCall( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchForFacetValuesRequest; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/facets/{facetName}/query".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{facetName\\}", this.escapeString(facetName.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchForFacetValuesValidateBeforeCall( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchForFacetValues(Async)" - ); - } - - // verify the required parameter 'facetName' is set - if (facetName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'facetName' when calling searchForFacetValues(Async)" - ); - } - - return searchForFacetValuesCall( - indexName, - facetName, - searchForFacetValuesRequest, - callback - ); - } - - /** - * Search for values of a given facet, optionally restricting the returned values to those - * contained in objects matching other search criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param facetName The facet name. (required) - * @param searchForFacetValuesRequest (optional) - * @return SearchForFacetValuesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchForFacetValuesResponse searchForFacetValues( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest - ) throws AlgoliaRuntimeException { - Call req = searchForFacetValuesValidateBeforeCall( - indexName, - facetName, - searchForFacetValuesRequest, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SearchForFacetValues( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public SearchForFacetValuesResponse searchForFacetValues( - String indexName, - String facetName - ) throws AlgoliaRuntimeException { - return this.searchForFacetValues(indexName, facetName, null); - } - - /** - * (asynchronously) Search for values of a given facet, optionally restricting the returned values - * to those contained in objects matching other search criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param facetName The facet name. (required) - * @param searchForFacetValuesRequest (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchForFacetValuesAsync( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchForFacetValuesValidateBeforeCall( - indexName, - facetName, - searchForFacetValuesRequest, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchRulesCall( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchRulesParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/search".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchRulesValidateBeforeCall( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchRules(Async)" - ); - } - - // verify the required parameter 'searchRulesParams' is set - if (searchRulesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchRulesParams' when calling searchRules(Async)" - ); - } - - return searchRulesCall(indexName, searchRulesParams, callback); - } - - /** - * Search for rules matching various criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param searchRulesParams (required) - * @return SearchRulesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchRulesResponse searchRules( - String indexName, - SearchRulesParams searchRulesParams - ) throws AlgoliaRuntimeException { - Call req = searchRulesValidateBeforeCall( - indexName, - searchRulesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SearchRules(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search for rules matching various criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param searchRulesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchRulesAsync( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchRulesValidateBeforeCall( - indexName, - searchRulesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchSynonymsCall( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/search".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (query != null) { - queryParams.addAll(this.parameterToPair("query", query)); - } - - if (type != null) { - queryParams.addAll(this.parameterToPair("type", type)); - } - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - if (hitsPerPage != null) { - queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchSynonymsValidateBeforeCall( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchSynonyms(Async)" - ); - } - - return searchSynonymsCall( - indexName, - query, - type, - page, - hitsPerPage, - callback - ); - } - - /** - * Search or browse all synonyms, optionally filtering them by type. - * - * @param indexName The index in which to perform the request. (required) - * @param query Search for specific synonyms matching this string. (optional, default to ) - * @param type Only search for specific types of synonyms. (optional) - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional, default to 0) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @return SearchSynonymsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchSynonymsResponse searchSynonyms( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage - ) throws AlgoliaRuntimeException { - Call req = searchSynonymsValidateBeforeCall( - indexName, - query, - type, - page, - hitsPerPage, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SearchSynonyms(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public SearchSynonymsResponse searchSynonyms(String indexName) - throws AlgoliaRuntimeException { - return this.searchSynonyms(indexName, "", null, 0, 100); - } - - /** - * (asynchronously) Search or browse all synonyms, optionally filtering them by type. - * - * @param indexName The index in which to perform the request. (required) - * @param query Search for specific synonyms matching this string. (optional, default to ) - * @param type Only search for specific types of synonyms. (optional) - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional, default to 0) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchSynonymsAsync( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchSynonymsValidateBeforeCall( - indexName, - query, - type, - page, - hitsPerPage, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchUserIdsCall( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchUserIdsParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping/search"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchUserIdsValidateBeforeCall( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'searchUserIdsParams' is set - if (searchUserIdsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchUserIdsParams' when calling searchUserIds(Async)" - ); - } - - return searchUserIdsCall(searchUserIdsParams, callback); - } - - /** - * Search for userIDs. The data returned will usually be a few seconds behind real time, because - * userID usage may take up to a few seconds propagate to the different clusters. To keep updates - * moving quickly, the index of userIDs isn't built synchronously with the mapping. Instead, the - * index is built once every 12h, at the same time as the update of userID usage. For example, - * when you perform a modification like adding or moving a userID, the search will report an - * outdated value until the next rebuild of the mapping, which takes place every 12h. Upon - * success, the response is 200 OK and contains the following userIDs data. - * - * @param searchUserIdsParams (required) - * @return SearchUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchUserIdsResponse searchUserIds( - SearchUserIdsParams searchUserIdsParams - ) throws AlgoliaRuntimeException { - Call req = searchUserIdsValidateBeforeCall(searchUserIdsParams, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SearchUserIds(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search for userIDs. The data returned will usually be a few seconds behind - * real time, because userID usage may take up to a few seconds propagate to the different - * clusters. To keep updates moving quickly, the index of userIDs isn't built synchronously - * with the mapping. Instead, the index is built once every 12h, at the same time as the update of - * userID usage. For example, when you perform a modification like adding or moving a userID, the - * search will report an outdated value until the next rebuild of the mapping, which takes place - * every 12h. Upon success, the response is 200 OK and contains the following userIDs data. - * - * @param searchUserIdsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchUserIdsAsync( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchUserIdsValidateBeforeCall(searchUserIdsParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for setDictionarySettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call setDictionarySettingsCall( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = dictionarySettingsParams; - - // create path and map variables - String requestPath = "/1/dictionaries/*/settings"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call setDictionarySettingsValidateBeforeCall( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionarySettingsParams' is set - if (dictionarySettingsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionarySettingsParams' when calling" + - " setDictionarySettings(Async)" - ); - } - - return setDictionarySettingsCall(dictionarySettingsParams, callback); - } - - /** - * Set dictionary settings. - * - * @param dictionarySettingsParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse setDictionarySettings( - DictionarySettingsParams dictionarySettingsParams - ) throws AlgoliaRuntimeException { - Call req = setDictionarySettingsValidateBeforeCall( - dictionarySettingsParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SetDictionarySettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Set dictionary settings. - * - * @param dictionarySettingsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call setDictionarySettingsAsync( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = setDictionarySettingsValidateBeforeCall( - dictionarySettingsParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for setSettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call setSettingsCall( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = indexSettings; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/settings".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call setSettingsValidateBeforeCall( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling setSettings(Async)" - ); - } - - // verify the required parameter 'indexSettings' is set - if (indexSettings == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexSettings' when calling setSettings(Async)" - ); - } - - return setSettingsCall( - indexName, - indexSettings, - forwardToReplicas, - callback - ); - } - - /** - * Update settings of a given indexName. Only specified settings are overridden; unspecified - * settings are left unchanged. Specifying null for a setting resets it to its default value. - * - * @param indexName The index in which to perform the request. (required) - * @param indexSettings (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse setSettings( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = setSettingsValidateBeforeCall( - indexName, - indexSettings, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponseSearch.SetSettings(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse setSettings( - String indexName, - IndexSettings indexSettings - ) throws AlgoliaRuntimeException { - return this.setSettings(indexName, indexSettings, null); - } - - /** - * (asynchronously) Update settings of a given indexName. Only specified settings are overridden; - * unspecified settings are left unchanged. Specifying null for a setting resets it to its default - * value. - * - * @param indexName The index in which to perform the request. (required) - * @param indexSettings (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call setSettingsAsync( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = setSettingsValidateBeforeCall( - indexName, - indexSettings, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for updateApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call updateApiKeyCall( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = apiKey; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call updateApiKeyValidateBeforeCall( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling updateApiKey(Async)" - ); - } - - // verify the required parameter 'apiKey' is set - if (apiKey == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'apiKey' when calling updateApiKey(Async)" - ); - } - - return updateApiKeyCall(key, apiKey, callback); - } - - /** - * Replace every permission of an existing API key. - * - * @param key API Key string. (required) - * @param apiKey (required) - * @return UpdateApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdateApiKeyResponse updateApiKey(String key, ApiKey apiKey) - throws AlgoliaRuntimeException { - Call req = updateApiKeyValidateBeforeCall(key, apiKey, null); - if (req instanceof CallEcho) { - return new EchoResponseSearch.UpdateApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Replace every permission of an existing API key. - * - * @param key API Key string. (required) - * @param apiKey (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call updateApiKeyAsync( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = updateApiKeyValidateBeforeCall(key, apiKey, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts b/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts deleted file mode 100644 index 54b4e0b70c..0000000000 --- a/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts +++ /dev/null @@ -1,305 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, - shuffle, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { MultipleQueriesParams } from '../model/multipleQueriesParams'; -import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; -import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest'; -import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse'; -import type { SearchParams } from '../model/searchParams'; -import type { SearchResponse } from '../model/searchResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -function getDefaultHosts(appId: string): Host[] { - return ( - [ - { - url: `${appId}-dsn.algolia.net`, - accept: 'read', - protocol: 'https', - }, - { - url: `${appId}.algolia.net`, - accept: 'write', - protocol: 'https', - }, - ] as Host[] - ).concat( - shuffle([ - { - url: `${appId}-1.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-2.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-3.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]) - ); -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createAlgoliasearchLiteApi(options: CreateClientOptions) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.appId), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'AlgoliasearchLite', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * Get search results for the given requests. - * - * @summary Get search results for the given requests. - * @param multipleQueriesParams - The multipleQueriesParams object. - */ - multipleQueries( - multipleQueriesParams: MultipleQueriesParams, - requestOptions?: RequestOptions - ): Promise { - if (!multipleQueriesParams) { - throw new Error( - 'Parameter `multipleQueriesParams` is required when calling `multipleQueries`.' - ); - } - - if (!multipleQueriesParams.requests) { - throw new Error( - 'Parameter `multipleQueriesParams.requests` is required when calling `multipleQueries`.' - ); - } - - const requestPath = '/1/indexes/*/queries'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: multipleQueriesParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get search results. - * - * @summary Get search results. - * @param search - The search object. - * @param search.indexName - The index in which to perform the request. - * @param search.searchParams - The searchParams object. - */ - search( - { indexName, searchParams }: SearchProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `search`.' - ); - } - - if (!searchParams) { - throw new Error( - 'Parameter `searchParams` is required when calling `search`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/query'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search for values of a given facet, optionally restricting the returned values to those contained in objects matching other search criteria. - * - * @summary Search for values of a given facet. - * @param searchForFacetValues - The searchForFacetValues object. - * @param searchForFacetValues.indexName - The index in which to perform the request. - * @param searchForFacetValues.facetName - The facet name. - * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object. - */ - searchForFacetValues( - { - indexName, - facetName, - searchForFacetValuesRequest, - }: SearchForFacetValuesProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `searchForFacetValues`.' - ); - } - - if (!facetName) { - throw new Error( - 'Parameter `facetName` is required when calling `searchForFacetValues`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/facets/{facetName}/query' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{facetName}', encodeURIComponent(facetName)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchForFacetValuesRequest, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type AlgoliasearchLiteApi = ReturnType< - typeof createAlgoliasearchLiteApi ->; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type SearchProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - searchParams: SearchParams; -}; - -export type SearchForFacetValuesProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * The facet name. - */ - facetName: string; - searchForFacetValuesRequest?: SearchForFacetValuesRequest; -}; diff --git a/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts index 53544310a6..201d55e66c 100644 --- a/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts @@ -1,8 +1,8 @@ import type { - AnalyticsApi, + AnalyticsClient, Region as AnalyticsRegion, -} from '@experimental-api-clients-automation/client-analytics/src/analyticsApi'; -import { createAnalyticsApi } from '@experimental-api-clients-automation/client-analytics/src/analyticsApi'; +} from '@experimental-api-clients-automation/client-analytics/src/analyticsClient'; +import { createAnalyticsClient } from '@experimental-api-clients-automation/client-analytics/src/analyticsClient'; import type { CreateClientOptions, Host, @@ -14,14 +14,14 @@ import { createBrowserLocalStorageCache, } from '@experimental-api-clients-automation/client-common'; import type { - PersonalizationApi, + PersonalizationClient, Region as PersonalizationRegion, -} from '@experimental-api-clients-automation/client-personalization/src/personalizationApi'; -import { createPersonalizationApi } from '@experimental-api-clients-automation/client-personalization/src/personalizationApi'; +} from '@experimental-api-clients-automation/client-personalization/src/personalizationClient'; +import { createPersonalizationClient } from '@experimental-api-clients-automation/client-personalization/src/personalizationClient'; import { - createSearchApi, + createSearchClient, apiClientVersion, -} from '@experimental-api-clients-automation/client-search/src/searchApi'; +} from '@experimental-api-clients-automation/client-search/src/searchClient'; import { createXhrRequester } from '@experimental-api-clients-automation/requester-browser-xhr'; // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @@ -63,8 +63,8 @@ export function algoliasearch( analyticsApiKey: string, region?: AnalyticsRegion, analyticsOptions?: { requester?: Requester; hosts?: Host[] } - ): AnalyticsApi { - return createAnalyticsApi({ + ): AnalyticsClient { + return createAnalyticsClient({ appId: analyticsAppId, apiKey: analyticsApiKey, region, @@ -78,12 +78,12 @@ export function algoliasearch( personalizationApiKey: string, region: PersonalizationRegion, personalizationOptions?: { requester?: Requester; hosts?: Host[] } - ): PersonalizationApi { + ): PersonalizationClient { if (!region) { throw new Error('`region` is missing.'); } - return createPersonalizationApi({ + return createPersonalizationClient({ appId: personalizationAppId, apiKey: personalizationApiKey, region, @@ -93,7 +93,7 @@ export function algoliasearch( } return { - ...createSearchApi({ appId, apiKey, ...commonOptions }), + ...createSearchClient({ appId, apiKey, ...commonOptions }), initAnalytics, initPersonalization, }; diff --git a/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts b/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts index 8bd40f1d36..7e2f758d66 100644 --- a/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts @@ -1,8 +1,8 @@ import type { - AnalyticsApi, + AnalyticsClient, Region as AnalyticsRegion, -} from '@experimental-api-clients-automation/client-analytics/src/analyticsApi'; -import { createAnalyticsApi } from '@experimental-api-clients-automation/client-analytics/src/analyticsApi'; +} from '@experimental-api-clients-automation/client-analytics/src/analyticsClient'; +import { createAnalyticsClient } from '@experimental-api-clients-automation/client-analytics/src/analyticsClient'; import type { CreateClientOptions, Host, @@ -13,11 +13,11 @@ import { createNullCache, } from '@experimental-api-clients-automation/client-common'; import type { - PersonalizationApi, + PersonalizationClient, Region as PersonalizationRegion, -} from '@experimental-api-clients-automation/client-personalization/src/personalizationApi'; -import { createPersonalizationApi } from '@experimental-api-clients-automation/client-personalization/src/personalizationApi'; -import { createSearchApi } from '@experimental-api-clients-automation/client-search/src/searchApi'; +} from '@experimental-api-clients-automation/client-personalization/src/personalizationClient'; +import { createPersonalizationClient } from '@experimental-api-clients-automation/client-personalization/src/personalizationClient'; +import { createSearchClient } from '@experimental-api-clients-automation/client-search/src/searchClient'; import { createHttpRequester } from '@experimental-api-clients-automation/requester-node-http'; // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @@ -53,8 +53,8 @@ export function algoliasearch( analyticsApiKey: string, region?: AnalyticsRegion, analyticsOptions?: { requester?: Requester; hosts?: Host[] } - ): AnalyticsApi { - return createAnalyticsApi({ + ): AnalyticsClient { + return createAnalyticsClient({ appId: analyticsAppId, apiKey: analyticsApiKey, region, @@ -68,12 +68,12 @@ export function algoliasearch( personalizationApiKey: string, region: PersonalizationRegion, personalizationOptions?: { requester?: Requester; hosts?: Host[] } - ): PersonalizationApi { + ): PersonalizationClient { if (!region) { throw new Error('`region` is missing.'); } - return createPersonalizationApi({ + return createPersonalizationClient({ appId: personalizationAppId, apiKey: personalizationApiKey, region, @@ -83,7 +83,7 @@ export function algoliasearch( } return { - ...createSearchApi({ appId, apiKey, ...commonOptions }), + ...createSearchClient({ appId, apiKey, ...commonOptions }), initAnalytics, initPersonalization, }; diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts deleted file mode 100644 index c03d450203..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts +++ /dev/null @@ -1,503 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { ABTest } from '../model/aBTest'; -import type { ABTestResponse } from '../model/aBTestResponse'; -import type { AddABTestsRequest } from '../model/addABTestsRequest'; -import type { ListABTestsResponse } from '../model/listABTestsResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -export type Region = 'de' | 'us'; - -function getDefaultHosts(region?: Region): Host[] { - const regionHost = region ? `.${region}.` : '.'; - - return [ - { - url: `analytics${regionHost}algolia.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createAbtestingApi( - options: CreateClientOptions & { region?: Region } -) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.region), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Abtesting', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * Creates a new A/B test with provided configuration. You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants. - * - * @summary Creates a new A/B test with provided configuration. - * @param addABTestsRequest - The addABTestsRequest object. - */ - addABTests( - addABTestsRequest: AddABTestsRequest, - requestOptions?: RequestOptions - ): Promise { - if (!addABTestsRequest) { - throw new Error( - 'Parameter `addABTestsRequest` is required when calling `addABTests`.' - ); - } - - if (!addABTestsRequest.name) { - throw new Error( - 'Parameter `addABTestsRequest.name` is required when calling `addABTests`.' - ); - } - if (!addABTestsRequest.variant) { - throw new Error( - 'Parameter `addABTestsRequest.variant` is required when calling `addABTests`.' - ); - } - if (!addABTestsRequest.endAt) { - throw new Error( - 'Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.' - ); - } - - const requestPath = '/2/abtests'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: addABTestsRequest, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Deletes the A/B Test and removes all associated metadata & metrics. - * - * @summary Deletes the A/B Test. - * @param deleteABTest - The deleteABTest object. - * @param deleteABTest.id - The A/B test ID. - */ - deleteABTest( - { id }: DeleteABTestProps, - requestOptions?: RequestOptions - ): Promise { - if (!id) { - throw new Error( - 'Parameter `id` is required when calling `deleteABTest`.' - ); - } - - const requestPath = '/2/abtests/{id}'.replace( - '{id}', - encodeURIComponent(id) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns metadata and metrics for A/B test id. Behaves in the same way as GET /2/abtests however the endpoint will return 403. - * - * @summary Returns metadata and metrics for A/B test id. - * @param getABTest - The getABTest object. - * @param getABTest.id - The A/B test ID. - */ - getABTest( - { id }: GetABTestProps, - requestOptions?: RequestOptions - ): Promise { - if (!id) { - throw new Error('Parameter `id` is required when calling `getABTest`.'); - } - - const requestPath = '/2/abtests/{id}'.replace( - '{id}', - encodeURIComponent(id) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Fetch all existing A/B tests for App that are available for the current API Key. Returns an array of metadata and metrics. When no data has been processed, the metrics will be returned as null. - * - * @summary Fetch all existing A/B tests for App that are available for the current API Key. - * @param listABTests - The listABTests object. - * @param listABTests.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param listABTests.limit - Number of records to return. Limit is the size of the page. - */ - listABTests( - { offset, limit }: ListABTestsProps, - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/2/abtests'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Marks the A/B test as stopped. At this point, the test is over and cannot be restarted. As a result, your application is back to normal: index A will perform as usual, receiving 100% of all search requests. Associated metadata and metrics are still stored. - * - * @summary Marks the A/B test as stopped. - * @param stopABTest - The stopABTest object. - * @param stopABTest.id - The A/B test ID. - */ - stopABTest( - { id }: StopABTestProps, - requestOptions?: RequestOptions - ): Promise { - if (!id) { - throw new Error( - 'Parameter `id` is required when calling `stopABTest`.' - ); - } - - const requestPath = '/2/abtests/{id}/stop'.replace( - '{id}', - encodeURIComponent(id) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type AbtestingApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type DeleteABTestProps = { - /** - * The A/B test ID. - */ - id: number; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetABTestProps = { - /** - * The A/B test ID. - */ - id: number; -}; - -export type ListABTestsProps = { - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type StopABTestProps = { - /** - * The A/B test ID. - */ - id: number; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts b/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts deleted file mode 100644 index 77d5a7e04c..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts +++ /dev/null @@ -1,1799 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { Direction } from '../model/direction'; -import type { GetAverageClickPositionResponse } from '../model/getAverageClickPositionResponse'; -import type { GetClickPositionsResponse } from '../model/getClickPositionsResponse'; -import type { GetClickThroughRateResponse } from '../model/getClickThroughRateResponse'; -import type { GetConversationRateResponse } from '../model/getConversationRateResponse'; -import type { GetNoClickRateResponse } from '../model/getNoClickRateResponse'; -import type { GetNoResultsRateResponse } from '../model/getNoResultsRateResponse'; -import type { GetSearchesCountResponse } from '../model/getSearchesCountResponse'; -import type { GetSearchesNoClicksResponse } from '../model/getSearchesNoClicksResponse'; -import type { GetSearchesNoResultsResponse } from '../model/getSearchesNoResultsResponse'; -import type { GetStatusResponse } from '../model/getStatusResponse'; -import type { GetTopCountriesResponse } from '../model/getTopCountriesResponse'; -import type { GetTopFilterAttributesResponse } from '../model/getTopFilterAttributesResponse'; -import type { GetTopFilterForAttributeResponse } from '../model/getTopFilterForAttributeResponse'; -import type { GetTopFiltersNoResultsResponse } from '../model/getTopFiltersNoResultsResponse'; -import type { GetTopHitsResponse } from '../model/getTopHitsResponse'; -import type { GetTopSearchesResponse } from '../model/getTopSearchesResponse'; -import type { GetUsersCountResponse } from '../model/getUsersCountResponse'; -import type { OrderBy } from '../model/orderBy'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -export type Region = 'de' | 'us'; - -function getDefaultHosts(region?: Region): Host[] { - const regionHost = region ? `.${region}.` : '.'; - - return [ - { - url: `analytics${regionHost}algolia.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createAnalyticsApi( - options: CreateClientOptions & { region?: Region } -) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.region), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Analytics', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the average click position. The endpoint returns a value for the complete given time range, as well as a value per day. - * - * @summary Returns the average click position. - * @param getAverageClickPosition - The getAverageClickPosition object. - * @param getAverageClickPosition.index - The index name to target. - * @param getAverageClickPosition.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getAverageClickPosition.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getAverageClickPosition.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getAverageClickPosition( - { index, startDate, endDate, tags }: GetAverageClickPositionProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getAverageClickPosition`.' - ); - } - - const requestPath = '/2/clicks/averageClickPosition'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the distribution of clicks per range of positions. - * - * @summary Returns the distribution of clicks per range of positions. - * @param getClickPositions - The getClickPositions object. - * @param getClickPositions.index - The index name to target. - * @param getClickPositions.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getClickPositions.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getClickPositions.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getClickPositions( - { index, startDate, endDate, tags }: GetClickPositionsProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getClickPositions`.' - ); - } - - const requestPath = '/2/clicks/positions'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns a click-through rate (CTR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of clicks and searches used to compute the rates. - * - * @summary Returns a click-through rate (CTR). - * @param getClickThroughRate - The getClickThroughRate object. - * @param getClickThroughRate.index - The index name to target. - * @param getClickThroughRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getClickThroughRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getClickThroughRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getClickThroughRate( - { index, startDate, endDate, tags }: GetClickThroughRateProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getClickThroughRate`.' - ); - } - - const requestPath = '/2/clicks/clickThroughRate'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns a conversion rate (CR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of conversion and searches used to compute the rates. - * - * @summary Returns a conversion rate (CR). - * @param getConversationRate - The getConversationRate object. - * @param getConversationRate.index - The index name to target. - * @param getConversationRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getConversationRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getConversationRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getConversationRate( - { index, startDate, endDate, tags }: GetConversationRateProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getConversationRate`.' - ); - } - - const requestPath = '/2/conversions/conversionRate'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the rate at which searches didn\'t lead to any clicks. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without clicks. - * - * @summary Returns the rate at which searches didn\'t lead to any clicks. - * @param getNoClickRate - The getNoClickRate object. - * @param getNoClickRate.index - The index name to target. - * @param getNoClickRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getNoClickRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getNoClickRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getNoClickRate( - { index, startDate, endDate, tags }: GetNoClickRateProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getNoClickRate`.' - ); - } - - const requestPath = '/2/searches/noClickRate'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the rate at which searches didn\'t return any results. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without results used to compute the rates. - * - * @summary Returns the rate at which searches didn\'t return any results. - * @param getNoResultsRate - The getNoResultsRate object. - * @param getNoResultsRate.index - The index name to target. - * @param getNoResultsRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getNoResultsRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getNoResultsRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getNoResultsRate( - { index, startDate, endDate, tags }: GetNoResultsRateProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getNoResultsRate`.' - ); - } - - const requestPath = '/2/searches/noResultRate'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the number of searches across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day. - * - * @summary Returns the number of searches across the given time range. - * @param getSearchesCount - The getSearchesCount object. - * @param getSearchesCount.index - The index name to target. - * @param getSearchesCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getSearchesCount( - { index, startDate, endDate, tags }: GetSearchesCountProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getSearchesCount`.' - ); - } - - const requestPath = '/2/searches/count'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top searches that didn\'t lead to any clicks. Limited to the 1000 most frequent ones. For each search, also returns the average number of found hits. - * - * @summary Returns top searches that didn\'t lead to any clicks. - * @param getSearchesNoClicks - The getSearchesNoClicks object. - * @param getSearchesNoClicks.index - The index name to target. - * @param getSearchesNoClicks.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesNoClicks.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesNoClicks.limit - Number of records to return. Limit is the size of the page. - * @param getSearchesNoClicks.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getSearchesNoClicks.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getSearchesNoClicks( - { - index, - startDate, - endDate, - limit, - offset, - tags, - }: GetSearchesNoClicksProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getSearchesNoClicks`.' - ); - } - - const requestPath = '/2/searches/noClicks'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top searches that didn\'t return any results. Limited to the 1000 most frequent ones. - * - * @summary Returns top searches that didn\'t return any results. - * @param getSearchesNoResults - The getSearchesNoResults object. - * @param getSearchesNoResults.index - The index name to target. - * @param getSearchesNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getSearchesNoResults.limit - Number of records to return. Limit is the size of the page. - * @param getSearchesNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getSearchesNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getSearchesNoResults( - { - index, - startDate, - endDate, - limit, - offset, - tags, - }: GetSearchesNoResultsProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getSearchesNoResults`.' - ); - } - - const requestPath = '/2/searches/noResults'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the latest update time of the analytics API for a given index. If the index has been recently created and/or no search has been performed yet the updated time will be null. - * - * @summary Get latest update time of the analytics API. - * @param getStatus - The getStatus object. - * @param getStatus.index - The index name to target. - */ - getStatus( - { index }: GetStatusProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getStatus`.' - ); - } - - const requestPath = '/2/status'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top countries. Limited to the 1000 most frequent ones. - * - * @summary Returns top countries. - * @param getTopCountries - The getTopCountries object. - * @param getTopCountries.index - The index name to target. - * @param getTopCountries.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopCountries.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopCountries.limit - Number of records to return. Limit is the size of the page. - * @param getTopCountries.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopCountries.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopCountries( - { index, startDate, endDate, limit, offset, tags }: GetTopCountriesProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopCountries`.' - ); - } - - const requestPath = '/2/countries'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top filter attributes. Limited to the 1000 most used filters. - * - * @summary Returns top filter attributes. - * @param getTopFilterAttributes - The getTopFilterAttributes object. - * @param getTopFilterAttributes.index - The index name to target. - * @param getTopFilterAttributes.search - The query term to search for. Must match the exact user input. - * @param getTopFilterAttributes.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterAttributes.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterAttributes.limit - Number of records to return. Limit is the size of the page. - * @param getTopFilterAttributes.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopFilterAttributes.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFilterAttributes( - { - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFilterAttributesProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopFilterAttributes`.' - ); - } - - const requestPath = '/2/filters'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (search !== undefined) { - queryParameters.search = search.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top filters for the given attribute. Limited to the 1000 most used filters. - * - * @summary Returns top filters for the given attribute. - * @param getTopFilterForAttribute - The getTopFilterForAttribute object. - * @param getTopFilterForAttribute.attribute - The exact name of the attribute. - * @param getTopFilterForAttribute.index - The index name to target. - * @param getTopFilterForAttribute.search - The query term to search for. Must match the exact user input. - * @param getTopFilterForAttribute.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterForAttribute.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterForAttribute.limit - Number of records to return. Limit is the size of the page. - * @param getTopFilterForAttribute.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopFilterForAttribute.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFilterForAttribute( - { - attribute, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFilterForAttributeProps, - requestOptions?: RequestOptions - ): Promise { - if (!attribute) { - throw new Error( - 'Parameter `attribute` is required when calling `getTopFilterForAttribute`.' - ); - } - - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopFilterForAttribute`.' - ); - } - - const requestPath = '/2/filters/{attribute}'.replace( - '{attribute}', - encodeURIComponent(attribute) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (search !== undefined) { - queryParameters.search = search.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top filters with no results. Limited to the 1000 most used filters. - * - * @summary Returns top filters with no results. - * @param getTopFiltersNoResults - The getTopFiltersNoResults object. - * @param getTopFiltersNoResults.index - The index name to target. - * @param getTopFiltersNoResults.search - The query term to search for. Must match the exact user input. - * @param getTopFiltersNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersNoResults.limit - Number of records to return. Limit is the size of the page. - * @param getTopFiltersNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopFiltersNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFiltersNoResults( - { - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFiltersNoResultsProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopFiltersNoResults`.' - ); - } - - const requestPath = '/2/filters/noResults'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (search !== undefined) { - queryParameters.search = search.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top hits. Limited to the 1000 most frequent ones. - * - * @summary Returns top hits. - * @param getTopHits - The getTopHits object. - * @param getTopHits.index - The index name to target. - * @param getTopHits.search - The query term to search for. Must match the exact user input. - * @param getTopHits.clickAnalytics - Whether to include the click-through and conversion rates for a search. - * @param getTopHits.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopHits.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopHits.limit - Number of records to return. Limit is the size of the page. - * @param getTopHits.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopHits.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopHits( - { - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopHitsProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopHits`.' - ); - } - - const requestPath = '/2/hits'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (search !== undefined) { - queryParameters.search = search.toString(); - } - - if (clickAnalytics !== undefined) { - queryParameters.clickAnalytics = clickAnalytics.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns top searches. Limited to the 1000 most frequent ones. For each search, also returns the average number of hits returned. - * - * @summary Returns top searches. - * @param getTopSearches - The getTopSearches object. - * @param getTopSearches.index - The index name to target. - * @param getTopSearches.clickAnalytics - Whether to include the click-through and conversion rates for a search. - * @param getTopSearches.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopSearches.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopSearches.orderBy - Reorder the results. - * @param getTopSearches.direction - The sorting of the result. - * @param getTopSearches.limit - Number of records to return. Limit is the size of the page. - * @param getTopSearches.offset - Position of the starting record. Used for paging. 0 is the first record. - * @param getTopSearches.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopSearches( - { - index, - clickAnalytics, - startDate, - endDate, - orderBy, - direction, - limit, - offset, - tags, - }: GetTopSearchesProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getTopSearches`.' - ); - } - - const requestPath = '/2/searches'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (clickAnalytics !== undefined) { - queryParameters.clickAnalytics = clickAnalytics.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (orderBy !== undefined) { - queryParameters.orderBy = orderBy.toString(); - } - - if (direction !== undefined) { - queryParameters.direction = direction.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the distinct count of users across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day. - * - * @summary Returns the distinct count of users across the given time range. - * @param getUsersCount - The getUsersCount object. - * @param getUsersCount.index - The index name to target. - * @param getUsersCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getUsersCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getUsersCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getUsersCount( - { index, startDate, endDate, tags }: GetUsersCountProps, - requestOptions?: RequestOptions - ): Promise { - if (!index) { - throw new Error( - 'Parameter `index` is required when calling `getUsersCount`.' - ); - } - - const requestPath = '/2/users/count'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (index !== undefined) { - queryParameters.index = index.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type AnalyticsApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetAverageClickPositionProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetClickPositionsProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetClickThroughRateProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetConversationRateProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetNoClickRateProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetNoResultsRateProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetSearchesCountProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetSearchesNoClicksProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetSearchesNoResultsProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetStatusProps = { - /** - * The index name to target. - */ - index: string; -}; - -export type GetTopCountriesProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFilterAttributesProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term to search for. Must match the exact user input. - */ - search?: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFilterForAttributeProps = { - /** - * The exact name of the attribute. - */ - attribute: string; - /** - * The index name to target. - */ - index: string; - /** - * The query term to search for. Must match the exact user input. - */ - search?: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFiltersNoResultsProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term to search for. Must match the exact user input. - */ - search?: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopHitsProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term to search for. Must match the exact user input. - */ - search?: string; - /** - * Whether to include the click-through and conversion rates for a search. - */ - clickAnalytics?: boolean; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopSearchesProps = { - /** - * The index name to target. - */ - index: string; - /** - * Whether to include the click-through and conversion rates for a search. - */ - clickAnalytics?: boolean; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Reorder the results. - */ - orderBy?: OrderBy; - /** - * The sorting of the result. - */ - direction?: Direction; - /** - * Number of records to return. Limit is the size of the page. - */ - limit?: number; - /** - * Position of the starting record. Used for paging. 0 is the first record. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetUsersCountProps = { - /** - * The index name to target. - */ - index: string; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: string; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: string; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts b/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts deleted file mode 100644 index ae999a5043..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts +++ /dev/null @@ -1,305 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { InsightEvents } from '../model/insightEvents'; -import type { PushEventsResponse } from '../model/pushEventsResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -export type Region = 'de' | 'us'; - -function getDefaultHosts(region?: Region): Host[] { - const regionHost = region ? `.${region}.` : '.'; - - return [ - { - url: `insights${regionHost}algolia.io`, - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createInsightsApi( - options: CreateClientOptions & { region?: Region } -) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.region), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Insights', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This command pushes an array of events. - * - * @summary Pushes an array of events. - * @param insightEvents - The insightEvents object. - */ - pushEvents( - insightEvents: InsightEvents, - requestOptions?: RequestOptions - ): Promise { - if (!insightEvents) { - throw new Error( - 'Parameter `insightEvents` is required when calling `pushEvents`.' - ); - } - - if (!insightEvents.events) { - throw new Error( - 'Parameter `insightEvents.events` is required when calling `pushEvents`.' - ); - } - - const requestPath = '/1/events'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: insightEvents, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type InsightsApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts b/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts deleted file mode 100644 index 588889af0d..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts +++ /dev/null @@ -1,434 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { DeleteUserProfileResponse } from '../model/deleteUserProfileResponse'; -import type { GetUserTokenResponse } from '../model/getUserTokenResponse'; -import type { PersonalizationStrategyParams } from '../model/personalizationStrategyParams'; -import type { SetPersonalizationStrategyResponse } from '../model/setPersonalizationStrategyResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -export type Region = 'eu' | 'us'; - -function getDefaultHosts(region: Region): Host[] { - return [ - { - url: `personalization.${region}.algolia.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createPersonalizationApi( - options: CreateClientOptions & { region: Region } -) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.region), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Personalization', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns, as part of the response, a date until which the data can safely be considered as deleted for the given user. This means that if you send events for the given user before this date, they will be ignored. Any data received after the deletedUntil date will start building a new user profile. It might take a couple hours before for the deletion request to be fully processed. - * - * @summary Delete the user profile and all its associated data. - * @param deleteUserProfile - The deleteUserProfile object. - * @param deleteUserProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. - */ - deleteUserProfile( - { userToken }: DeleteUserProfileProps, - requestOptions?: RequestOptions - ): Promise { - if (!userToken) { - throw new Error( - 'Parameter `userToken` is required when calling `deleteUserProfile`.' - ); - } - - const requestPath = '/1/profiles/{userToken}'.replace( - '{userToken}', - encodeURIComponent(userToken) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * The strategy contains information on the events and facets that impact user profiles and personalized search results. - * - * @summary Get the current personalization strategy. - */ - getPersonalizationStrategy( - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/strategies/personalization'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * The profile is structured by facet name used in the strategy. Each facet value is mapped to its score. Each score represents the user affinity for a specific facet value given the userToken past events and the Personalization strategy defined. Scores are bounded to 20. The last processed event timestamp is provided using the ISO 8601 format for debugging purposes. - * - * @summary Get the user profile built from Personalization strategy. - * @param getUserTokenProfile - The getUserTokenProfile object. - * @param getUserTokenProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. - */ - getUserTokenProfile( - { userToken }: GetUserTokenProfileProps, - requestOptions?: RequestOptions - ): Promise { - if (!userToken) { - throw new Error( - 'Parameter `userToken` is required when calling `getUserTokenProfile`.' - ); - } - - const requestPath = '/1/profiles/personalization/{userToken}'.replace( - '{userToken}', - encodeURIComponent(userToken) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * A strategy defines the events and facets that impact user profiles and personalized search results. - * - * @summary Set a new personalization strategy. - * @param personalizationStrategyParams - The personalizationStrategyParams object. - */ - setPersonalizationStrategy( - personalizationStrategyParams: PersonalizationStrategyParams, - requestOptions?: RequestOptions - ): Promise { - if (!personalizationStrategyParams) { - throw new Error( - 'Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.' - ); - } - - if (!personalizationStrategyParams.eventScoring) { - throw new Error( - 'Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.' - ); - } - if (!personalizationStrategyParams.facetScoring) { - throw new Error( - 'Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.' - ); - } - if (!personalizationStrategyParams.personalizationImpact) { - throw new Error( - 'Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.' - ); - } - - const requestPath = '/1/strategies/personalization'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: personalizationStrategyParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type PersonalizationApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type DeleteUserProfileProps = { - /** - * UserToken representing the user for which to fetch the Personalization profile. - */ - userToken: string; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetUserTokenProfileProps = { - /** - * UserToken representing the user for which to fetch the Personalization profile. - */ - userToken: string; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts deleted file mode 100644 index ca2946d3b4..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts +++ /dev/null @@ -1,312 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; -import type { Params } from '../model/params'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -function getDefaultHosts(): Host[] { - return [ - { - url: 'predict-api-oslcbws3zq-ew.a.run.app', - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createPredictApi(options: CreateClientOptions) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Predict', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile. - * - * @summary Get user profile. - * @param fetchUserProfile - The fetchUserProfile object. - * @param fetchUserProfile.userID - User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). - * @param fetchUserProfile.params - The params object. - */ - fetchUserProfile( - { userID, params }: FetchUserProfileProps, - requestOptions?: RequestOptions - ): Promise { - if (!userID) { - throw new Error( - 'Parameter `userID` is required when calling `fetchUserProfile`.' - ); - } - - if (!params) { - throw new Error( - 'Parameter `params` is required when calling `fetchUserProfile`.' - ); - } - - const requestPath = '/1/users/{userID}/fetch'.replace( - '{userID}', - encodeURIComponent(userID) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: params, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type PredictApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type FetchUserProfileProps = { - /** - * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). - */ - userID: string; - params: Params; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts deleted file mode 100644 index 63033fe47d..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts +++ /dev/null @@ -1,573 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { LogFile } from '../model/logFile'; -import type { QuerySuggestionsIndex } from '../model/querySuggestionsIndex'; -import type { QuerySuggestionsIndexParam } from '../model/querySuggestionsIndexParam'; -import type { QuerySuggestionsIndexWithIndexParam } from '../model/querySuggestionsIndexWithIndexParam'; -import type { Status } from '../model/status'; -import type { SucessResponse } from '../model/sucessResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -export type Region = 'eu' | 'us'; - -function getDefaultHosts(region: Region): Host[] { - return [ - { - url: `query-suggestions.${region}.algolia.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]; -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createQuerySuggestionsApi( - options: CreateClientOptions & { region: Region } -) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.region), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'QuerySuggestions', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * Create a configuration of a Query Suggestions index. There\'s a limit of 100 configurations per application. - * - * @summary Create a configuration of a Query Suggestions index. - * @param querySuggestionsIndexWithIndexParam - The querySuggestionsIndexWithIndexParam object. - */ - createConfig( - querySuggestionsIndexWithIndexParam: QuerySuggestionsIndexWithIndexParam, - requestOptions?: RequestOptions - ): Promise { - if (!querySuggestionsIndexWithIndexParam) { - throw new Error( - 'Parameter `querySuggestionsIndexWithIndexParam` is required when calling `createConfig`.' - ); - } - - const requestPath = '/1/configs'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: querySuggestionsIndexWithIndexParam, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete a configuration of a Query Suggestion\'s index. By deleting a configuraton, you stop all updates to the underlying query suggestion index. Note that when doing this, the underlying index does not change - existing suggestions remain untouched. - * - * @summary Delete a configuration of a Query Suggestion\'s index. - * @param deleteConfig - The deleteConfig object. - * @param deleteConfig.indexName - The index in which to perform the request. - */ - deleteConfig( - { indexName }: DeleteConfigProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteConfig`.' - ); - } - - const requestPath = '/1/configs/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get all the configurations of Query Suggestions. For each index, you get a block of JSON with a list of its configuration settings. - * - * @summary Get all the configurations of Query Suggestions. - */ - getAllConfigs( - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/configs'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the configuration of a single Query Suggestions index. - * - * @summary Get the configuration of a single Query Suggestions index. - * @param getConfig - The getConfig object. - * @param getConfig.indexName - The index in which to perform the request. - */ - getConfig( - { indexName }: GetConfigProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getConfig`.' - ); - } - - const requestPath = '/1/configs/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the status of a Query Suggestion\'s index. The status includes whether the Query Suggestions index is currently in the process of being built, and the last build time. - * - * @summary Get the status of a Query Suggestion\'s index. - * @param getConfigStatus - The getConfigStatus object. - * @param getConfigStatus.indexName - The index in which to perform the request. - */ - getConfigStatus( - { indexName }: GetConfigStatusProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getConfigStatus`.' - ); - } - - const requestPath = '/1/configs/{indexName}/status'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the log file of the last build of a single Query Suggestion index. - * - * @summary Get the log file of the last build of a single Query Suggestion index. - * @param getLogFile - The getLogFile object. - * @param getLogFile.indexName - The index in which to perform the request. - */ - getLogFile( - { indexName }: GetLogFileProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getLogFile`.' - ); - } - - const requestPath = '/1/logs/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Update the configuration of a Query Suggestions index. - * - * @summary Update the configuration of a Query Suggestions index. - * @param updateConfig - The updateConfig object. - * @param updateConfig.indexName - The index in which to perform the request. - * @param updateConfig.querySuggestionsIndexParam - The querySuggestionsIndexParam object. - */ - updateConfig( - { indexName, querySuggestionsIndexParam }: UpdateConfigProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `updateConfig`.' - ); - } - - if (!querySuggestionsIndexParam) { - throw new Error( - 'Parameter `querySuggestionsIndexParam` is required when calling `updateConfig`.' - ); - } - - if (!querySuggestionsIndexParam.sourceIndices) { - throw new Error( - 'Parameter `querySuggestionsIndexParam.sourceIndices` is required when calling `updateConfig`.' - ); - } - - const requestPath = '/1/configs/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: querySuggestionsIndexParam, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type QuerySuggestionsApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type DeleteConfigProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetConfigProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type GetConfigStatusProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type GetLogFileProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type UpdateConfigProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - querySuggestionsIndexParam: QuerySuggestionsIndexParam; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts b/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts deleted file mode 100644 index bf0da9ac02..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts +++ /dev/null @@ -1,3354 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, - shuffle, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { AddApiKeyResponse } from '../model/addApiKeyResponse'; -import type { ApiKey } from '../model/apiKey'; -import type { AssignUserIdParams } from '../model/assignUserIdParams'; -import type { AttributeOrBuiltInOperation } from '../model/attributeOrBuiltInOperation'; -import type { BatchAssignUserIdsParams } from '../model/batchAssignUserIdsParams'; -import type { BatchDictionaryEntriesParams } from '../model/batchDictionaryEntriesParams'; -import type { BatchParams } from '../model/batchParams'; -import type { BatchResponse } from '../model/batchResponse'; -import type { BatchWriteParams } from '../model/batchWriteParams'; -import type { BrowseRequest } from '../model/browseRequest'; -import type { BrowseResponse } from '../model/browseResponse'; -import type { CreatedAtResponse } from '../model/createdAtResponse'; -import type { DeleteApiKeyResponse } from '../model/deleteApiKeyResponse'; -import type { DeleteSourceResponse } from '../model/deleteSourceResponse'; -import type { DeletedAtResponse } from '../model/deletedAtResponse'; -import type { DictionarySettingsParams } from '../model/dictionarySettingsParams'; -import type { DictionaryType } from '../model/dictionaryType'; -import type { GetDictionarySettingsResponse } from '../model/getDictionarySettingsResponse'; -import type { GetLogsResponse } from '../model/getLogsResponse'; -import type { GetObjectsParams } from '../model/getObjectsParams'; -import type { GetObjectsResponse } from '../model/getObjectsResponse'; -import type { GetTaskResponse } from '../model/getTaskResponse'; -import type { GetTopUserIdsResponse } from '../model/getTopUserIdsResponse'; -import type { IndexSettings } from '../model/indexSettings'; -import type { Key } from '../model/key'; -import type { Languages } from '../model/languages'; -import type { ListApiKeysResponse } from '../model/listApiKeysResponse'; -import type { ListClustersResponse } from '../model/listClustersResponse'; -import type { ListIndicesResponse } from '../model/listIndicesResponse'; -import type { ListUserIdsResponse } from '../model/listUserIdsResponse'; -import type { LogType } from '../model/logType'; -import type { MultipleBatchResponse } from '../model/multipleBatchResponse'; -import type { MultipleQueriesParams } from '../model/multipleQueriesParams'; -import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; -import type { OperationIndexParams } from '../model/operationIndexParams'; -import type { RemoveUserIdResponse } from '../model/removeUserIdResponse'; -import type { ReplaceSourceResponse } from '../model/replaceSourceResponse'; -import type { Rule } from '../model/rule'; -import type { SaveObjectResponse } from '../model/saveObjectResponse'; -import type { SaveSynonymResponse } from '../model/saveSynonymResponse'; -import type { SearchDictionaryEntriesParams } from '../model/searchDictionaryEntriesParams'; -import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest'; -import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse'; -import type { SearchParams } from '../model/searchParams'; -import type { SearchResponse } from '../model/searchResponse'; -import type { SearchRulesParams } from '../model/searchRulesParams'; -import type { SearchRulesResponse } from '../model/searchRulesResponse'; -import type { SearchSynonymsResponse } from '../model/searchSynonymsResponse'; -import type { SearchUserIdsParams } from '../model/searchUserIdsParams'; -import type { SearchUserIdsResponse } from '../model/searchUserIdsResponse'; -import type { Source } from '../model/source'; -import type { SynonymHit } from '../model/synonymHit'; -import type { SynonymType } from '../model/synonymType'; -import type { UpdateApiKeyResponse } from '../model/updateApiKeyResponse'; -import type { UpdatedAtResponse } from '../model/updatedAtResponse'; -import type { UpdatedAtWithObjectIdResponse } from '../model/updatedAtWithObjectIdResponse'; -import type { UpdatedRuleResponse } from '../model/updatedRuleResponse'; -import type { UserId } from '../model/userId'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -function getDefaultHosts(appId: string): Host[] { - return ( - [ - { - url: `${appId}-dsn.algolia.net`, - accept: 'read', - protocol: 'https', - }, - { - url: `${appId}.algolia.net`, - accept: 'write', - protocol: 'https', - }, - ] as Host[] - ).concat( - shuffle([ - { - url: `${appId}-1.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-2.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-3.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]) - ); -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createSearchApi(options: CreateClientOptions) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.appId), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Search', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * Add a new API Key with specific permissions/restrictions. - * - * @summary Create a new API key. - * @param apiKey - The apiKey object. - */ - addApiKey( - apiKey: ApiKey, - requestOptions?: RequestOptions - ): Promise { - if (!apiKey) { - throw new Error( - 'Parameter `apiKey` is required when calling `addApiKey`.' - ); - } - - if (!apiKey.acl) { - throw new Error( - 'Parameter `apiKey.acl` is required when calling `addApiKey`.' - ); - } - - const requestPath = '/1/keys'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: apiKey, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Add or replace an object with a given object ID. If the object does not exist, it will be created. If it already exists, it will be replaced. - * - * @summary Add or replace an object with a given object ID. - * @param addOrUpdateObject - The addOrUpdateObject object. - * @param addOrUpdateObject.indexName - The index in which to perform the request. - * @param addOrUpdateObject.objectID - Unique identifier of an object. - * @param addOrUpdateObject.body - The Algolia object. - */ - addOrUpdateObject( - { indexName, objectID, body }: AddOrUpdateObjectProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `addOrUpdateObject`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `addOrUpdateObject`.' - ); - } - - if (!body) { - throw new Error( - 'Parameter `body` is required when calling `addOrUpdateObject`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Add a single source to the list of allowed sources. - * - * @summary Add a single source. - * @param source - The source to add. - */ - appendSource( - source: Source, - requestOptions?: RequestOptions - ): Promise { - if (!source) { - throw new Error( - 'Parameter `source` is required when calling `appendSource`.' - ); - } - - const requestPath = '/1/security/sources/append'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: source, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Assign or Move a userID to a cluster. The time it takes to migrate (move) a user is proportional to the amount of data linked to the userID. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userID is directly usable. - * - * @summary Assign or Move userID. - * @param assignUserId - The assignUserId object. - * @param assignUserId.xAlgoliaUserID - UserID to assign. - * @param assignUserId.assignUserIdParams - The assignUserIdParams object. - */ - assignUserId( - { xAlgoliaUserID, assignUserIdParams }: AssignUserIdProps, - requestOptions?: RequestOptions - ): Promise { - if (!xAlgoliaUserID) { - throw new Error( - 'Parameter `xAlgoliaUserID` is required when calling `assignUserId`.' - ); - } - - if (!assignUserIdParams) { - throw new Error( - 'Parameter `assignUserIdParams` is required when calling `assignUserId`.' - ); - } - - if (!assignUserIdParams.cluster) { - throw new Error( - 'Parameter `assignUserIdParams.cluster` is required when calling `assignUserId`.' - ); - } - - const requestPath = '/1/clusters/mapping'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (xAlgoliaUserID !== undefined) { - queryParameters['X-Algolia-User-ID'] = xAlgoliaUserID.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - data: assignUserIdParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Performs multiple write operations in a single API call. - * - * @summary Performs multiple write operations in a single API call. - * @param batch - The batch object. - * @param batch.indexName - The index in which to perform the request. - * @param batch.batchWriteParams - The batchWriteParams object. - */ - batch( - { indexName, batchWriteParams }: BatchProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `batch`.' - ); - } - - if (!batchWriteParams) { - throw new Error( - 'Parameter `batchWriteParams` is required when calling `batch`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/batch'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: batchWriteParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userIDs are directly usable. - * - * @summary Batch assign userIDs. - * @param batchAssignUserIds - The batchAssignUserIds object. - * @param batchAssignUserIds.xAlgoliaUserID - UserID to assign. - * @param batchAssignUserIds.batchAssignUserIdsParams - The batchAssignUserIdsParams object. - */ - batchAssignUserIds( - { xAlgoliaUserID, batchAssignUserIdsParams }: BatchAssignUserIdsProps, - requestOptions?: RequestOptions - ): Promise { - if (!xAlgoliaUserID) { - throw new Error( - 'Parameter `xAlgoliaUserID` is required when calling `batchAssignUserIds`.' - ); - } - - if (!batchAssignUserIdsParams) { - throw new Error( - 'Parameter `batchAssignUserIdsParams` is required when calling `batchAssignUserIds`.' - ); - } - - if (!batchAssignUserIdsParams.cluster) { - throw new Error( - 'Parameter `batchAssignUserIdsParams.cluster` is required when calling `batchAssignUserIds`.' - ); - } - if (!batchAssignUserIdsParams.users) { - throw new Error( - 'Parameter `batchAssignUserIdsParams.users` is required when calling `batchAssignUserIds`.' - ); - } - - const requestPath = '/1/clusters/mapping/batch'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (xAlgoliaUserID !== undefined) { - queryParameters['X-Algolia-User-ID'] = xAlgoliaUserID.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - data: batchAssignUserIdsParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Send a batch of dictionary entries. - * - * @summary Send a batch of dictionary entries. - * @param batchDictionaryEntries - The batchDictionaryEntries object. - * @param batchDictionaryEntries.dictionaryName - The dictionary to search in. - * @param batchDictionaryEntries.batchDictionaryEntriesParams - The batchDictionaryEntriesParams object. - */ - batchDictionaryEntries( - { - dictionaryName, - batchDictionaryEntriesParams, - }: BatchDictionaryEntriesProps, - requestOptions?: RequestOptions - ): Promise { - if (!dictionaryName) { - throw new Error( - 'Parameter `dictionaryName` is required when calling `batchDictionaryEntries`.' - ); - } - - if (!batchDictionaryEntriesParams) { - throw new Error( - 'Parameter `batchDictionaryEntriesParams` is required when calling `batchDictionaryEntries`.' - ); - } - - if (!batchDictionaryEntriesParams.requests) { - throw new Error( - 'Parameter `batchDictionaryEntriesParams.requests` is required when calling `batchDictionaryEntries`.' - ); - } - - const requestPath = '/1/dictionaries/{dictionaryName}/batch'.replace( - '{dictionaryName}', - encodeURIComponent(dictionaryName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: batchDictionaryEntriesParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Create or update a batch of Rules. - * - * @summary Batch Rules. - * @param batchRules - The batchRules object. - * @param batchRules.indexName - The index in which to perform the request. - * @param batchRules.rule - The rule object. - * @param batchRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - * @param batchRules.clearExistingRules - When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. - */ - batchRules( - { - indexName, - rule, - forwardToReplicas, - clearExistingRules, - }: BatchRulesProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `batchRules`.' - ); - } - - if (!rule) { - throw new Error( - 'Parameter `rule` is required when calling `batchRules`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/batch'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - if (clearExistingRules !== undefined) { - queryParameters.clearExistingRules = clearExistingRules.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - data: rule, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allows you to retrieve all index content. It can retrieve up to 1,000 records per call and supports full text search and filters. For performance reasons, some features are not supported, including `distinct`, sorting by `typos`, `words` or `geo distance`. When there is more content to be browsed, the response contains a cursor field. This cursor has to be passed to the subsequent call to browse in order to get the next page of results. When the end of the index has been reached, the cursor field is absent from the response. - * - * @summary Retrieve all index content. - * @param browse - The browse object. - * @param browse.indexName - The index in which to perform the request. - * @param browse.browseRequest - The browseRequest object. - */ - browse( - { indexName, browseRequest }: BrowseProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `browse`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/browse'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: browseRequest, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Remove all synonyms from an index. - * - * @summary Clear all synonyms. - * @param clearAllSynonyms - The clearAllSynonyms object. - * @param clearAllSynonyms.indexName - The index in which to perform the request. - * @param clearAllSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - clearAllSynonyms( - { indexName, forwardToReplicas }: ClearAllSynonymsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `clearAllSynonyms`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/clear'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete an index\'s content, but leave settings and index-specific API keys untouched. - * - * @summary Clear all objects from an index. - * @param clearObjects - The clearObjects object. - * @param clearObjects.indexName - The index in which to perform the request. - */ - clearObjects( - { indexName }: ClearObjectsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `clearObjects`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/clear'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete all Rules in the index. - * - * @summary Clear Rules. - * @param clearRules - The clearRules object. - * @param clearRules.indexName - The index in which to perform the request. - * @param clearRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - clearRules( - { indexName, forwardToReplicas }: ClearRulesProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `clearRules`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/clear'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete an existing API Key. - * - * @summary Delete an API key. - * @param deleteApiKey - The deleteApiKey object. - * @param deleteApiKey.key - API Key string. - */ - deleteApiKey( - { key }: DeleteApiKeyProps, - requestOptions?: RequestOptions - ): Promise { - if (!key) { - throw new Error( - 'Parameter `key` is required when calling `deleteApiKey`.' - ); - } - - const requestPath = '/1/keys/{key}'.replace( - '{key}', - encodeURIComponent(key) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Remove all objects matching a filter (including geo filters). This method enables you to delete one or more objects based on filters (numeric, facet, tag or geo queries). It doesn\'t accept empty filters or a query. - * - * @summary Delete all records matching the query. - * @param deleteBy - The deleteBy object. - * @param deleteBy.indexName - The index in which to perform the request. - * @param deleteBy.searchParams - The searchParams object. - */ - deleteBy( - { indexName, searchParams }: DeleteByProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteBy`.' - ); - } - - if (!searchParams) { - throw new Error( - 'Parameter `searchParams` is required when calling `deleteBy`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/deleteByQuery'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete an existing index. - * - * @summary Delete index. - * @param deleteIndex - The deleteIndex object. - * @param deleteIndex.indexName - The index in which to perform the request. - */ - deleteIndex( - { indexName }: DeleteIndexProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteIndex`.' - ); - } - - const requestPath = '/1/indexes/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete an existing object. - * - * @summary Delete object. - * @param deleteObject - The deleteObject object. - * @param deleteObject.indexName - The index in which to perform the request. - * @param deleteObject.objectID - Unique identifier of an object. - */ - deleteObject( - { indexName, objectID }: DeleteObjectProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteObject`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `deleteObject`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete the Rule with the specified objectID. - * - * @summary Delete a rule. - * @param deleteRule - The deleteRule object. - * @param deleteRule.indexName - The index in which to perform the request. - * @param deleteRule.objectID - Unique identifier of an object. - * @param deleteRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - deleteRule( - { indexName, objectID, forwardToReplicas }: DeleteRuleProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteRule`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `deleteRule`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Remove a single source from the list of allowed sources. - * - * @summary Remove a single source. - * @param deleteSource - The deleteSource object. - * @param deleteSource.source - The IP range of the source. - */ - deleteSource( - { source }: DeleteSourceProps, - requestOptions?: RequestOptions - ): Promise { - if (!source) { - throw new Error( - 'Parameter `source` is required when calling `deleteSource`.' - ); - } - - const requestPath = '/1/security/sources/{source}'.replace( - '{source}', - encodeURIComponent(source) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Delete a single synonyms set, identified by the given objectID. - * - * @summary Delete synonym. - * @param deleteSynonym - The deleteSynonym object. - * @param deleteSynonym.indexName - The index in which to perform the request. - * @param deleteSynonym.objectID - Unique identifier of an object. - * @param deleteSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - deleteSynonym( - { indexName, objectID, forwardToReplicas }: DeleteSynonymProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `deleteSynonym`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `deleteSynonym`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the permissions of an API key. - * - * @summary Get an API key. - * @param getApiKey - The getApiKey object. - * @param getApiKey.key - API Key string. - */ - getApiKey( - { key }: GetApiKeyProps, - requestOptions?: RequestOptions - ): Promise { - if (!key) { - throw new Error( - 'Parameter `key` is required when calling `getApiKey`.' - ); - } - - const requestPath = '/1/keys/{key}'.replace( - '{key}', - encodeURIComponent(key) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List dictionaries supported per language. - * - * @summary List dictionaries supported per language. - */ - getDictionaryLanguages( - requestOptions?: RequestOptions - ): Promise<{ [key: string]: Languages }> { - const requestPath = '/1/dictionaries/*/languages'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Retrieve dictionaries settings. - * - * @summary Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values. - */ - getDictionarySettings( - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/dictionaries/*/settings'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Return the lastest log entries. - * - * @summary Return the lastest log entries. - * @param getLogs - The getLogs object. - * @param getLogs.offset - First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. - * @param getLogs.length - Maximum number of entries to retrieve. The maximum allowed value is 1000. - * @param getLogs.indexName - Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. - * @param getLogs.type - Type of log entries to retrieve. When omitted, all log entries are retrieved. - */ - getLogs( - { offset, length, indexName, type }: GetLogsProps, - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/logs'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (length !== undefined) { - queryParameters.length = length.toString(); - } - - if (indexName !== undefined) { - queryParameters.indexName = indexName.toString(); - } - - if (type !== undefined) { - queryParameters.type = type.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Retrieve one object from the index. - * - * @summary Retrieve one object from the index. - * @param getObject - The getObject object. - * @param getObject.indexName - The index in which to perform the request. - * @param getObject.objectID - Unique identifier of an object. - * @param getObject.attributesToRetrieve - List of attributes to retrieve. If not specified, all retrievable attributes are returned. - */ - getObject( - { indexName, objectID, attributesToRetrieve }: GetObjectProps, - requestOptions?: RequestOptions - ): Promise<{ [key: string]: string }> { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getObject`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `getObject`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (attributesToRetrieve !== undefined) { - queryParameters.attributesToRetrieve = attributesToRetrieve.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Retrieve one or more objects, potentially from different indices, in a single API call. - * - * @summary Retrieve one or more objects. - * @param getObjectsParams - The getObjectsParams object. - */ - getObjects( - getObjectsParams: GetObjectsParams, - requestOptions?: RequestOptions - ): Promise { - if (!getObjectsParams) { - throw new Error( - 'Parameter `getObjectsParams` is required when calling `getObjects`.' - ); - } - - const requestPath = '/1/indexes/*/objects'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: getObjectsParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Retrieve the Rule with the specified objectID. - * - * @summary Get a rule. - * @param getRule - The getRule object. - * @param getRule.indexName - The index in which to perform the request. - * @param getRule.objectID - Unique identifier of an object. - */ - getRule( - { indexName, objectID }: GetRuleProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getRule`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `getRule`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Retrieve settings of a given indexName. - * - * @summary Retrieve settings of a given indexName. - * @param getSettings - The getSettings object. - * @param getSettings.indexName - The index in which to perform the request. - */ - getSettings( - { indexName }: GetSettingsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getSettings`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/settings'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List all allowed sources. - * - * @summary List all allowed sources. - */ - getSources(requestOptions?: RequestOptions): Promise { - const requestPath = '/1/security/sources'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Fetch a synonym object identified by its objectID. - * - * @summary Get synonym. - * @param getSynonym - The getSynonym object. - * @param getSynonym.indexName - The index in which to perform the request. - * @param getSynonym.objectID - Unique identifier of an object. - */ - getSynonym( - { indexName, objectID }: GetSynonymProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getSynonym`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `getSynonym`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Check the current status of a given task. - * - * @summary Check the current status of a given task. - * @param getTask - The getTask object. - * @param getTask.indexName - The index in which to perform the request. - * @param getTask.taskID - Unique identifier of an task. Numeric value (up to 64bits). - */ - getTask( - { indexName, taskID }: GetTaskProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `getTask`.' - ); - } - - if (!taskID) { - throw new Error( - 'Parameter `taskID` is required when calling `getTask`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/task/{taskID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{taskID}', encodeURIComponent(taskID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the top 10 userIDs with the highest number of records per cluster. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following array of userIDs and clusters. - * - * @summary Get top userID. - */ - getTopUserIds( - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/clusters/mapping/top'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns the userID data stored in the mapping. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following userID data. - * - * @summary Get userID. - * @param getUserId - The getUserId object. - * @param getUserId.userID - UserID to assign. - */ - getUserId( - { userID }: GetUserIdProps, - requestOptions?: RequestOptions - ): Promise { - if (!userID) { - throw new Error( - 'Parameter `userID` is required when calling `getUserId`.' - ); - } - - const requestPath = '/1/clusters/mapping/{userID}'.replace( - '{userID}', - encodeURIComponent(userID) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get the status of your clusters\' migrations or user creations. Creating a large batch of users or migrating your multi-cluster may take quite some time. This method lets you retrieve the status of the migration, so you can know when it\'s done. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userIDs are directly usable. - * - * @summary Has pending mappings. - * @param hasPendingMappings - The hasPendingMappings object. - * @param hasPendingMappings.getClusters - Whether to get clusters or not. - */ - hasPendingMappings( - { getClusters }: HasPendingMappingsProps, - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/clusters/mapping/pending'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (getClusters !== undefined) { - queryParameters.getClusters = getClusters.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List API keys, along with their associated rights. - * - * @summary Get the full list of API Keys. - */ - listApiKeys(requestOptions?: RequestOptions): Promise { - const requestPath = '/1/keys'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List the clusters available in a multi-clusters setup for a single appID. Upon success, the response is 200 OK and contains the following clusters. - * - * @summary List clusters. - */ - listClusters( - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/clusters'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List existing indexes from an application. - * - * @summary List existing indexes. - * @param listIndices - The listIndices object. - * @param listIndices.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - */ - listIndices( - { page }: ListIndicesProps, - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/indexes'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (page !== undefined) { - queryParameters.page = page.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * List the userIDs assigned to a multi-clusters appID. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following userIDs data. - * - * @summary List userIDs. - * @param listUserIds - The listUserIds object. - * @param listUserIds.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * @param listUserIds.hitsPerPage - Maximum number of objects to retrieve. - */ - listUserIds( - { page, hitsPerPage }: ListUserIdsProps, - requestOptions?: RequestOptions - ): Promise { - const requestPath = '/1/clusters/mapping'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (page !== undefined) { - queryParameters.page = page.toString(); - } - - if (hitsPerPage !== undefined) { - queryParameters.hitsPerPage = hitsPerPage.toString(); - } - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Perform multiple write operations, potentially targeting multiple indices, in a single API call. - * - * @summary Perform multiple write operations. - * @param batchParams - The batchParams object. - */ - multipleBatch( - batchParams: BatchParams, - requestOptions?: RequestOptions - ): Promise { - if (!batchParams) { - throw new Error( - 'Parameter `batchParams` is required when calling `multipleBatch`.' - ); - } - - const requestPath = '/1/indexes/*/batch'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: batchParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get search results for the given requests. - * - * @summary Get search results for the given requests. - * @param multipleQueriesParams - The multipleQueriesParams object. - */ - multipleQueries( - multipleQueriesParams: MultipleQueriesParams, - requestOptions?: RequestOptions - ): Promise { - if (!multipleQueriesParams) { - throw new Error( - 'Parameter `multipleQueriesParams` is required when calling `multipleQueries`.' - ); - } - - if (!multipleQueriesParams.requests) { - throw new Error( - 'Parameter `multipleQueriesParams.requests` is required when calling `multipleQueries`.' - ); - } - - const requestPath = '/1/indexes/*/queries'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: multipleQueriesParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Peforms a copy or a move operation on a index. - * - * @summary Copy/move index. - * @param operationIndex - The operationIndex object. - * @param operationIndex.indexName - The index in which to perform the request. - * @param operationIndex.operationIndexParams - The operationIndexParams object. - */ - operationIndex( - { indexName, operationIndexParams }: OperationIndexProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `operationIndex`.' - ); - } - - if (!operationIndexParams) { - throw new Error( - 'Parameter `operationIndexParams` is required when calling `operationIndex`.' - ); - } - - if (!operationIndexParams.operation) { - throw new Error( - 'Parameter `operationIndexParams.operation` is required when calling `operationIndex`.' - ); - } - if (!operationIndexParams.destination) { - throw new Error( - 'Parameter `operationIndexParams.destination` is required when calling `operationIndex`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/operation'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: operationIndexParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Update one or more attributes of an existing object. This method lets you update only a part of an existing object, either by adding new attributes or updating existing ones. You can partially update several objects in a single method call. If the index targeted by this operation doesn\'t exist yet, it\'s automatically created. - * - * @summary Partially update an object. - * @param partialUpdateObject - The partialUpdateObject object. - * @param partialUpdateObject.indexName - The index in which to perform the request. - * @param partialUpdateObject.objectID - Unique identifier of an object. - * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update. - * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet. - */ - partialUpdateObject( - { - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - }: PartialUpdateObjectProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `partialUpdateObject`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `partialUpdateObject`.' - ); - } - - if (!attributeOrBuiltInOperation) { - throw new Error( - 'Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/{objectID}/partial' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (createIfNotExists !== undefined) { - queryParameters.createIfNotExists = createIfNotExists.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - data: attributeOrBuiltInOperation, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Remove a userID and its associated data from the multi-clusters. Upon success, the response is 200 OK and a task is created to remove the userID data and mapping. - * - * @summary Remove userID. - * @param removeUserId - The removeUserId object. - * @param removeUserId.userID - UserID to assign. - */ - removeUserId( - { userID }: RemoveUserIdProps, - requestOptions?: RequestOptions - ): Promise { - if (!userID) { - throw new Error( - 'Parameter `userID` is required when calling `removeUserId`.' - ); - } - - const requestPath = '/1/clusters/mapping/{userID}'.replace( - '{userID}', - encodeURIComponent(userID) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Replace all allowed sources. - * - * @summary Replace all allowed sources. - * @param replaceSources - The replaceSources object. - * @param replaceSources.source - The sources to allow. - */ - replaceSources( - { source }: ReplaceSourcesProps, - requestOptions?: RequestOptions - ): Promise { - if (!source) { - throw new Error( - 'Parameter `source` is required when calling `replaceSources`.' - ); - } - - const requestPath = '/1/security/sources'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: source, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Restore a deleted API key, along with its associated rights. - * - * @summary Restore an API key. - * @param restoreApiKey - The restoreApiKey object. - * @param restoreApiKey.key - API Key string. - */ - restoreApiKey( - { key }: RestoreApiKeyProps, - requestOptions?: RequestOptions - ): Promise { - if (!key) { - throw new Error( - 'Parameter `key` is required when calling `restoreApiKey`.' - ); - } - - const requestPath = '/1/keys/{key}/restore'.replace( - '{key}', - encodeURIComponent(key) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Add an object to the index, automatically assigning it an object ID. - * - * @summary Add an object to the index. - * @param saveObject - The saveObject object. - * @param saveObject.indexName - The index in which to perform the request. - * @param saveObject.body - The Algolia record. - */ - saveObject( - { indexName, body }: SaveObjectProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `saveObject`.' - ); - } - - if (!body) { - throw new Error( - 'Parameter `body` is required when calling `saveObject`.' - ); - } - - const requestPath = '/1/indexes/{indexName}'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Create or update the Rule with the specified objectID. - * - * @summary Save/Update a rule. - * @param saveRule - The saveRule object. - * @param saveRule.indexName - The index in which to perform the request. - * @param saveRule.objectID - Unique identifier of an object. - * @param saveRule.rule - The rule object. - * @param saveRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - saveRule( - { indexName, objectID, rule, forwardToReplicas }: SaveRuleProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `saveRule`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `saveRule`.' - ); - } - - if (!rule) { - throw new Error( - 'Parameter `rule` is required when calling `saveRule`.' - ); - } - - if (!rule.objectID) { - throw new Error( - 'Parameter `rule.objectID` is required when calling `saveRule`.' - ); - } - if (!rule.consequence) { - throw new Error( - 'Parameter `rule.consequence` is required when calling `saveRule`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'PUT', - path: requestPath, - data: rule, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Create a new synonym object or update the existing synonym object with the given object ID. - * - * @summary Save synonym. - * @param saveSynonym - The saveSynonym object. - * @param saveSynonym.indexName - The index in which to perform the request. - * @param saveSynonym.objectID - Unique identifier of an object. - * @param saveSynonym.synonymHit - The synonymHit object. - * @param saveSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - saveSynonym( - { indexName, objectID, synonymHit, forwardToReplicas }: SaveSynonymProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `saveSynonym`.' - ); - } - - if (!objectID) { - throw new Error( - 'Parameter `objectID` is required when calling `saveSynonym`.' - ); - } - - if (!synonymHit) { - throw new Error( - 'Parameter `synonymHit` is required when calling `saveSynonym`.' - ); - } - - if (!synonymHit.objectID) { - throw new Error( - 'Parameter `synonymHit.objectID` is required when calling `saveSynonym`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{objectID}', encodeURIComponent(objectID)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'PUT', - path: requestPath, - data: synonymHit, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Create/update multiple synonym objects at once, potentially replacing the entire list of synonyms if replaceExistingSynonyms is true. - * - * @summary Save a batch of synonyms. - * @param saveSynonyms - The saveSynonyms object. - * @param saveSynonyms.indexName - The index in which to perform the request. - * @param saveSynonyms.synonymHit - The synonymHit object. - * @param saveSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - * @param saveSynonyms.replaceExistingSynonyms - Replace all synonyms of the index with the ones sent with this request. - */ - saveSynonyms( - { - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - }: SaveSynonymsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `saveSynonyms`.' - ); - } - - if (!synonymHit) { - throw new Error( - 'Parameter `synonymHit` is required when calling `saveSynonyms`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/batch'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - if (replaceExistingSynonyms !== undefined) { - queryParameters.replaceExistingSynonyms = - replaceExistingSynonyms.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - data: synonymHit, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Get search results. - * - * @summary Get search results. - * @param search - The search object. - * @param search.indexName - The index in which to perform the request. - * @param search.searchParams - The searchParams object. - */ - search( - { indexName, searchParams }: SearchProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `search`.' - ); - } - - if (!searchParams) { - throw new Error( - 'Parameter `searchParams` is required when calling `search`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/query'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search the dictionary entries. - * - * @summary Search the dictionary entries. - * @param searchDictionaryEntries - The searchDictionaryEntries object. - * @param searchDictionaryEntries.dictionaryName - The dictionary to search in. - * @param searchDictionaryEntries.searchDictionaryEntriesParams - The searchDictionaryEntriesParams object. - */ - searchDictionaryEntries( - { - dictionaryName, - searchDictionaryEntriesParams, - }: SearchDictionaryEntriesProps, - requestOptions?: RequestOptions - ): Promise { - if (!dictionaryName) { - throw new Error( - 'Parameter `dictionaryName` is required when calling `searchDictionaryEntries`.' - ); - } - - if (!searchDictionaryEntriesParams) { - throw new Error( - 'Parameter `searchDictionaryEntriesParams` is required when calling `searchDictionaryEntries`.' - ); - } - - if (!searchDictionaryEntriesParams.query) { - throw new Error( - 'Parameter `searchDictionaryEntriesParams.query` is required when calling `searchDictionaryEntries`.' - ); - } - - const requestPath = '/1/dictionaries/{dictionaryName}/search'.replace( - '{dictionaryName}', - encodeURIComponent(dictionaryName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchDictionaryEntriesParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search for values of a given facet, optionally restricting the returned values to those contained in objects matching other search criteria. - * - * @summary Search for values of a given facet. - * @param searchForFacetValues - The searchForFacetValues object. - * @param searchForFacetValues.indexName - The index in which to perform the request. - * @param searchForFacetValues.facetName - The facet name. - * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object. - */ - searchForFacetValues( - { - indexName, - facetName, - searchForFacetValuesRequest, - }: SearchForFacetValuesProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `searchForFacetValues`.' - ); - } - - if (!facetName) { - throw new Error( - 'Parameter `facetName` is required when calling `searchForFacetValues`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/facets/{facetName}/query' - .replace('{indexName}', encodeURIComponent(indexName)) - .replace('{facetName}', encodeURIComponent(facetName)); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchForFacetValuesRequest, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search for rules matching various criteria. - * - * @summary Search for rules. - * @param searchRules - The searchRules object. - * @param searchRules.indexName - The index in which to perform the request. - * @param searchRules.searchRulesParams - The searchRulesParams object. - */ - searchRules( - { indexName, searchRulesParams }: SearchRulesProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `searchRules`.' - ); - } - - if (!searchRulesParams) { - throw new Error( - 'Parameter `searchRulesParams` is required when calling `searchRules`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/rules/search'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchRulesParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search or browse all synonyms, optionally filtering them by type. - * - * @summary Get all synonyms that match a query. - * @param searchSynonyms - The searchSynonyms object. - * @param searchSynonyms.indexName - The index in which to perform the request. - * @param searchSynonyms.query - Search for specific synonyms matching this string. - * @param searchSynonyms.type - Only search for specific types of synonyms. - * @param searchSynonyms.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * @param searchSynonyms.hitsPerPage - Maximum number of objects to retrieve. - */ - searchSynonyms( - { indexName, query, type, page, hitsPerPage }: SearchSynonymsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `searchSynonyms`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/synonyms/search'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (query !== undefined) { - queryParameters.query = query.toString(); - } - - if (type !== undefined) { - queryParameters.type = type.toString(); - } - - if (page !== undefined) { - queryParameters.page = page.toString(); - } - - if (hitsPerPage !== undefined) { - queryParameters.hitsPerPage = hitsPerPage.toString(); - } - - const request: Request = { - method: 'POST', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Search for userIDs. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds propagate to the different clusters. To keep updates moving quickly, the index of userIDs isn\'t built synchronously with the mapping. Instead, the index is built once every 12h, at the same time as the update of userID usage. For example, when you perform a modification like adding or moving a userID, the search will report an outdated value until the next rebuild of the mapping, which takes place every 12h. Upon success, the response is 200 OK and contains the following userIDs data. - * - * @summary Search userID. - * @param searchUserIdsParams - The searchUserIdsParams object. - */ - searchUserIds( - searchUserIdsParams: SearchUserIdsParams, - requestOptions?: RequestOptions - ): Promise { - if (!searchUserIdsParams) { - throw new Error( - 'Parameter `searchUserIdsParams` is required when calling `searchUserIds`.' - ); - } - - if (!searchUserIdsParams.query) { - throw new Error( - 'Parameter `searchUserIdsParams.query` is required when calling `searchUserIds`.' - ); - } - - const requestPath = '/1/clusters/mapping/search'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: searchUserIdsParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Set dictionary settings. - * - * @summary Set dictionary settings. - * @param dictionarySettingsParams - The dictionarySettingsParams object. - */ - setDictionarySettings( - dictionarySettingsParams: DictionarySettingsParams, - requestOptions?: RequestOptions - ): Promise { - if (!dictionarySettingsParams) { - throw new Error( - 'Parameter `dictionarySettingsParams` is required when calling `setDictionarySettings`.' - ); - } - - if (!dictionarySettingsParams.disableStandardEntries) { - throw new Error( - 'Parameter `dictionarySettingsParams.disableStandardEntries` is required when calling `setDictionarySettings`.' - ); - } - - const requestPath = '/1/dictionaries/*/settings'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: dictionarySettingsParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Update settings of a given indexName. Only specified settings are overridden; unspecified settings are left unchanged. Specifying null for a setting resets it to its default value. - * - * @summary Update settings of a given indexName. - * @param setSettings - The setSettings object. - * @param setSettings.indexName - The index in which to perform the request. - * @param setSettings.indexSettings - The indexSettings object. - * @param setSettings.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. - */ - setSettings( - { indexName, indexSettings, forwardToReplicas }: SetSettingsProps, - requestOptions?: RequestOptions - ): Promise { - if (!indexName) { - throw new Error( - 'Parameter `indexName` is required when calling `setSettings`.' - ); - } - - if (!indexSettings) { - throw new Error( - 'Parameter `indexSettings` is required when calling `setSettings`.' - ); - } - - const requestPath = '/1/indexes/{indexName}/settings'.replace( - '{indexName}', - encodeURIComponent(indexName) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - if (forwardToReplicas !== undefined) { - queryParameters.forwardToReplicas = forwardToReplicas.toString(); - } - - const request: Request = { - method: 'PUT', - path: requestPath, - data: indexSettings, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Replace every permission of an existing API key. - * - * @summary Update an API key. - * @param updateApiKey - The updateApiKey object. - * @param updateApiKey.key - API Key string. - * @param updateApiKey.apiKey - The apiKey object. - */ - updateApiKey( - { key, apiKey }: UpdateApiKeyProps, - requestOptions?: RequestOptions - ): Promise { - if (!key) { - throw new Error( - 'Parameter `key` is required when calling `updateApiKey`.' - ); - } - - if (!apiKey) { - throw new Error( - 'Parameter `apiKey` is required when calling `updateApiKey`.' - ); - } - - if (!apiKey.acl) { - throw new Error( - 'Parameter `apiKey.acl` is required when calling `updateApiKey`.' - ); - } - - const requestPath = '/1/keys/{key}'.replace( - '{key}', - encodeURIComponent(key) - ); - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: apiKey, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type SearchApi = ReturnType; - -export type AddOrUpdateObjectProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - /** - * The Algolia object. - */ - body: Record; -}; - -export type AssignUserIdProps = { - /** - * UserID to assign. - */ - xAlgoliaUserID: string; - assignUserIdParams: AssignUserIdParams; -}; - -export type BatchProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - batchWriteParams: BatchWriteParams; -}; - -export type BatchAssignUserIdsProps = { - /** - * UserID to assign. - */ - xAlgoliaUserID: string; - batchAssignUserIdsParams: BatchAssignUserIdsParams; -}; - -export type BatchDictionaryEntriesProps = { - /** - * The dictionary to search in. - */ - dictionaryName: DictionaryType; - batchDictionaryEntriesParams: BatchDictionaryEntriesParams; -}; - -export type BatchRulesProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - rule: Rule[]; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; - /** - * When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. - */ - clearExistingRules?: boolean; -}; - -export type BrowseProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - browseRequest?: BrowseRequest; -}; - -export type ClearAllSynonymsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type ClearObjectsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type ClearRulesProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type DeleteApiKeyProps = { - /** - * API Key string. - */ - key: string; -}; - -export type DeleteByProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - searchParams: SearchParams; -}; - -export type DeleteIndexProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type DeleteObjectProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; -}; - -export type DeleteRuleProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type DeleteSourceProps = { - /** - * The IP range of the source. - */ - source: string; -}; - -export type DeleteSynonymProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetApiKeyProps = { - /** - * API Key string. - */ - key: string; -}; - -export type GetLogsProps = { - /** - * First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. - */ - offset?: number; - /** - * Maximum number of entries to retrieve. The maximum allowed value is 1000. - */ - length?: number; - /** - * Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. - */ - indexName?: string; - /** - * Type of log entries to retrieve. When omitted, all log entries are retrieved. - */ - type?: LogType; -}; - -export type GetObjectProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - /** - * List of attributes to retrieve. If not specified, all retrievable attributes are returned. - */ - attributesToRetrieve?: string[]; -}; - -export type GetRuleProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; -}; - -export type GetSettingsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; -}; - -export type GetSynonymProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; -}; - -export type GetTaskProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an task. Numeric value (up to 64bits). - */ - taskID: number; -}; - -export type GetUserIdProps = { - /** - * UserID to assign. - */ - userID: string; -}; - -export type HasPendingMappingsProps = { - /** - * Whether to get clusters or not. - */ - getClusters?: boolean; -}; - -export type ListIndicesProps = { - /** - * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - */ - page?: number; -}; - -export type ListUserIdsProps = { - /** - * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - */ - page?: number; - /** - * Maximum number of objects to retrieve. - */ - hitsPerPage?: number; -}; - -export type OperationIndexProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - operationIndexParams: OperationIndexParams; -}; - -export type PartialUpdateObjectProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - /** - * List of attributes to update. - */ - attributeOrBuiltInOperation: Array<{ - [key: string]: AttributeOrBuiltInOperation; - }>; - /** - * Creates the record if it does not exist yet. - */ - createIfNotExists?: boolean; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type RemoveUserIdProps = { - /** - * UserID to assign. - */ - userID: string; -}; - -export type ReplaceSourcesProps = { - /** - * The sources to allow. - */ - source: Source[]; -}; - -export type RestoreApiKeyProps = { - /** - * API Key string. - */ - key: string; -}; - -export type SaveObjectProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * The Algolia record. - */ - body: Record; -}; - -export type SaveRuleProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - rule: Rule; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type SaveSynonymProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Unique identifier of an object. - */ - objectID: string; - synonymHit: SynonymHit; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type SaveSynonymsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - synonymHit: SynonymHit[]; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; - /** - * Replace all synonyms of the index with the ones sent with this request. - */ - replaceExistingSynonyms?: boolean; -}; - -export type SearchProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - searchParams: SearchParams; -}; - -export type SearchDictionaryEntriesProps = { - /** - * The dictionary to search in. - */ - dictionaryName: DictionaryType; - searchDictionaryEntriesParams: SearchDictionaryEntriesParams; -}; - -export type SearchForFacetValuesProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * The facet name. - */ - facetName: string; - searchForFacetValuesRequest?: SearchForFacetValuesRequest; -}; - -export type SearchRulesProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - searchRulesParams: SearchRulesParams; -}; - -export type SearchSynonymsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - /** - * Search for specific synonyms matching this string. - */ - query?: string; - /** - * Only search for specific types of synonyms. - */ - type?: SynonymType; - /** - * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - */ - page?: number; - /** - * Maximum number of objects to retrieve. - */ - hitsPerPage?: number; -}; - -export type SetSettingsProps = { - /** - * The index in which to perform the request. - */ - indexName: string; - indexSettings: IndexSettings; - /** - * When true, changes are also propagated to replicas of the given indexName. - */ - forwardToReplicas?: boolean; -}; - -export type UpdateApiKeyProps = { - /** - * API Key string. - */ - key: string; - apiKey: ApiKey; -}; diff --git a/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts b/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts deleted file mode 100644 index cb6f6caa70..0000000000 --- a/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts +++ /dev/null @@ -1,325 +0,0 @@ -import { - createAuth, - createTransporter, - getUserAgent, - shuffle, -} from '@experimental-api-clients-automation/client-common'; -import type { - CreateClientOptions, - Headers, - Host, - Request, - RequestOptions, - QueryParameters, -} from '@experimental-api-clients-automation/client-common'; - -import type { GetRecommendationsParams } from '../model/getRecommendationsParams'; -import type { GetRecommendationsResponse } from '../model/getRecommendationsResponse'; - -export * from '../model'; -export const apiClientVersion = '0.0.5'; - -function getDefaultHosts(appId: string): Host[] { - return ( - [ - { - url: `${appId}-dsn.algolia.net`, - accept: 'read', - protocol: 'https', - }, - { - url: `${appId}.algolia.net`, - accept: 'write', - protocol: 'https', - }, - ] as Host[] - ).concat( - shuffle([ - { - url: `${appId}-1.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-2.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-3.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]) - ); -} - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function createRecommendApi(options: CreateClientOptions) { - const auth = createAuth(options.appId, options.apiKey, options.authMode); - const transporter = createTransporter({ - hosts: options?.hosts ?? getDefaultHosts(options.appId), - hostsCache: options.hostsCache, - requestsCache: options.requestsCache, - responsesCache: options.responsesCache, - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded', - ...auth.headers(), - }, - baseQueryParameters: auth.queryParameters(), - userAgent: getUserAgent({ - userAgents: options.userAgents, - client: 'Recommend', - version: apiClientVersion, - }), - timeouts: options.timeouts, - requester: options.requester, - }); - - function addUserAgent(segment: string, version?: string): void { - transporter.userAgent.add({ segment, version }); - } - - return { - addUserAgent, - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param del - The del object. - * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param del.parameters - Query parameters to be applied to the current query. - */ - del( - { path, parameters }: DelProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `del`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'DELETE', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param get - The get object. - * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param get.parameters - Query parameters to be applied to the current query. - */ - get( - { path, parameters }: GetProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `get`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'GET', - path: requestPath, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * Returns recommendations for a specific model and objectID. - * - * @summary Returns recommendations for a specific model and objectID. - * @param getRecommendationsParams - The getRecommendationsParams object. - */ - getRecommendations( - getRecommendationsParams: GetRecommendationsParams, - requestOptions?: RequestOptions - ): Promise { - if (!getRecommendationsParams) { - throw new Error( - 'Parameter `getRecommendationsParams` is required when calling `getRecommendations`.' - ); - } - - if (!getRecommendationsParams.requests) { - throw new Error( - 'Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.' - ); - } - - const requestPath = '/1/indexes/*/recommendations'; - const headers: Headers = {}; - const queryParameters: QueryParameters = {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: getRecommendationsParams, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param post - The post object. - * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param post.parameters - Query parameters to be applied to the current query. - * @param post.body - The parameters to send with the custom request. - */ - post( - { path, parameters, body }: PostProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `post`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'POST', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @summary Send requests to the Algolia REST API. - * @param put - The put object. - * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. - * @param put.parameters - Query parameters to be applied to the current query. - * @param put.body - The parameters to send with the custom request. - */ - put( - { path, parameters, body }: PutProps, - requestOptions?: RequestOptions - ): Promise> { - if (!path) { - throw new Error('Parameter `path` is required when calling `put`.'); - } - - const requestPath = '/1{path}'.replace('{path}', path); - const headers: Headers = {}; - const queryParameters: QueryParameters = parameters || {}; - - const request: Request = { - method: 'PUT', - path: requestPath, - data: body, - }; - - return transporter.request( - request, - { - queryParameters, - headers, - }, - requestOptions - ); - }, - }; -} - -export type RecommendApi = ReturnType; - -export type DelProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type GetProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; -}; - -export type PostProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; - -export type PutProps = { - /** - * The path of the API endpoint to target, anything after the /1 needs to be specified. - */ - path: string; - /** - * Query parameters to be applied to the current query. - */ - parameters?: Record; - /** - * The parameters to send with the custom request. - */ - body?: Record; -}; diff --git a/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php b/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php deleted file mode 100644 index 3795eae75a..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php +++ /dev/null @@ -1,455 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials and region - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - * @param string $region Region - */ - public static function create($appId = null, $apiKey = null, $region = null) - { - $allowedRegions = explode('-', 'us-de'); - $config = AbtestingConfig::create($appId, $apiKey, $region, $allowedRegions); - - return static::createWithConfig($config); - } - - /** - * Instantiate the client with configuration - * - * @param AbtestingConfig $config Configuration - */ - public static function createWithConfig(AbtestingConfig $config) - { - $config = clone $config; - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } else { - $clusterHosts = ClusterHosts::create('analytics.'.$config->getRegion().'.algolia.com'); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return AbtestingConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Creates a new A/B test with provided configuration. - * - * @param array $addABTestsRequest addABTestsRequest (required) - * - $addABTestsRequest['name'] => (string) A/B test name. (required) - * - $addABTestsRequest['variant'] => (array) List of 2 variants for the A/B test. (required) - * - $addABTestsRequest['endAt'] => (string) End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsRequest - * - * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse - */ - public function addABTests($addABTestsRequest) - { - // verify the required parameter 'addABTestsRequest' is set - if ($addABTestsRequest === null || (is_array($addABTestsRequest) && count($addABTestsRequest) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $addABTestsRequest when calling addABTests' - ); - } - - $resourcePath = '/2/abtests'; - $queryParams = []; - $httpBody = []; - - if (isset($addABTestsRequest)) { - $httpBody = $addABTestsRequest; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Deletes the A/B Test. - * - * @param int $id The A/B test ID. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse - */ - public function deleteABTest($id) - { - // verify the required parameter 'id' is set - if ($id === null || (is_array($id) && count($id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $id when calling deleteABTest' - ); - } - - $resourcePath = '/2/abtests/{id}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($id !== null) { - $resourcePath = str_replace( - '{id}', - ObjectSerializer::toPathValue($id), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns metadata and metrics for A/B test id. - * - * @param int $id The A/B test ID. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTest - */ - public function getABTest($id) - { - // verify the required parameter 'id' is set - if ($id === null || (is_array($id) && count($id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $id when calling getABTest' - ); - } - - $resourcePath = '/2/abtests/{id}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($id !== null) { - $resourcePath = str_replace( - '{id}', - ObjectSerializer::toPathValue($id), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Fetch all existing A/B tests for App that are available for the current API Key. - * - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * - * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ListABTestsResponse - */ - public function listABTests($offset = 0, $limit = 10) - { - $resourcePath = '/2/abtests'; - $queryParams = []; - $httpBody = []; - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Marks the A/B test as stopped. - * - * @param int $id The A/B test ID. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse - */ - public function stopABTest($id) - { - // verify the required parameter 'id' is set - if ($id === null || (is_array($id) && count($id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $id when calling stopABTest' - ); - } - - $resourcePath = '/2/abtests/{id}/stop'; - $queryParams = []; - $httpBody = []; - - // path params - if ($id !== null) { - $resourcePath = str_replace( - '{id}', - ObjectSerializer::toPathValue($id), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php b/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php deleted file mode 100644 index a38c328e4a..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php +++ /dev/null @@ -1,1771 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials and region - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - * @param string $region Region - */ - public static function create($appId = null, $apiKey = null, $region = null) - { - $allowedRegions = explode('-', 'us-de'); - $config = AnalyticsConfig::create($appId, $apiKey, $region, $allowedRegions); - - return static::createWithConfig($config); - } - - /** - * Instantiate the client with configuration - * - * @param AnalyticsConfig $config Configuration - */ - public static function createWithConfig(AnalyticsConfig $config) - { - $config = clone $config; - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } else { - $clusterHosts = ClusterHosts::create('analytics.'.$config->getRegion().'.algolia.com'); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return AnalyticsConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the average click position. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetAverageClickPositionResponse - */ - public function getAverageClickPosition($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getAverageClickPosition' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getAverageClickPosition, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getAverageClickPosition, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/clicks/averageClickPosition'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the distribution of clicks per range of positions. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetClickPositionsResponse - */ - public function getClickPositions($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getClickPositions' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getClickPositions, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getClickPositions, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/clicks/positions'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns a click-through rate (CTR). - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetClickThroughRateResponse - */ - public function getClickThroughRate($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getClickThroughRate' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getClickThroughRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getClickThroughRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/clicks/clickThroughRate'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns a conversion rate (CR). - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetConversationRateResponse - */ - public function getConversationRate($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getConversationRate' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getConversationRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getConversationRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/conversions/conversionRate'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the rate at which searches didn't lead to any clicks. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetNoClickRateResponse - */ - public function getNoClickRate($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getNoClickRate' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getNoClickRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getNoClickRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches/noClickRate'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the rate at which searches didn't return any results. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetNoResultsRateResponse - */ - public function getNoResultsRate($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getNoResultsRate' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getNoResultsRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getNoResultsRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches/noResultRate'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the number of searches across the given time range. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesCountResponse - */ - public function getSearchesCount($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getSearchesCount' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches/count'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top searches that didn't lead to any clicks. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesNoClicksResponse - */ - public function getSearchesNoClicks($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getSearchesNoClicks' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesNoClicks, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesNoClicks, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches/noClicks'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top searches that didn't return any results. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesNoResultsResponse - */ - public function getSearchesNoResults($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getSearchesNoResults' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches/noResults'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get latest update time of the analytics API. - * - * @param string $index The index name to target. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetStatusResponse - */ - public function getStatus($index) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getStatus' - ); - } - - $resourcePath = '/2/status'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top countries. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopCountriesResponse - */ - public function getTopCountries($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopCountries' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopCountries, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopCountries, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/countries'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top filter attributes. - * - * @param string $index The index name to target. (required) - * @param string $search The query term to search for. Must match the exact user input. (optional) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFilterAttributesResponse - */ - public function getTopFilterAttributes($index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopFilterAttributes' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFilterAttributes, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFilterAttributes, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/filters'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($search !== null) { - if ('form' === 'form' && is_array($search)) { - foreach ($search as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['search'] = $search; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top filters for the given attribute. - * - * @param string $attribute The exact name of the attribute. (required) - * @param string $index The index name to target. (required) - * @param string $search The query term to search for. Must match the exact user input. (optional) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFilterForAttributeResponse - */ - public function getTopFilterForAttribute($attribute, $index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'attribute' is set - if ($attribute === null || (is_array($attribute) && count($attribute) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $attribute when calling getTopFilterForAttribute' - ); - } - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopFilterForAttribute' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFilterForAttribute, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFilterForAttribute, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/filters/{attribute}'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($search !== null) { - if ('form' === 'form' && is_array($search)) { - foreach ($search as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['search'] = $search; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - // path params - if ($attribute !== null) { - $resourcePath = str_replace( - '{attribute}', - ObjectSerializer::toPathValue($attribute), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top filters with no results. - * - * @param string $index The index name to target. (required) - * @param string $search The query term to search for. Must match the exact user input. (optional) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFiltersNoResultsResponse - */ - public function getTopFiltersNoResults($index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopFiltersNoResults' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFiltersNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFiltersNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/filters/noResults'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($search !== null) { - if ('form' === 'form' && is_array($search)) { - foreach ($search as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['search'] = $search; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top hits. - * - * @param string $index The index name to target. (required) - * @param string $search The query term to search for. Must match the exact user input. (optional) - * @param bool $clickAnalytics Whether to include the click-through and conversion rates for a search. (optional, default to false) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopHitsResponse - */ - public function getTopHits($index, $search = null, $clickAnalytics = false, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopHits' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopHits, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopHits, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/hits'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($search !== null) { - if ('form' === 'form' && is_array($search)) { - foreach ($search as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['search'] = $search; - } - } - - if ($clickAnalytics !== null) { - if ('form' === 'form' && is_array($clickAnalytics)) { - foreach ($clickAnalytics as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['clickAnalytics'] = $clickAnalytics; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns top searches. - * - * @param string $index The index name to target. (required) - * @param bool $clickAnalytics Whether to include the click-through and conversion rates for a search. (optional, default to false) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param array $orderBy Reorder the results. (optional) - * @param array $direction The sorting of the result. (optional) - * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) - * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopSearchesResponse - */ - public function getTopSearches($index, $clickAnalytics = false, $startDate = null, $endDate = null, $orderBy = null, $direction = null, $limit = 10, $offset = 0, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getTopSearches' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopSearches, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopSearches, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/searches'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($clickAnalytics !== null) { - if ('form' === 'form' && is_array($clickAnalytics)) { - foreach ($clickAnalytics as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['clickAnalytics'] = $clickAnalytics; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($orderBy !== null) { - if ('form' === 'form' && is_array($orderBy)) { - foreach ($orderBy as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['orderBy'] = $orderBy; - } - } - - if ($direction !== null) { - if ('form' === 'form' && is_array($direction)) { - foreach ($direction as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['direction'] = $direction; - } - } - - if ($limit !== null) { - if ('form' === 'form' && is_array($limit)) { - foreach ($limit as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['limit'] = $limit; - } - } - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns the distinct count of users across the given time range. - * - * @param string $index The index name to target. (required) - * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) - * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetUsersCountResponse - */ - public function getUsersCount($index, $startDate = null, $endDate = null, $tags = null) - { - // verify the required parameter 'index' is set - if ($index === null || (is_array($index) && count($index) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $index when calling getUsersCount' - ); - } - if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { - throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getUsersCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { - throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getUsersCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); - } - - $resourcePath = '/2/users/count'; - $queryParams = []; - $httpBody = []; - - if ($index !== null) { - if ('form' === 'form' && is_array($index)) { - foreach ($index as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['index'] = $index; - } - } - - if ($startDate !== null) { - if ('form' === 'form' && is_array($startDate)) { - foreach ($startDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['startDate'] = $startDate; - } - } - - if ($endDate !== null) { - if ('form' === 'form' && is_array($endDate)) { - foreach ($endDate as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['endDate'] = $endDate; - } - } - - if ($tags !== null) { - if ('form' === 'form' && is_array($tags)) { - foreach ($tags as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['tags'] = $tags; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/InsightsApi.php b/clients/algoliasearch-client-php/lib/Api/InsightsApi.php deleted file mode 100644 index 858783fa6f..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/InsightsApi.php +++ /dev/null @@ -1,319 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials and region - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - * @param string $region Region - */ - public static function create($appId = null, $apiKey = null, $region = null) - { - $allowedRegions = explode('-', 'us-de'); - $config = InsightsConfig::create($appId, $apiKey, $region, $allowedRegions); - - return static::createWithConfig($config); - } - - /** - * Instantiate the client with configuration - * - * @param InsightsConfig $config Configuration - */ - public static function createWithConfig(InsightsConfig $config) - { - $config = clone $config; - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } else { - $clusterHosts = ClusterHosts::create('insights.'.$config->getRegion().'.algolia.io'); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return InsightsConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Pushes an array of events. - * - * @param array $insightEvents insightEvents (required) - * - $insightEvents['events'] => (array) Array of events sent. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Insights\InsightEvents - * - * @return array|\Algolia\AlgoliaSearch\Model\Insights\PushEventsResponse - */ - public function pushEvents($insightEvents) - { - // verify the required parameter 'insightEvents' is set - if ($insightEvents === null || (is_array($insightEvents) && count($insightEvents) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $insightEvents when calling pushEvents' - ); - } - - $resourcePath = '/1/events'; - $queryParams = []; - $httpBody = []; - - if (isset($insightEvents)) { - $httpBody = $insightEvents; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php b/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php deleted file mode 100644 index 9cda894221..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php +++ /dev/null @@ -1,401 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials and region - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - * @param string $region Region - */ - public static function create($appId = null, $apiKey = null, $region = null) - { - $allowedRegions = explode('-', 'us-eu'); - $config = PersonalizationConfig::create($appId, $apiKey, $region, $allowedRegions); - - return static::createWithConfig($config); - } - - /** - * Instantiate the client with configuration - * - * @param PersonalizationConfig $config Configuration - */ - public static function createWithConfig(PersonalizationConfig $config) - { - $config = clone $config; - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } else { - $clusterHosts = ClusterHosts::create('personalization.'.$config->getRegion().'.algolia.com'); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return PersonalizationConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete the user profile and all its associated data. - * - * @param string $userToken userToken representing the user for which to fetch the Personalization profile. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Personalization\DeleteUserProfileResponse - */ - public function deleteUserProfile($userToken) - { - // verify the required parameter 'userToken' is set - if ($userToken === null || (is_array($userToken) && count($userToken) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $userToken when calling deleteUserProfile' - ); - } - - $resourcePath = '/1/profiles/{userToken}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($userToken !== null) { - $resourcePath = str_replace( - '{userToken}', - ObjectSerializer::toPathValue($userToken), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the current personalization strategy. - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Personalization\PersonalizationStrategyParams - */ - public function getPersonalizationStrategy() - { - $resourcePath = '/1/strategies/personalization'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the user profile built from Personalization strategy. - * - * @param string $userToken userToken representing the user for which to fetch the Personalization profile. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Personalization\GetUserTokenResponse - */ - public function getUserTokenProfile($userToken) - { - // verify the required parameter 'userToken' is set - if ($userToken === null || (is_array($userToken) && count($userToken) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $userToken when calling getUserTokenProfile' - ); - } - - $resourcePath = '/1/profiles/personalization/{userToken}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($userToken !== null) { - $resourcePath = str_replace( - '{userToken}', - ObjectSerializer::toPathValue($userToken), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Set a new personalization strategy. - * - * @param array $personalizationStrategyParams personalizationStrategyParams (required) - * - $personalizationStrategyParams['eventScoring'] => (array) Scores associated with the events. (required) - * - $personalizationStrategyParams['facetScoring'] => (array) Scores associated with the facets. (required) - * - $personalizationStrategyParams['personalizationImpact'] => (int) The impact that personalization has on search results: a number between 0 (personalization disabled) and 100 (personalization fully enabled). (required) - * - * @see \Algolia\AlgoliaSearch\Model\Personalization\PersonalizationStrategyParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Personalization\SetPersonalizationStrategyResponse - */ - public function setPersonalizationStrategy($personalizationStrategyParams) - { - // verify the required parameter 'personalizationStrategyParams' is set - if ($personalizationStrategyParams === null || (is_array($personalizationStrategyParams) && count($personalizationStrategyParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $personalizationStrategyParams when calling setPersonalizationStrategy' - ); - } - - $resourcePath = '/1/strategies/personalization'; - $queryParams = []; - $httpBody = []; - - if (isset($personalizationStrategyParams)) { - $httpBody = $personalizationStrategyParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php b/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php deleted file mode 100644 index ae21d7a7a0..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php +++ /dev/null @@ -1,510 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials and region - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - * @param string $region Region - */ - public static function create($appId = null, $apiKey = null, $region = null) - { - $allowedRegions = explode('-', 'us-eu'); - $config = QuerySuggestionsConfig::create($appId, $apiKey, $region, $allowedRegions); - - return static::createWithConfig($config); - } - - /** - * Instantiate the client with configuration - * - * @param QuerySuggestionsConfig $config Configuration - */ - public static function createWithConfig(QuerySuggestionsConfig $config) - { - $config = clone $config; - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } else { - $clusterHosts = ClusterHosts::create('query-suggestions.'.$config->getRegion().'.algolia.com'); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return QuerySuggestionsConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Create a configuration of a Query Suggestions index. - * - * @param array $querySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam (required) - * - * @see \Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndexWithIndexParam - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse - */ - public function createConfig($querySuggestionsIndexWithIndexParam) - { - // verify the required parameter 'querySuggestionsIndexWithIndexParam' is set - if ($querySuggestionsIndexWithIndexParam === null || (is_array($querySuggestionsIndexWithIndexParam) && count($querySuggestionsIndexWithIndexParam) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $querySuggestionsIndexWithIndexParam when calling createConfig' - ); - } - - $resourcePath = '/1/configs'; - $queryParams = []; - $httpBody = []; - - if (isset($querySuggestionsIndexWithIndexParam)) { - $httpBody = $querySuggestionsIndexWithIndexParam; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete a configuration of a Query Suggestion's index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse - */ - public function deleteConfig($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteConfig' - ); - } - - $resourcePath = '/1/configs/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get all the configurations of Query Suggestions. - * - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndex[] - */ - public function getAllConfigs() - { - $resourcePath = '/1/configs'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the configuration of a single Query Suggestions index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndex - */ - public function getConfig($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getConfig' - ); - } - - $resourcePath = '/1/configs/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the status of a Query Suggestion's index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\Status - */ - public function getConfigStatus($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getConfigStatus' - ); - } - - $resourcePath = '/1/configs/{indexName}/status'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the log file of the last build of a single Query Suggestion index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\LogFile[] - */ - public function getLogFile($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getLogFile' - ); - } - - $resourcePath = '/1/logs/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Update the configuration of a Query Suggestions index. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $querySuggestionsIndexParam querySuggestionsIndexParam (required) - * - $querySuggestionsIndexParam['sourceIndices'] => (array) List of source indices used to generate a Query Suggestions index. (required) - * - $querySuggestionsIndexParam['languages'] => (array) De-duplicate singular and plural suggestions. For example, let's say your index contains English content, and that two suggestions “shoe” and “shoes” end up in your Query Suggestions index. If the English language is configured, only the most popular of those two suggestions would remain. - * - $querySuggestionsIndexParam['exclude'] => (array) List of words and patterns to exclude from the Query Suggestions index. - * - * @see \Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndexParam - * - * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse - */ - public function updateConfig($indexName, $querySuggestionsIndexParam) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling updateConfig' - ); - } - // verify the required parameter 'querySuggestionsIndexParam' is set - if ($querySuggestionsIndexParam === null || (is_array($querySuggestionsIndexParam) && count($querySuggestionsIndexParam) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $querySuggestionsIndexParam when calling updateConfig' - ); - } - - $resourcePath = '/1/configs/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($querySuggestionsIndexParam)) { - $httpBody = $querySuggestionsIndexParam; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/RecommendApi.php b/clients/algoliasearch-client-php/lib/Api/RecommendApi.php deleted file mode 100644 index 0656d79e25..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/RecommendApi.php +++ /dev/null @@ -1,320 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - */ - public static function create($appId = null, $apiKey = null) - { - return static::createWithConfig(RecommendConfig::create($appId, $apiKey)); - } - - /** - * Instantiate the client with configuration - * - * @param RecommendConfig $config Configuration - */ - public static function createWithConfig(RecommendConfig $config) - { - $config = clone $config; - - $cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId()); - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) { - // We'll try to restore the ClusterHost from cache, if we cannot - // we create a new instance and set the cache key - $clusterHosts = ClusterHosts::createFromAppId($config->getAppId()) - ->setCacheKey($cacheKey); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return RecommendConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Returns recommendations for a specific model and objectID. - * - * @param array $getRecommendationsParams getRecommendationsParams (required) - * - $getRecommendationsParams['requests'] => (array) The `getRecommendations` requests. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Recommend\GetRecommendationsParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Recommend\GetRecommendationsResponse - */ - public function getRecommendations($getRecommendationsParams) - { - // verify the required parameter 'getRecommendationsParams' is set - if ($getRecommendationsParams === null || (is_array($getRecommendationsParams) && count($getRecommendationsParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $getRecommendationsParams when calling getRecommendations' - ); - } - - $resourcePath = '/1/indexes/*/recommendations'; - $queryParams = []; - $httpBody = []; - - if (isset($getRecommendationsParams)) { - $httpBody = $getRecommendationsParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/clients/algoliasearch-client-php/lib/Api/SearchApi.php b/clients/algoliasearch-client-php/lib/Api/SearchApi.php deleted file mode 100644 index 71c8ecb9c2..0000000000 --- a/clients/algoliasearch-client-php/lib/Api/SearchApi.php +++ /dev/null @@ -1,2713 +0,0 @@ -config = $config; - - $this->api = $apiWrapper; - } - - /** - * Instantiate the client with basic credentials - * - * @param string $appId Application ID - * @param string $apiKey Algolia API Key - */ - public static function create($appId = null, $apiKey = null) - { - return static::createWithConfig(SearchConfig::create($appId, $apiKey)); - } - - /** - * Instantiate the client with configuration - * - * @param SearchConfig $config Configuration - */ - public static function createWithConfig(SearchConfig $config) - { - $config = clone $config; - - $cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId()); - - if ($hosts = $config->getHosts()) { - // If a list of hosts was passed, we ignore the cache - $clusterHosts = ClusterHosts::create($hosts); - } elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) { - // We'll try to restore the ClusterHost from cache, if we cannot - // we create a new instance and set the cache key - $clusterHosts = ClusterHosts::createFromAppId($config->getAppId()) - ->setCacheKey($cacheKey); - } - - $apiWrapper = new ApiWrapper( - Algolia::getHttpClient(), - $config, - $clusterHosts - ); - - return new static($apiWrapper, $config); - } - - /** - * @return SearchConfig - */ - public function getClientConfig() - { - return $this->config; - } - - /** - * Create a new API key. - * - * @param array $apiKey apiKey (required) - * - $apiKey['acl'] => (array) Set of permissions associated with the key. (required) - * - $apiKey['description'] => (string) A comment used to identify a key more easily in the dashboard. It is not interpreted by the API. - * - $apiKey['indexes'] => (array) Restrict this new API key to a list of indices or index patterns. If the list is empty, all indices are allowed. - * - $apiKey['maxHitsPerQuery'] => (int) Maximum number of hits this API key can retrieve in one query. If zero, no limit is enforced. - * - $apiKey['maxQueriesPerIPPerHour'] => (int) Maximum number of API calls per hour allowed from a given IP address or a user token. - * - $apiKey['queryParameters'] => (string) URL-encoded query string. Force some query parameters to be applied for each query made with this API key. - * - $apiKey['referers'] => (array) Restrict this new API key to specific referers. If empty or blank, defaults to all referers. - * - $apiKey['validity'] => (int) Validity limit for this key in seconds. The key will automatically be removed after this period of time. - * - * @see \Algolia\AlgoliaSearch\Model\Search\ApiKey - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\AddApiKeyResponse - */ - public function addApiKey($apiKey) - { - // verify the required parameter 'apiKey' is set - if ($apiKey === null || (is_array($apiKey) && count($apiKey) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $apiKey when calling addApiKey' - ); - } - - $resourcePath = '/1/keys'; - $queryParams = []; - $httpBody = []; - - if (isset($apiKey)) { - $httpBody = $apiKey; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Add or replace an object with a given object ID. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param array $body The Algolia object. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtWithObjectIdResponse - */ - public function addOrUpdateObject($indexName, $objectID, $body) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling addOrUpdateObject' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling addOrUpdateObject' - ); - } - // verify the required parameter 'body' is set - if ($body === null || (is_array($body) && count($body) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $body when calling addOrUpdateObject' - ); - } - - $resourcePath = '/1/indexes/{indexName}/{objectID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Add a single source. - * - * @param array $source The source to add. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\Source - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse - */ - public function appendSource($source) - { - // verify the required parameter 'source' is set - if ($source === null || (is_array($source) && count($source) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $source when calling appendSource' - ); - } - - $resourcePath = '/1/security/sources/append'; - $queryParams = []; - $httpBody = []; - - if (isset($source)) { - $httpBody = $source; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Assign or Move userID - * - * @param string $xAlgoliaUserID userID to assign. (required) - * @param array $assignUserIdParams assignUserIdParams (required) - * - $assignUserIdParams['cluster'] => (string) Name of the cluster. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\AssignUserIdParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse - */ - public function assignUserId($xAlgoliaUserID, $assignUserIdParams) - { - // verify the required parameter 'xAlgoliaUserID' is set - if ($xAlgoliaUserID === null || (is_array($xAlgoliaUserID) && count($xAlgoliaUserID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $xAlgoliaUserID when calling assignUserId' - ); - } - if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) { - throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchApi.assignUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); - } - - // verify the required parameter 'assignUserIdParams' is set - if ($assignUserIdParams === null || (is_array($assignUserIdParams) && count($assignUserIdParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $assignUserIdParams when calling assignUserId' - ); - } - - $resourcePath = '/1/clusters/mapping'; - $queryParams = []; - $httpBody = []; - - if ($xAlgoliaUserID !== null) { - if ('form' === 'form' && is_array($xAlgoliaUserID)) { - foreach ($xAlgoliaUserID as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['X-Algolia-User-ID'] = $xAlgoliaUserID; - } - } - - if (isset($assignUserIdParams)) { - $httpBody = $assignUserIdParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Performs multiple write operations in a single API call. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $batchWriteParams batchWriteParams (required) - * - $batchWriteParams['requests'] => (array) - * - * @see \Algolia\AlgoliaSearch\Model\Search\BatchWriteParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\BatchResponse - */ - public function batch($indexName, $batchWriteParams) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling batch' - ); - } - // verify the required parameter 'batchWriteParams' is set - if ($batchWriteParams === null || (is_array($batchWriteParams) && count($batchWriteParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $batchWriteParams when calling batch' - ); - } - - $resourcePath = '/1/indexes/{indexName}/batch'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($batchWriteParams)) { - $httpBody = $batchWriteParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Batch assign userIDs - * - * @param string $xAlgoliaUserID userID to assign. (required) - * @param array $batchAssignUserIdsParams batchAssignUserIdsParams (required) - * - $batchAssignUserIdsParams['cluster'] => (string) Name of the cluster. (required) - * - $batchAssignUserIdsParams['users'] => (array) userIDs to assign. Note you cannot move users with this method. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\BatchAssignUserIdsParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse - */ - public function batchAssignUserIds($xAlgoliaUserID, $batchAssignUserIdsParams) - { - // verify the required parameter 'xAlgoliaUserID' is set - if ($xAlgoliaUserID === null || (is_array($xAlgoliaUserID) && count($xAlgoliaUserID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $xAlgoliaUserID when calling batchAssignUserIds' - ); - } - if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) { - throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchApi.batchAssignUserIds, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); - } - - // verify the required parameter 'batchAssignUserIdsParams' is set - if ($batchAssignUserIdsParams === null || (is_array($batchAssignUserIdsParams) && count($batchAssignUserIdsParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $batchAssignUserIdsParams when calling batchAssignUserIds' - ); - } - - $resourcePath = '/1/clusters/mapping/batch'; - $queryParams = []; - $httpBody = []; - - if ($xAlgoliaUserID !== null) { - if ('form' === 'form' && is_array($xAlgoliaUserID)) { - foreach ($xAlgoliaUserID as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['X-Algolia-User-ID'] = $xAlgoliaUserID; - } - } - - if (isset($batchAssignUserIdsParams)) { - $httpBody = $batchAssignUserIdsParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send a batch of dictionary entries. - * - * @param array $dictionaryName The dictionary to search in. (required) - * @param array $batchDictionaryEntriesParams batchDictionaryEntriesParams (required) - * - $batchDictionaryEntriesParams['clearExistingDictionaryEntries'] => (bool) When `true`, start the batch by removing all the custom entries from the dictionary. - * - $batchDictionaryEntriesParams['requests'] => (array) List of operations to batch. Each operation is described by an `action` and a `body`. (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\BatchDictionaryEntriesParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function batchDictionaryEntries($dictionaryName, $batchDictionaryEntriesParams) - { - // verify the required parameter 'dictionaryName' is set - if ($dictionaryName === null || (is_array($dictionaryName) && count($dictionaryName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $dictionaryName when calling batchDictionaryEntries' - ); - } - // verify the required parameter 'batchDictionaryEntriesParams' is set - if ($batchDictionaryEntriesParams === null || (is_array($batchDictionaryEntriesParams) && count($batchDictionaryEntriesParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $batchDictionaryEntriesParams when calling batchDictionaryEntries' - ); - } - - $resourcePath = '/1/dictionaries/{dictionaryName}/batch'; - $queryParams = []; - $httpBody = []; - - // path params - if ($dictionaryName !== null) { - $resourcePath = str_replace( - '{dictionaryName}', - ObjectSerializer::toPathValue($dictionaryName), - $resourcePath - ); - } - - if (isset($batchDictionaryEntriesParams)) { - $httpBody = $batchDictionaryEntriesParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Batch Rules. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $rule rule (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * @param bool $clearExistingRules When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function batchRules($indexName, $rule, $forwardToReplicas = null, $clearExistingRules = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling batchRules' - ); - } - // verify the required parameter 'rule' is set - if ($rule === null || (is_array($rule) && count($rule) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $rule when calling batchRules' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/batch'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - if ($clearExistingRules !== null) { - if ('form' === 'form' && is_array($clearExistingRules)) { - foreach ($clearExistingRules as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['clearExistingRules'] = $clearExistingRules; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($rule)) { - $httpBody = $rule; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Retrieve all index content. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $browseRequest browseRequest (optional) - * - $browseRequest['params'] => (string) Search parameters as URL-encoded query string. - * - $browseRequest['cursor'] => (string) Cursor indicating the location to resume browsing from. Must match the value returned by the previous call. - * - * @see \Algolia\AlgoliaSearch\Model\Search\BrowseRequest - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\BrowseResponse - */ - public function browse($indexName, $browseRequest = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling browse' - ); - } - - $resourcePath = '/1/indexes/{indexName}/browse'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($browseRequest)) { - $httpBody = $browseRequest; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Clear all synonyms. - * - * @param string $indexName The index in which to perform the request. (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function clearAllSynonyms($indexName, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling clearAllSynonyms' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/clear'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * clear all objects from an index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function clearObjects($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling clearObjects' - ); - } - - $resourcePath = '/1/indexes/{indexName}/clear'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Clear Rules. - * - * @param string $indexName The index in which to perform the request. (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function clearRules($indexName, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling clearRules' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/clear'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function del($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling del' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete an API key. - * - * @param string $key API Key string. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeleteApiKeyResponse - */ - public function deleteApiKey($key) - { - // verify the required parameter 'key' is set - if ($key === null || (is_array($key) && count($key) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $key when calling deleteApiKey' - ); - } - - $resourcePath = '/1/keys/{key}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($key !== null) { - $resourcePath = str_replace( - '{key}', - ObjectSerializer::toPathValue($key), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete all records matching the query. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $searchParams searchParams (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse - */ - public function deleteBy($indexName, $searchParams) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteBy' - ); - } - // verify the required parameter 'searchParams' is set - if ($searchParams === null || (is_array($searchParams) && count($searchParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $searchParams when calling deleteBy' - ); - } - - $resourcePath = '/1/indexes/{indexName}/deleteByQuery'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($searchParams)) { - $httpBody = $searchParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete index. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse - */ - public function deleteIndex($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteIndex' - ); - } - - $resourcePath = '/1/indexes/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete object. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse - */ - public function deleteObject($indexName, $objectID) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteObject' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling deleteObject' - ); - } - - $resourcePath = '/1/indexes/{indexName}/{objectID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete a rule. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function deleteRule($indexName, $objectID, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteRule' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling deleteRule' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Remove a single source. - * - * @param string $source The IP range of the source. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeleteSourceResponse - */ - public function deleteSource($source) - { - // verify the required parameter 'source' is set - if ($source === null || (is_array($source) && count($source) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $source when calling deleteSource' - ); - } - - $resourcePath = '/1/security/sources/{source}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($source !== null) { - $resourcePath = str_replace( - '{source}', - ObjectSerializer::toPathValue($source), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Delete synonym. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse - */ - public function deleteSynonym($indexName, $objectID, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling deleteSynonym' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling deleteSynonym' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * - * @return array|object - */ - public function get($path, $parameters = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling get' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get an API key. - * - * @param string $key API Key string. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\Key - */ - public function getApiKey($key) - { - // verify the required parameter 'key' is set - if ($key === null || (is_array($key) && count($key) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $key when calling getApiKey' - ); - } - - $resourcePath = '/1/keys/{key}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($key !== null) { - $resourcePath = str_replace( - '{key}', - ObjectSerializer::toPathValue($key), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * List dictionaries supported per language. - * - * - * @return array|array - */ - public function getDictionaryLanguages() - { - $resourcePath = '/1/dictionaries/*/languages'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values. - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\GetDictionarySettingsResponse - */ - public function getDictionarySettings() - { - $resourcePath = '/1/dictionaries/*/settings'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Return the lastest log entries. - * - * @param int $offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. (optional, default to 0) - * @param int $length Maximum number of entries to retrieve. The maximum allowed value is 1000. (optional, default to 10) - * @param string $indexName Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. (optional) - * @param array $type Type of log entries to retrieve. When omitted, all log entries are retrieved. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\GetLogsResponse - */ - public function getLogs($offset = 0, $length = 10, $indexName = null, $type = null) - { - if ($length !== null && $length > 1000) { - throw new \InvalidArgumentException('invalid value for "$length" when calling SearchApi.getLogs, must be smaller than or equal to 1000.'); - } - - $resourcePath = '/1/logs'; - $queryParams = []; - $httpBody = []; - - if ($offset !== null) { - if ('form' === 'form' && is_array($offset)) { - foreach ($offset as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['offset'] = $offset; - } - } - - if ($length !== null) { - if ('form' === 'form' && is_array($length)) { - foreach ($length as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['length'] = $length; - } - } - - if ($indexName !== null) { - if ('form' === 'form' && is_array($indexName)) { - foreach ($indexName as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['indexName'] = $indexName; - } - } - - if ($type !== null) { - if ('form' === 'form' && is_array($type)) { - foreach ($type as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['type'] = $type; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Retrieve one object from the index. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param array $attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable attributes are returned. (optional) - * - * @return array|array - */ - public function getObject($indexName, $objectID, $attributesToRetrieve = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getObject' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling getObject' - ); - } - - $resourcePath = '/1/indexes/{indexName}/{objectID}'; - $queryParams = []; - $httpBody = []; - - if ($attributesToRetrieve !== null) { - if ('form' === 'form' && is_array($attributesToRetrieve)) { - foreach ($attributesToRetrieve as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['attributesToRetrieve'] = $attributesToRetrieve; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Retrieve one or more objects. - * - * @param array $getObjectsParams getObjectsParams (required) - * - $getObjectsParams['requests'] => (array) - * - * @see \Algolia\AlgoliaSearch\Model\Search\GetObjectsParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\GetObjectsResponse - */ - public function getObjects($getObjectsParams) - { - // verify the required parameter 'getObjectsParams' is set - if ($getObjectsParams === null || (is_array($getObjectsParams) && count($getObjectsParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $getObjectsParams when calling getObjects' - ); - } - - $resourcePath = '/1/indexes/*/objects'; - $queryParams = []; - $httpBody = []; - - if (isset($getObjectsParams)) { - $httpBody = $getObjectsParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get a rule. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\Rule - */ - public function getRule($indexName, $objectID) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getRule' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling getRule' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Retrieve settings of a given indexName. - * - * @param string $indexName The index in which to perform the request. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\IndexSettings - */ - public function getSettings($indexName) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getSettings' - ); - } - - $resourcePath = '/1/indexes/{indexName}/settings'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * List all allowed sources. - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\Source[] - */ - public function getSources() - { - $resourcePath = '/1/security/sources'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get synonym. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SynonymHit - */ - public function getSynonym($indexName, $objectID) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getSynonym' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling getSynonym' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Check the current status of a given task. - * - * @param string $indexName The index in which to perform the request. (required) - * @param int $taskID Unique identifier of an task. Numeric value (up to 64bits). (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\GetTaskResponse - */ - public function getTask($indexName, $taskID) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling getTask' - ); - } - // verify the required parameter 'taskID' is set - if ($taskID === null || (is_array($taskID) && count($taskID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $taskID when calling getTask' - ); - } - - $resourcePath = '/1/indexes/{indexName}/task/{taskID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($taskID !== null) { - $resourcePath = str_replace( - '{taskID}', - ObjectSerializer::toPathValue($taskID), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get top userID - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\GetTopUserIdsResponse - */ - public function getTopUserIds() - { - $resourcePath = '/1/clusters/mapping/top'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get userID - * - * @param string $userID userID to assign. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UserId - */ - public function getUserId($userID) - { - // verify the required parameter 'userID' is set - if ($userID === null || (is_array($userID) && count($userID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $userID when calling getUserId' - ); - } - if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $userID)) { - throw new \InvalidArgumentException('invalid value for "userID" when calling SearchApi.getUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); - } - - $resourcePath = '/1/clusters/mapping/{userID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($userID !== null) { - $resourcePath = str_replace( - '{userID}', - ObjectSerializer::toPathValue($userID), - $resourcePath - ); - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Has pending mappings - * - * @param bool $getClusters Whether to get clusters or not. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse - */ - public function hasPendingMappings($getClusters = null) - { - $resourcePath = '/1/clusters/mapping/pending'; - $queryParams = []; - $httpBody = []; - - if ($getClusters !== null) { - if ('form' === 'form' && is_array($getClusters)) { - foreach ($getClusters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['getClusters'] = $getClusters; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get the full list of API Keys. - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\ListApiKeysResponse - */ - public function listApiKeys() - { - $resourcePath = '/1/keys'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * List clusters - * - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\ListClustersResponse - */ - public function listClusters() - { - $resourcePath = '/1/clusters'; - $queryParams = []; - $httpBody = []; - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * List existing indexes. - * - * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\ListIndicesResponse - */ - public function listIndices($page = null) - { - $resourcePath = '/1/indexes'; - $queryParams = []; - $httpBody = []; - - if ($page !== null) { - if ('form' === 'form' && is_array($page)) { - foreach ($page as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['page'] = $page; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * List userIDs - * - * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional) - * @param int $hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\ListUserIdsResponse - */ - public function listUserIds($page = null, $hitsPerPage = 100) - { - $resourcePath = '/1/clusters/mapping'; - $queryParams = []; - $httpBody = []; - - if ($page !== null) { - if ('form' === 'form' && is_array($page)) { - foreach ($page as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['page'] = $page; - } - } - - if ($hitsPerPage !== null) { - if ('form' === 'form' && is_array($hitsPerPage)) { - foreach ($hitsPerPage as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['hitsPerPage'] = $hitsPerPage; - } - } - - return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); - } - - /** - * Perform multiple write operations. - * - * @param array $batchParams batchParams (required) - * - $batchParams['requests'] => (array) - * - * @see \Algolia\AlgoliaSearch\Model\Search\BatchParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\MultipleBatchResponse - */ - public function multipleBatch($batchParams) - { - // verify the required parameter 'batchParams' is set - if ($batchParams === null || (is_array($batchParams) && count($batchParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $batchParams when calling multipleBatch' - ); - } - - $resourcePath = '/1/indexes/*/batch'; - $queryParams = []; - $httpBody = []; - - if (isset($batchParams)) { - $httpBody = $batchParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get search results for the given requests. - * - * @param array $multipleQueriesParams multipleQueriesParams (required) - * - $multipleQueriesParams['requests'] => (array) (required) - * - $multipleQueriesParams['strategy'] => (array) - * - * @see \Algolia\AlgoliaSearch\Model\Search\MultipleQueriesParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\MultipleQueriesResponse - */ - public function multipleQueries($multipleQueriesParams) - { - // verify the required parameter 'multipleQueriesParams' is set - if ($multipleQueriesParams === null || (is_array($multipleQueriesParams) && count($multipleQueriesParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $multipleQueriesParams when calling multipleQueries' - ); - } - - $resourcePath = '/1/indexes/*/queries'; - $queryParams = []; - $httpBody = []; - - if (isset($multipleQueriesParams)) { - $httpBody = $multipleQueriesParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Copy/move index. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $operationIndexParams operationIndexParams (required) - * - $operationIndexParams['operation'] => (array) (required) - * - $operationIndexParams['destination'] => (string) The Algolia index name. (required) - * - $operationIndexParams['scope'] => (array) Scope of the data to copy. When absent, a full copy is performed. When present, only the selected scopes are copied. - * - * @see \Algolia\AlgoliaSearch\Model\Search\OperationIndexParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function operationIndex($indexName, $operationIndexParams) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling operationIndex' - ); - } - // verify the required parameter 'operationIndexParams' is set - if ($operationIndexParams === null || (is_array($operationIndexParams) && count($operationIndexParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $operationIndexParams when calling operationIndex' - ); - } - - $resourcePath = '/1/indexes/{indexName}/operation'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($operationIndexParams)) { - $httpBody = $operationIndexParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Partially update an object. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param array $attributeOrBuiltInOperation List of attributes to update. (required) - * @param bool $createIfNotExists Creates the record if it does not exist yet. (optional, default to true) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtWithObjectIdResponse - */ - public function partialUpdateObject($indexName, $objectID, $attributeOrBuiltInOperation, $createIfNotExists = true) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling partialUpdateObject' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling partialUpdateObject' - ); - } - // verify the required parameter 'attributeOrBuiltInOperation' is set - if ($attributeOrBuiltInOperation === null || (is_array($attributeOrBuiltInOperation) && count($attributeOrBuiltInOperation) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $attributeOrBuiltInOperation when calling partialUpdateObject' - ); - } - - $resourcePath = '/1/indexes/{indexName}/{objectID}/partial'; - $queryParams = []; - $httpBody = []; - - if ($createIfNotExists !== null) { - if ('form' === 'form' && is_array($createIfNotExists)) { - foreach ($createIfNotExists as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['createIfNotExists'] = $createIfNotExists; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - if (isset($attributeOrBuiltInOperation)) { - $httpBody = $attributeOrBuiltInOperation; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function post($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling post' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Send requests to the Algolia REST API. - * - * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) - * @param array $parameters Query parameters to be applied to the current query. (optional) - * @param array $body The parameters to send with the custom request. (optional) - * - * @return array|object - */ - public function put($path, $parameters = null, $body = null) - { - // verify the required parameter 'path' is set - if ($path === null || (is_array($path) && count($path) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $path when calling put' - ); - } - - $resourcePath = '/1{path}'; - $queryParams = []; - $httpBody = []; - - if ($parameters !== null) { - if ('form' === 'form' && is_array($parameters)) { - foreach ($parameters as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams = $parameters; - } - } - - // path params - if ($path !== null) { - $resourcePath = str_replace( - '{path}', - $path, - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Remove userID - * - * @param string $userID userID to assign. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\RemoveUserIdResponse - */ - public function removeUserId($userID) - { - // verify the required parameter 'userID' is set - if ($userID === null || (is_array($userID) && count($userID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $userID when calling removeUserId' - ); - } - if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $userID)) { - throw new \InvalidArgumentException('invalid value for "userID" when calling SearchApi.removeUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); - } - - $resourcePath = '/1/clusters/mapping/{userID}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($userID !== null) { - $resourcePath = str_replace( - '{userID}', - ObjectSerializer::toPathValue($userID), - $resourcePath - ); - } - - return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); - } - - /** - * Replace all allowed sources. - * - * @param array $source The sources to allow. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\ReplaceSourceResponse - */ - public function replaceSources($source) - { - // verify the required parameter 'source' is set - if ($source === null || (is_array($source) && count($source) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $source when calling replaceSources' - ); - } - - $resourcePath = '/1/security/sources'; - $queryParams = []; - $httpBody = []; - - if (isset($source)) { - $httpBody = $source; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Restore an API key. - * - * @param string $key API Key string. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\AddApiKeyResponse - */ - public function restoreApiKey($key) - { - // verify the required parameter 'key' is set - if ($key === null || (is_array($key) && count($key) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $key when calling restoreApiKey' - ); - } - - $resourcePath = '/1/keys/{key}/restore'; - $queryParams = []; - $httpBody = []; - - // path params - if ($key !== null) { - $resourcePath = str_replace( - '{key}', - ObjectSerializer::toPathValue($key), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Add an object to the index. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $body The Algolia record. (required) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SaveObjectResponse - */ - public function saveObject($indexName, $body) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling saveObject' - ); - } - // verify the required parameter 'body' is set - if ($body === null || (is_array($body) && count($body) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $body when calling saveObject' - ); - } - - $resourcePath = '/1/indexes/{indexName}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($body)) { - $httpBody = $body; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Save/Update a rule. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param array $rule rule (required) - * - $rule['objectID'] => (string) Unique identifier of the object. (required) - * - $rule['conditions'] => (array) A list of conditions that should apply to activate a Rule. You can use up to 25 conditions per Rule. - * - $rule['consequence'] => (array) (required) - * - $rule['description'] => (string) This field is intended for Rule management purposes, in particular to ease searching for Rules and presenting them to human readers. It's not interpreted by the API. - * - $rule['enabled'] => (bool) Whether the Rule is enabled. Disabled Rules remain in the index, but aren't applied at query time. - * - $rule['validity'] => (array) By default, Rules are permanently valid. When validity periods are specified, the Rule applies only during those periods; it's ignored the rest of the time. The list must not be empty. - * - * @see \Algolia\AlgoliaSearch\Model\Search\Rule - * - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedRuleResponse - */ - public function saveRule($indexName, $objectID, $rule, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling saveRule' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling saveRule' - ); - } - // verify the required parameter 'rule' is set - if ($rule === null || (is_array($rule) && count($rule) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $rule when calling saveRule' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - if (isset($rule)) { - $httpBody = $rule; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Save synonym. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $objectID Unique identifier of an object. (required) - * @param array $synonymHit synonymHit (required) - * - $synonymHit['objectID'] => (string) Unique identifier of the synonym object to be created or updated. (required) - * - $synonymHit['type'] => (array) - * - $synonymHit['synonyms'] => (array) Words or phrases to be considered equivalent. - * - $synonymHit['input'] => (string) Word or phrase to appear in query strings (for onewaysynonym). - * - $synonymHit['word'] => (string) Word or phrase to appear in query strings (for altcorrection1 and altcorrection2). - * - $synonymHit['corrections'] => (array) Words to be matched in records. - * - $synonymHit['placeholder'] => (string) Token to be put inside records. - * - $synonymHit['replacements'] => (array) List of query words that will match the token. - * - $synonymHit['_highlightResult'] => (array) - * - * @see \Algolia\AlgoliaSearch\Model\Search\SynonymHit - * - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SaveSynonymResponse - */ - public function saveSynonym($indexName, $objectID, $synonymHit, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling saveSynonym' - ); - } - // verify the required parameter 'objectID' is set - if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $objectID when calling saveSynonym' - ); - } - // verify the required parameter 'synonymHit' is set - if ($synonymHit === null || (is_array($synonymHit) && count($synonymHit) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $synonymHit when calling saveSynonym' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($objectID !== null) { - $resourcePath = str_replace( - '{objectID}', - ObjectSerializer::toPathValue($objectID), - $resourcePath - ); - } - - if (isset($synonymHit)) { - $httpBody = $synonymHit; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Save a batch of synonyms. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $synonymHit synonymHit (required) - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * @param bool $replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this request. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function saveSynonyms($indexName, $synonymHit, $forwardToReplicas = null, $replaceExistingSynonyms = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling saveSynonyms' - ); - } - // verify the required parameter 'synonymHit' is set - if ($synonymHit === null || (is_array($synonymHit) && count($synonymHit) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $synonymHit when calling saveSynonyms' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/batch'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - if ($replaceExistingSynonyms !== null) { - if ('form' === 'form' && is_array($replaceExistingSynonyms)) { - foreach ($replaceExistingSynonyms as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['replaceExistingSynonyms'] = $replaceExistingSynonyms; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($synonymHit)) { - $httpBody = $synonymHit; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get search results. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $searchParams searchParams (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchResponse - */ - public function search($indexName, $searchParams) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling search' - ); - } - // verify the required parameter 'searchParams' is set - if ($searchParams === null || (is_array($searchParams) && count($searchParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $searchParams when calling search' - ); - } - - $resourcePath = '/1/indexes/{indexName}/query'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($searchParams)) { - $httpBody = $searchParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Search the dictionary entries. - * - * @param array $dictionaryName The dictionary to search in. (required) - * @param array $searchDictionaryEntriesParams searchDictionaryEntriesParams (required) - * - $searchDictionaryEntriesParams['query'] => (string) The text to search in the index. (required) - * - $searchDictionaryEntriesParams['page'] => (int) Specify the page to retrieve. - * - $searchDictionaryEntriesParams['hitsPerPage'] => (int) Set the number of hits per page. - * - $searchDictionaryEntriesParams['language'] => (string) Language ISO code supported by the dictionary (e.g., \"en\" for English). - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchDictionaryEntriesParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function searchDictionaryEntries($dictionaryName, $searchDictionaryEntriesParams) - { - // verify the required parameter 'dictionaryName' is set - if ($dictionaryName === null || (is_array($dictionaryName) && count($dictionaryName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $dictionaryName when calling searchDictionaryEntries' - ); - } - // verify the required parameter 'searchDictionaryEntriesParams' is set - if ($searchDictionaryEntriesParams === null || (is_array($searchDictionaryEntriesParams) && count($searchDictionaryEntriesParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $searchDictionaryEntriesParams when calling searchDictionaryEntries' - ); - } - - $resourcePath = '/1/dictionaries/{dictionaryName}/search'; - $queryParams = []; - $httpBody = []; - - // path params - if ($dictionaryName !== null) { - $resourcePath = str_replace( - '{dictionaryName}', - ObjectSerializer::toPathValue($dictionaryName), - $resourcePath - ); - } - - if (isset($searchDictionaryEntriesParams)) { - $httpBody = $searchDictionaryEntriesParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Search for values of a given facet - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $facetName The facet name. (required) - * @param array $searchForFacetValuesRequest searchForFacetValuesRequest (optional) - * - $searchForFacetValuesRequest['params'] => (string) Search parameters as URL-encoded query string. - * - $searchForFacetValuesRequest['facetQuery'] => (string) Text to search inside the facet's values. - * - $searchForFacetValuesRequest['maxFacetHits'] => (int) Maximum number of facet hits to return during a search for facet values. For performance reasons, the maximum allowed number of returned values is 100. - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchForFacetValuesRequest - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchForFacetValuesResponse - */ - public function searchForFacetValues($indexName, $facetName, $searchForFacetValuesRequest = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling searchForFacetValues' - ); - } - // verify the required parameter 'facetName' is set - if ($facetName === null || (is_array($facetName) && count($facetName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $facetName when calling searchForFacetValues' - ); - } - - $resourcePath = '/1/indexes/{indexName}/facets/{facetName}/query'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - // path params - if ($facetName !== null) { - $resourcePath = str_replace( - '{facetName}', - ObjectSerializer::toPathValue($facetName), - $resourcePath - ); - } - - if (isset($searchForFacetValuesRequest)) { - $httpBody = $searchForFacetValuesRequest; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Search for rules. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $searchRulesParams searchRulesParams (required) - * - $searchRulesParams['query'] => (string) Full text query. - * - $searchRulesParams['anchoring'] => (array) - * - $searchRulesParams['context'] => (string) Restricts matches to contextual rules with a specific context (exact match). - * - $searchRulesParams['page'] => (int) Requested page (zero-based). - * - $searchRulesParams['hitsPerPage'] => (int) Maximum number of hits in a page. Minimum is 1, maximum is 1000. - * - $searchRulesParams['enabled'] => (bool) When specified, restricts matches to rules with a specific enabled status. When absent (default), all rules are retrieved, regardless of their enabled status. - * - $searchRulesParams['requestOptions'] => (array) A mapping of requestOptions to send along with the request. - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchRulesParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchRulesResponse - */ - public function searchRules($indexName, $searchRulesParams) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling searchRules' - ); - } - // verify the required parameter 'searchRulesParams' is set - if ($searchRulesParams === null || (is_array($searchRulesParams) && count($searchRulesParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $searchRulesParams when calling searchRules' - ); - } - - $resourcePath = '/1/indexes/{indexName}/rules/search'; - $queryParams = []; - $httpBody = []; - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($searchRulesParams)) { - $httpBody = $searchRulesParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Get all synonyms that match a query. - * - * @param string $indexName The index in which to perform the request. (required) - * @param string $query Search for specific synonyms matching this string. (optional, default to '') - * @param array $type Only search for specific types of synonyms. (optional) - * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional, default to 0) - * @param int $hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchSynonymsResponse - */ - public function searchSynonyms($indexName, $query = '', $type = null, $page = 0, $hitsPerPage = 100) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling searchSynonyms' - ); - } - - $resourcePath = '/1/indexes/{indexName}/synonyms/search'; - $queryParams = []; - $httpBody = []; - - if ($query !== null) { - if ('form' === 'form' && is_array($query)) { - foreach ($query as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['query'] = $query; - } - } - - if ($type !== null) { - if ('form' === 'form' && is_array($type)) { - foreach ($type as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['type'] = $type; - } - } - - if ($page !== null) { - if ('form' === 'form' && is_array($page)) { - foreach ($page as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['page'] = $page; - } - } - - if ($hitsPerPage !== null) { - if ('form' === 'form' && is_array($hitsPerPage)) { - foreach ($hitsPerPage as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['hitsPerPage'] = $hitsPerPage; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Search userID - * - * @param array $searchUserIdsParams searchUserIdsParams (required) - * - $searchUserIdsParams['query'] => (string) Query to search. The search is a prefix search with typoTolerance. Use empty query to retrieve all users. (required) - * - $searchUserIdsParams['clusterName'] => (string) Name of the cluster. - * - $searchUserIdsParams['page'] => (int) Specify the page to retrieve. - * - $searchUserIdsParams['hitsPerPage'] => (int) Set the number of hits per page. - * - * @see \Algolia\AlgoliaSearch\Model\Search\SearchUserIdsParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchUserIdsResponse - */ - public function searchUserIds($searchUserIdsParams) - { - // verify the required parameter 'searchUserIdsParams' is set - if ($searchUserIdsParams === null || (is_array($searchUserIdsParams) && count($searchUserIdsParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $searchUserIdsParams when calling searchUserIds' - ); - } - - $resourcePath = '/1/clusters/mapping/search'; - $queryParams = []; - $httpBody = []; - - if (isset($searchUserIdsParams)) { - $httpBody = $searchUserIdsParams; - } - - return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); - } - - /** - * Set dictionary settings. - * - * @param array $dictionarySettingsParams dictionarySettingsParams (required) - * - $dictionarySettingsParams['disableStandardEntries'] => (array) (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\DictionarySettingsParams - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function setDictionarySettings($dictionarySettingsParams) - { - // verify the required parameter 'dictionarySettingsParams' is set - if ($dictionarySettingsParams === null || (is_array($dictionarySettingsParams) && count($dictionarySettingsParams) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $dictionarySettingsParams when calling setDictionarySettings' - ); - } - - $resourcePath = '/1/dictionaries/*/settings'; - $queryParams = []; - $httpBody = []; - - if (isset($dictionarySettingsParams)) { - $httpBody = $dictionarySettingsParams; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Update settings of a given indexName. - * - * @param string $indexName The index in which to perform the request. (required) - * @param array $indexSettings indexSettings (required) - * - * @see \Algolia\AlgoliaSearch\Model\Search\IndexSettings - * - * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse - */ - public function setSettings($indexName, $indexSettings, $forwardToReplicas = null) - { - // verify the required parameter 'indexName' is set - if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexName when calling setSettings' - ); - } - // verify the required parameter 'indexSettings' is set - if ($indexSettings === null || (is_array($indexSettings) && count($indexSettings) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $indexSettings when calling setSettings' - ); - } - - $resourcePath = '/1/indexes/{indexName}/settings'; - $queryParams = []; - $httpBody = []; - - if ($forwardToReplicas !== null) { - if ('form' === 'form' && is_array($forwardToReplicas)) { - foreach ($forwardToReplicas as $key => $value) { - $queryParams[$key] = $value; - } - } else { - $queryParams['forwardToReplicas'] = $forwardToReplicas; - } - } - - // path params - if ($indexName !== null) { - $resourcePath = str_replace( - '{indexName}', - ObjectSerializer::toPathValue($indexName), - $resourcePath - ); - } - - if (isset($indexSettings)) { - $httpBody = $indexSettings; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - /** - * Update an API key. - * - * @param string $key API Key string. (required) - * @param array $apiKey apiKey (required) - * - $apiKey['acl'] => (array) Set of permissions associated with the key. (required) - * - $apiKey['description'] => (string) A comment used to identify a key more easily in the dashboard. It is not interpreted by the API. - * - $apiKey['indexes'] => (array) Restrict this new API key to a list of indices or index patterns. If the list is empty, all indices are allowed. - * - $apiKey['maxHitsPerQuery'] => (int) Maximum number of hits this API key can retrieve in one query. If zero, no limit is enforced. - * - $apiKey['maxQueriesPerIPPerHour'] => (int) Maximum number of API calls per hour allowed from a given IP address or a user token. - * - $apiKey['queryParameters'] => (string) URL-encoded query string. Force some query parameters to be applied for each query made with this API key. - * - $apiKey['referers'] => (array) Restrict this new API key to specific referers. If empty or blank, defaults to all referers. - * - $apiKey['validity'] => (int) Validity limit for this key in seconds. The key will automatically be removed after this period of time. - * - * @see \Algolia\AlgoliaSearch\Model\Search\ApiKey - * - * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdateApiKeyResponse - */ - public function updateApiKey($key, $apiKey) - { - // verify the required parameter 'key' is set - if ($key === null || (is_array($key) && count($key) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $key when calling updateApiKey' - ); - } - // verify the required parameter 'apiKey' is set - if ($apiKey === null || (is_array($apiKey) && count($apiKey) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $apiKey when calling updateApiKey' - ); - } - - $resourcePath = '/1/keys/{key}'; - $queryParams = []; - $httpBody = []; - - // path params - if ($key !== null) { - $resourcePath = str_replace( - '{key}', - ObjectSerializer::toPathValue($key), - $resourcePath - ); - } - - if (isset($apiKey)) { - $httpBody = $apiKey; - } - - return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); - } - - private function sendRequest($method, $resourcePath, $queryParams, $httpBody) - { - $query = \GuzzleHttp\Psr7\Query::build($queryParams); - - if ($method === 'GET') { - $request = $this->api->read( - $method, - $resourcePath . ($query ? "?{$query}" : '') - ); - } else { - $request = $this->api->write( - $method, - $resourcePath . ($query ? "?{$query}" : ''), - $httpBody - ); - } - - return $request; - } -} diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index aed746e6a3..c79280a196 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -227,7 +227,9 @@ public void processOpts() { // generator specific options setDateLibrary("java8"); setSourceFolder("algoliasearch-core"); + setApiNameSuffix(Utils.API_SUFFIX); + additionalProperties.put("apiNameSuffix", Utils.API_SUFFIX); additionalProperties.put("java8", true); additionalProperties.put("sourceFolder", "algoliasearch-core"); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 9858f4a4df..c23e54fc88 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -12,6 +12,8 @@ public class AlgoliaJavascriptGenerator extends TypeScriptNodeClientCodegen { + private String CLIENT; + @Override public String getName() { return "algolia-javascript"; @@ -53,12 +55,12 @@ public void processOpts() { /** Set default generator options */ private void setDefaultGeneratorOptions(Map client) { - String spec = (String) client.get("pathPrefix"); - String apiName = spec + "Api"; + CLIENT = (String) client.get("pathPrefix"); + String apiName = CLIENT + Utils.API_SUFFIX; additionalProperties.put("apiName", apiName); additionalProperties.put("capitalizedApiName", Utils.capitalize(apiName)); - additionalProperties.put("userAgent", Utils.capitalize(spec)); + additionalProperties.put("userAgent", Utils.capitalize(CLIENT)); } /** Provides an opportunity to inspect and modify operation data before the code is generated. */ @@ -80,6 +82,37 @@ public Map postProcessOperationsWithModels( return results; } + /** + * The `apiSuffix` option is not supported on the TypeScript client, so we override the names + * method to use it with our suffix. + */ + + /** The `apiName` is capitalized. */ + @Override + public String toApiName(String name) { + if (name.length() == 0) { + return "Default" + Utils.API_SUFFIX; + } + + return Utils.capitalize(CLIENT + Utils.API_SUFFIX); + } + + /** The `apiFileName` is in camelCase. */ + @Override + public String toApiFilename(String name) { + if (name.length() == 0) { + return "default" + Utils.API_SUFFIX; + } + + return CLIENT + Utils.API_SUFFIX; + } + + /** The `apiFileName` is in camelCase. */ + @Override + public String apiFilename(String templateName, String tag) { + return super.apiFilename(templateName, toApiFilename(CLIENT)); + } + @Override public CodegenOperation fromOperation( String path, diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java index 7745eebf6c..1991dd88f2 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java @@ -65,7 +65,9 @@ public void processOpts() { super.processOpts(); // generator specific options + setApiNameSuffix(Utils.API_SUFFIX); setParameterNamingConvention("camelCase"); + additionalProperties.put("apiNameSuffix", Utils.API_SUFFIX); // Remove base template as we want to change its path supportingFiles.removeIf(file -> diff --git a/generators/src/main/java/com/algolia/codegen/Utils.java b/generators/src/main/java/com/algolia/codegen/Utils.java index 6613c88f9e..947dfd4600 100644 --- a/generators/src/main/java/com/algolia/codegen/Utils.java +++ b/generators/src/main/java/com/algolia/codegen/Utils.java @@ -6,6 +6,9 @@ public class Utils { + /** The suffix of our client names. */ + public static final String API_SUFFIX = "Client"; + public static final Set CUSTOM_METHOD = Sets.newHashSet( "del", "get", diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index 75cf619dae..302de41084 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -131,7 +131,7 @@ public Map postProcessSupportingFileData( // We can put whatever we want in the bundle, and it will be accessible in the // template - bundle.put("client", Utils.createClientName(client, language) + "Api"); + bundle.put("client", Utils.createClientName(client, language) + "Client"); bundle.put("import", createImportName()); bundle.put("hasRegionalHost", hasRegionalHost); bundle.put("lambda", lambda); diff --git a/playground/java/src/main/java/com/algolia/playground/App.java b/playground/java/src/main/java/com/algolia/playground/App.java index 53ffca8aa8..0de0e4a201 100644 --- a/playground/java/src/main/java/com/algolia/playground/App.java +++ b/playground/java/src/main/java/com/algolia/playground/App.java @@ -4,21 +4,24 @@ import com.algolia.exceptions.AlgoliaRetryException; import com.algolia.exceptions.AlgoliaRuntimeException; import com.algolia.model.search.*; -import com.algolia.search.SearchApi; +import com.algolia.search.SearchClient; import com.algolia.utils.UserAgent; - import io.github.cdimascio.dotenv.Dotenv; public class App { + public static void main(String[] args) { Dotenv dotenv = Dotenv.configure().directory("../").load(); - SearchApi client = new SearchApi(dotenv.get("ALGOLIA_APPLICATION_ID"), dotenv.get("ALGOLIA_SEARCH_KEY"), - new UserAgent.Segment[] { - new UserAgent.Segment("test", "8.0.0"), - new UserAgent.Segment("JVM", "11.0.14"), - new UserAgent.Segment("no version") - }); + SearchClient client = new SearchClient( + dotenv.get("ALGOLIA_APPLICATION_ID"), + dotenv.get("ALGOLIA_SEARCH_KEY"), + new UserAgent.Segment[] { + new UserAgent.Segment("test", "8.0.0"), + new UserAgent.Segment("JVM", "11.0.14"), + new UserAgent.Segment("no version"), + } + ); String indexName = dotenv.get("SEARCH_INDEX"); SearchParamsObject params = new SearchParamsObject(); @@ -26,20 +29,21 @@ public static void main(String[] args) { params.setQuery(dotenv.get("SEARCH_QUERY")); try { - SearchResponse result = client.search(indexName, SearchParams.ofSearchParamsObject(params)); + SearchResponse result = client.search( + indexName, + SearchParams.ofSearchParamsObject(params) + ); System.out.println(result); } catch (AlgoliaApiException e) { // the API failed - System.err.println("Exception when calling SearchApi#search"); + System.err.println("Exception when calling SearchClient#search"); System.err.println("Status code: " + e.getHttpErrorCode()); System.err.println("Reason: " + e.getMessage()); e.printStackTrace(); - } catch (AlgoliaRetryException e) { // the retry failed System.err.println("Exception in the retry strategy"); e.printStackTrace(); - } catch (AlgoliaRuntimeException e) { // the serialization or something else failed e.printStackTrace(); diff --git a/playground/javascript/browser/app.ts b/playground/javascript/browser/app.ts index 9749db84e3..1fe2ba618d 100644 --- a/playground/javascript/browser/app.ts +++ b/playground/javascript/browser/app.ts @@ -1,8 +1,8 @@ -import { searchApi } from '@experimental-api-clients-automation/client-search'; +import { searchClient } from '@experimental-api-clients-automation/client-search'; import './app.css'; -const searchClient = searchApi( +const searchClient = searchClient( 'QPBQ67WNIG', 'b590ae1153bf574215ca1605c19eb1fe' ); diff --git a/playground/javascript/node/abtesting.ts b/playground/javascript/node/abtesting.ts index 04b5989c57..138775fd1c 100644 --- a/playground/javascript/node/abtesting.ts +++ b/playground/javascript/node/abtesting.ts @@ -1,4 +1,4 @@ -import { abtestingApi } from '@experimental-api-clients-automation/client-abtesting'; +import { abtestingClient } from '@experimental-api-clients-automation/client-abtesting'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -9,7 +9,7 @@ const apiKey = process.env.ALGOLIA_ANALYTICS_KEY || '**** ANALYTICS_API_KEY *****'; // Init client with appId and apiKey -const client = abtestingApi(appId, apiKey, 'de'); +const client = abtestingClient(appId, apiKey, 'de'); async function testABTesting() { try { diff --git a/playground/javascript/node/analytics.ts b/playground/javascript/node/analytics.ts index 14a979fafc..8774acb8be 100644 --- a/playground/javascript/node/analytics.ts +++ b/playground/javascript/node/analytics.ts @@ -1,4 +1,4 @@ -import { analyticsApi } from '@experimental-api-clients-automation/client-analytics'; +import { analyticsClient } from '@experimental-api-clients-automation/client-analytics'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -11,7 +11,7 @@ const apiKey = const analyticsIndex = process.env.ANALYTICS_INDEX || 'test_index'; // Init client with appId and apiKey -const client = analyticsApi(appId, apiKey, 'de'); +const client = analyticsClient(appId, apiKey, 'de'); async function testAnalytics() { try { diff --git a/playground/javascript/node/insights.ts b/playground/javascript/node/insights.ts index a5c8d94844..c8b4bcdb1d 100644 --- a/playground/javascript/node/insights.ts +++ b/playground/javascript/node/insights.ts @@ -1,4 +1,4 @@ -import { insightsApi } from '@experimental-api-clients-automation/client-insights'; +import { insightsClient } from '@experimental-api-clients-automation/client-insights'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -9,7 +9,7 @@ const apiKey = process.env.ALGOLIA_INSIGHTS_API_KEY || '**** INSIGHTS_API_KEY *****'; // Init client with appId and apiKey -const client = insightsApi(appId, apiKey); +const client = insightsClient(appId, apiKey); async function testInsights() { try { diff --git a/playground/javascript/node/personalization.ts b/playground/javascript/node/personalization.ts index 1b0816c30b..f7c4dc3ae4 100644 --- a/playground/javascript/node/personalization.ts +++ b/playground/javascript/node/personalization.ts @@ -1,4 +1,4 @@ -import { personalizationApi } from '@experimental-api-clients-automation/client-personalization'; +import { personalizationClient } from '@experimental-api-clients-automation/client-personalization'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -9,7 +9,7 @@ const apiKey = process.env.ALGOLIA_RECOMMENDATION_KEY || '**** RECOMMENDATION_API_KEY *****'; // Init client with appId and apiKey -const client = personalizationApi(appId, apiKey, 'eu'); +const client = personalizationClient(appId, apiKey, 'eu'); async function testPersonalization() { try { diff --git a/playground/javascript/node/predict.ts b/playground/javascript/node/predict.ts index 07c8e21135..13c42fc6e4 100644 --- a/playground/javascript/node/predict.ts +++ b/playground/javascript/node/predict.ts @@ -1,4 +1,4 @@ -import { predictApi } from '@experimental-api-clients-automation/client-predict'; +import { predictClient } from '@experimental-api-clients-automation/client-predict'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -10,7 +10,7 @@ const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****'; const userId = process.env.USER_ID || 'user1'; // Init client with appId and apiKey -const predictClient = predictApi(appId, apiKey); +const predictClient = predictClient(appId, apiKey); async function testPredict() { try { diff --git a/playground/javascript/node/query-suggestions.ts b/playground/javascript/node/query-suggestions.ts index 8c408051d1..1d466fd84b 100644 --- a/playground/javascript/node/query-suggestions.ts +++ b/playground/javascript/node/query-suggestions.ts @@ -1,4 +1,4 @@ -import { querySuggestionsApi } from '@experimental-api-clients-automation/client-query-suggestions'; +import { querySuggestionsClient } from '@experimental-api-clients-automation/client-query-suggestions'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -10,7 +10,7 @@ const apiKey = '**** QUERY_SUGGESTIONS_KEY *****'; // Init client with appId and apiKey -const client = querySuggestionsApi(appId, apiKey, 'us'); +const client = querySuggestionsClient(appId, apiKey, 'us'); async function testQuerySuggestions() { try { diff --git a/playground/javascript/node/recommend.ts b/playground/javascript/node/recommend.ts index 1fdf860ad3..d6131c0c0f 100644 --- a/playground/javascript/node/recommend.ts +++ b/playground/javascript/node/recommend.ts @@ -1,4 +1,4 @@ -import { recommendApi } from '@experimental-api-clients-automation/recommend'; +import { recommendClient } from '@experimental-api-clients-automation/recommend'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -11,7 +11,7 @@ const searchIndex = process.env.SEARCH_INDEX || 'test_index'; const searchQuery = process.env.SEARCH_QUERY || 'test_query'; // Init client with appId and apiKey -const client = recommendApi(appId, apiKey); +const client = recommendClient(appId, apiKey); async function testRecommend() { try { diff --git a/playground/javascript/node/search.ts b/playground/javascript/node/search.ts index f9ae245fe0..54799bf46c 100644 --- a/playground/javascript/node/search.ts +++ b/playground/javascript/node/search.ts @@ -1,4 +1,4 @@ -import { searchApi } from '@experimental-api-clients-automation/client-search'; +import { searchClient } from '@experimental-api-clients-automation/client-search'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -11,7 +11,7 @@ const searchIndex = process.env.SEARCH_INDEX || 'test_index'; const searchQuery = process.env.SEARCH_QUERY || 'test_query'; // Init client with appId and apiKey -const client = searchApi(appId, apiKey); +const client = searchClient(appId, apiKey); client.addUserAgent('Node playground', '0.0.1'); diff --git a/playground/javascript/node/sources.ts b/playground/javascript/node/sources.ts index c464552f19..5fd5fc4b13 100644 --- a/playground/javascript/node/sources.ts +++ b/playground/javascript/node/sources.ts @@ -1,4 +1,4 @@ -import { sourcesApi } from '@experimental-api-clients-automation/client-sources'; +import { sourcesClient } from '@experimental-api-clients-automation/client-sources'; import { ApiError } from '@experimental-api-clients-automation/client-common'; import dotenv from 'dotenv'; @@ -8,7 +8,7 @@ const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****'; const apiKey = process.env.ALGOLIA_ADMIN_KEY || '**** ALGOLIA_ADMIN_KEY *****'; // Init client with appId and apiKey -const client = sourcesApi(appId, apiKey, 'us'); +const client = sourcesClient(appId, apiKey, 'us'); async function testSource() { try { diff --git a/playground/php/src/abtesting.php b/playground/php/src/abtesting.php index 0ed14a1665..557785ee84 100644 --- a/playground/php/src/abtesting.php +++ b/playground/php/src/abtesting.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\AbtestingApi; +use Algolia\AlgoliaSearch\Api\AbtestingClient; -$client = AbtestingApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ANALYTICS_KEY')); +$client = AbtestingClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ANALYTICS_KEY')); $abTest = [ 'name' => 'testing', diff --git a/playground/php/src/analytics.php b/playground/php/src/analytics.php index 9d09bd8f84..437c6b9800 100644 --- a/playground/php/src/analytics.php +++ b/playground/php/src/analytics.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\AnalyticsApi; +use Algolia\AlgoliaSearch\Api\AnalyticsClient; -$client = AnalyticsApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ANALYTICS_KEY')); +$client = AnalyticsClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ANALYTICS_KEY')); $indexName = getenv('ANALYTICS_INDEX'); var_dump( diff --git a/playground/php/src/insights.php b/playground/php/src/insights.php index 131cbbdd3a..665b6241a5 100644 --- a/playground/php/src/insights.php +++ b/playground/php/src/insights.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\InsightsApi; +use Algolia\AlgoliaSearch\Api\InsightsClient; -$client = InsightsApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); +$client = InsightsClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); $indexName = getenv('SEARCH_INDEX'); $twoDaysAgoMs = (time() - (2 * 24 * 60 * 60)) * 1000; diff --git a/playground/php/src/personalization.php b/playground/php/src/personalization.php index bc2ae4fab1..245e135e9e 100644 --- a/playground/php/src/personalization.php +++ b/playground/php/src/personalization.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\PersonalizationApi; +use Algolia\AlgoliaSearch\Api\PersonalizationClient; -$client = PersonalizationApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_RECOMMENDATION_KEY')); +$client = PersonalizationClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_RECOMMENDATION_KEY')); var_dump( $client->deleteUserProfile('userToken') diff --git a/playground/php/src/query-suggestions.php b/playground/php/src/query-suggestions.php index 5a3739cbee..eea5dbc53d 100644 --- a/playground/php/src/query-suggestions.php +++ b/playground/php/src/query-suggestions.php @@ -2,8 +2,8 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\QuerySuggestionsApi; +use Algolia\AlgoliaSearch\Api\QuerySuggestionsClient; -$client = QuerySuggestionsApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('QUERY_SUGGESTIONS_KEY')); +$client = QuerySuggestionsClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('QUERY_SUGGESTIONS_KEY')); var_dump($client->getAllConfigs()); diff --git a/playground/php/src/recommend.php b/playground/php/src/recommend.php index f826375c6b..923ecab1c6 100644 --- a/playground/php/src/recommend.php +++ b/playground/php/src/recommend.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\RecommendApi; +use Algolia\AlgoliaSearch\Api\RecommendClient; -$client = RecommendApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); +$client = RecommendClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); $indexName = getenv('SEARCH_INDEX'); $query = getenv('SEARCH_QUERY'); diff --git a/playground/php/src/search.php b/playground/php/src/search.php index 16319182a3..3c4556e838 100644 --- a/playground/php/src/search.php +++ b/playground/php/src/search.php @@ -2,9 +2,9 @@ require '../../../clients/algoliasearch-client-php/vendor/autoload.php'; -use Algolia\AlgoliaSearch\Api\SearchApi; +use Algolia\AlgoliaSearch\Api\SearchClient; -$client = SearchApi::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); +$client = SearchClient::create(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_ADMIN_KEY')); $indexName = getenv('SEARCH_INDEX'); var_dump($client->search($indexName, ['query' => getenv('SEARCH_QUERY')])); diff --git a/scripts/ci/createMatrix.ts b/scripts/ci/createMatrix.ts index 5c62d34204..ad38e280cf 100644 --- a/scripts/ci/createMatrix.ts +++ b/scripts/ci/createMatrix.ts @@ -77,7 +77,7 @@ async function getClientMatrix({ const clientName = createClientName(client, 'php'); matchedGenerator.config = `${clientName}Config`; - matchedGenerator.api = `${clientName}Api`; + matchedGenerator.api = `${clientName}Client`; matchedGenerator.capitalizedName = clientName; } diff --git a/scripts/cts/client/generate.ts b/scripts/cts/client/generate.ts index db218426df..b200bdff4e 100644 --- a/scripts/cts/client/generate.ts +++ b/scripts/cts/client/generate.ts @@ -98,7 +98,7 @@ export async function generateClientTests( template, { import: packageName, - client: `${createClientName(client, language)}Api`, + client: `${createClientName(client, language)}Client`, blocks: modifyForMustache(testsBlocks), hasRegionalHost: hasRegionalHost ? true : undefined, }, diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java index d7ae7ac106..0185285041 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.AbtestingApi; +import com.algolia.api.AbtestingClient; import com.algolia.model.abtesting.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class AbtestingApiTests { +class AbtestingClientTests { - private AbtestingApi client; + private AbtestingClient client; @BeforeAll void init() { - client = new AbtestingApi("appId", "apiKey", new EchoRequester()); + client = new AbtestingClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java index c10e9c5147..9b353c7f8e 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.AnalyticsApi; +import com.algolia.api.AnalyticsClient; import com.algolia.model.analytics.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class AnalyticsApiTests { +class AnalyticsClientTests { - private AnalyticsApi client; + private AnalyticsClient client; @BeforeAll void init() { - client = new AnalyticsApi("appId", "apiKey", new EchoRequester()); + client = new AnalyticsClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java index f211036175..426a5b7c76 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.InsightsApi; +import com.algolia.api.InsightsClient; import com.algolia.model.insights.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class InsightsApiTests { +class InsightsClientTests { - private InsightsApi client; + private InsightsClient client; @BeforeAll void init() { - client = new InsightsApi("appId", "apiKey", new EchoRequester()); + client = new InsightsClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java index f29ff3dc48..0d53385e91 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.PersonalizationApi; +import com.algolia.api.PersonalizationClient; import com.algolia.model.personalization.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class PersonalizationApiTests { +class PersonalizationClientTests { - private PersonalizationApi client; + private PersonalizationClient client; @BeforeAll void init() { - client = new PersonalizationApi("appId", "apiKey", new EchoRequester()); + client = new PersonalizationClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java index a709f46f24..a0fd0c2093 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.QuerySuggestionsApi; +import com.algolia.api.QuerySuggestionsClient; import com.algolia.model.querySuggestions.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class QuerySuggestionsApiTests { +class QuerySuggestionsClientTests { - private QuerySuggestionsApi client; + private QuerySuggestionsClient client; @BeforeAll void init() { - client = new QuerySuggestionsApi("appId", "apiKey", new EchoRequester()); + client = new QuerySuggestionsClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java index 9352bd6b17..1ed96929b5 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.RecommendApi; +import com.algolia.api.RecommendClient; import com.algolia.model.recommend.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class RecommendApiTests { +class RecommendClientTests { - private RecommendApi client; + private RecommendClient client; @BeforeAll void init() { - client = new RecommendApi("appId", "apiKey", new EchoRequester()); + client = new RecommendClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index c6c1b1ec31..c3e9bcdc4a 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -6,7 +6,7 @@ import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.api.SearchApi; +import com.algolia.api.SearchClient; import com.algolia.model.search.*; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; @@ -19,13 +19,13 @@ import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class SearchApiTests { +class SearchClientTests { - private SearchApi client; + private SearchClient client; @BeforeAll void init() { - client = new SearchApi("appId", "apiKey", new EchoRequester()); + client = new SearchClient("appId", "apiKey", new EchoRequester()); } @Test diff --git a/tests/output/javascript/src/client/abtesting.test.ts b/tests/output/javascript/src/client/abtesting.test.ts index d04907bedd..af31b60dc8 100644 --- a/tests/output/javascript/src/client/abtesting.test.ts +++ b/tests/output/javascript/src/client/abtesting.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { abtestingApi } from '@experimental-api-clients-automation/client-abtesting'; +import { abtestingClient } from '@experimental-api-clients-automation/client-abtesting'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return abtestingApi(appId, apiKey, 'us', { requester: echoRequester() }); + return abtestingClient(appId, apiKey, 'us', { requester: echoRequester() }); } describe('api', () => { @@ -63,7 +63,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = abtestingApi('my-app-id', 'my-api-key', '', { + $client = abtestingClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/client/analytics.test.ts b/tests/output/javascript/src/client/analytics.test.ts index eada257bef..db65dbcfe7 100644 --- a/tests/output/javascript/src/client/analytics.test.ts +++ b/tests/output/javascript/src/client/analytics.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { analyticsApi } from '@experimental-api-clients-automation/client-analytics'; +import { analyticsClient } from '@experimental-api-clients-automation/client-analytics'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return analyticsApi(appId, apiKey, 'us', { requester: echoRequester() }); + return analyticsClient(appId, apiKey, 'us', { requester: echoRequester() }); } describe('api', () => { @@ -55,7 +55,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = analyticsApi('my-app-id', 'my-api-key', '', { + $client = analyticsClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/client/insights.test.ts b/tests/output/javascript/src/client/insights.test.ts index a74d5b6a27..f614e2bfa4 100644 --- a/tests/output/javascript/src/client/insights.test.ts +++ b/tests/output/javascript/src/client/insights.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { insightsApi } from '@experimental-api-clients-automation/client-insights'; +import { insightsClient } from '@experimental-api-clients-automation/client-insights'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return insightsApi(appId, apiKey, 'us', { requester: echoRequester() }); + return insightsClient(appId, apiKey, 'us', { requester: echoRequester() }); } describe('api', () => { @@ -55,7 +55,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = insightsApi('my-app-id', 'my-api-key', '', { + $client = insightsClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/client/personalization.test.ts b/tests/output/javascript/src/client/personalization.test.ts index 203e2fecdd..b16ae0bd3f 100644 --- a/tests/output/javascript/src/client/personalization.test.ts +++ b/tests/output/javascript/src/client/personalization.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { personalizationApi } from '@experimental-api-clients-automation/client-personalization'; +import { personalizationClient } from '@experimental-api-clients-automation/client-personalization'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return personalizationApi(appId, apiKey, 'us', { + return personalizationClient(appId, apiKey, 'us', { requester: echoRequester(), }); } @@ -56,7 +56,7 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - $client = personalizationApi('my-app-id', 'my-api-key', '', { + $client = personalizationClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); @@ -78,7 +78,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = personalizationApi('my-app-id', 'my-api-key', 'us', { + $client = personalizationClient('my-app-id', 'my-api-key', 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/client/query-suggestions.test.ts b/tests/output/javascript/src/client/query-suggestions.test.ts index 292f526c9d..88842d5106 100644 --- a/tests/output/javascript/src/client/query-suggestions.test.ts +++ b/tests/output/javascript/src/client/query-suggestions.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { querySuggestionsApi } from '@experimental-api-clients-automation/client-query-suggestions'; +import { querySuggestionsClient } from '@experimental-api-clients-automation/client-query-suggestions'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return querySuggestionsApi(appId, apiKey, 'us', { + return querySuggestionsClient(appId, apiKey, 'us', { requester: echoRequester(), }); } @@ -56,7 +56,7 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - $client = querySuggestionsApi('my-app-id', 'my-api-key', '', { + $client = querySuggestionsClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); @@ -78,7 +78,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = querySuggestionsApi('my-app-id', 'my-api-key', 'us', { + $client = querySuggestionsClient('my-app-id', 'my-api-key', 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/client/recommend.test.ts b/tests/output/javascript/src/client/recommend.test.ts index 780491323e..1d321158ed 100644 --- a/tests/output/javascript/src/client/recommend.test.ts +++ b/tests/output/javascript/src/client/recommend.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { recommendApi } from '@experimental-api-clients-automation/recommend'; +import { recommendClient } from '@experimental-api-clients-automation/recommend'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return recommendApi(appId, apiKey, { requester: echoRequester() }); + return recommendClient(appId, apiKey, { requester: echoRequester() }); } describe('api', () => { diff --git a/tests/output/javascript/src/client/search.test.ts b/tests/output/javascript/src/client/search.test.ts index d0891cce1d..25feb9bd23 100644 --- a/tests/output/javascript/src/client/search.test.ts +++ b/tests/output/javascript/src/client/search.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { searchApi } from '@experimental-api-clients-automation/client-search'; +import { searchClient } from '@experimental-api-clients-automation/client-search'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return searchApi(appId, apiKey, { requester: echoRequester() }); + return searchClient(appId, apiKey, { requester: echoRequester() }); } describe('api', () => { @@ -71,7 +71,7 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - $client = searchApi('', '', { requester: echoRequester() }); + $client = searchClient('', '', { requester: echoRequester() }); actual = $client; @@ -85,7 +85,9 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = searchApi('', 'my-api-key', { requester: echoRequester() }); + $client = searchClient('', 'my-api-key', { + requester: echoRequester(), + }); actual = $client; @@ -99,7 +101,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = searchApi('my-app-id', '', { requester: echoRequester() }); + $client = searchClient('my-app-id', '', { requester: echoRequester() }); actual = $client; diff --git a/tests/output/javascript/src/client/sources.test.ts b/tests/output/javascript/src/client/sources.test.ts index 207e63408a..4470bedf50 100644 --- a/tests/output/javascript/src/client/sources.test.ts +++ b/tests/output/javascript/src/client/sources.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. -import { sourcesApi } from '@experimental-api-clients-automation/client-sources'; +import { sourcesClient } from '@experimental-api-clients-automation/client-sources'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return sourcesApi(appId, apiKey, 'us', { requester: echoRequester() }); + return sourcesClient(appId, apiKey, 'us', { requester: echoRequester() }); } describe('api', () => { @@ -83,7 +83,7 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - $client = sourcesApi('my-app-id', 'my-api-key', '', { + $client = sourcesClient('my-app-id', 'my-api-key', '', { requester: echoRequester(), }); @@ -105,7 +105,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - $client = sourcesApi('my-app-id', 'my-api-key', 'us', { + $client = sourcesClient('my-app-id', 'my-api-key', 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/methods/requests/abtesting.test.ts b/tests/output/javascript/src/methods/requests/abtesting.test.ts index 750dff432d..6ae5e9153e 100644 --- a/tests/output/javascript/src/methods/requests/abtesting.test.ts +++ b/tests/output/javascript/src/methods/requests/abtesting.test.ts @@ -1,11 +1,11 @@ -import { abtestingApi } from '@experimental-api-clients-automation/client-abtesting'; +import { abtestingClient } from '@experimental-api-clients-automation/client-abtesting'; import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = abtestingApi(appId, apiKey, 'us', { +const client = abtestingClient(appId, apiKey, 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/methods/requests/analytics.test.ts b/tests/output/javascript/src/methods/requests/analytics.test.ts index bdbd9a3471..93f2e3dacc 100644 --- a/tests/output/javascript/src/methods/requests/analytics.test.ts +++ b/tests/output/javascript/src/methods/requests/analytics.test.ts @@ -1,11 +1,11 @@ -import { analyticsApi } from '@experimental-api-clients-automation/client-analytics'; +import { analyticsClient } from '@experimental-api-clients-automation/client-analytics'; import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = analyticsApi(appId, apiKey, 'us', { +const client = analyticsClient(appId, apiKey, 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/methods/requests/insights.test.ts b/tests/output/javascript/src/methods/requests/insights.test.ts index 4562d36486..a2a8e57792 100644 --- a/tests/output/javascript/src/methods/requests/insights.test.ts +++ b/tests/output/javascript/src/methods/requests/insights.test.ts @@ -1,11 +1,13 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { insightsApi } from '@experimental-api-clients-automation/client-insights'; +import { insightsClient } from '@experimental-api-clients-automation/client-insights'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = insightsApi(appId, apiKey, 'us', { requester: echoRequester() }); +const client = insightsClient(appId, apiKey, 'us', { + requester: echoRequester(), +}); describe('del', () => { test('allow del method for a custom path with minimal parameters', async () => { diff --git a/tests/output/javascript/src/methods/requests/personalization.test.ts b/tests/output/javascript/src/methods/requests/personalization.test.ts index 4f35ddd9d5..3f97eefec3 100644 --- a/tests/output/javascript/src/methods/requests/personalization.test.ts +++ b/tests/output/javascript/src/methods/requests/personalization.test.ts @@ -1,11 +1,11 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { personalizationApi } from '@experimental-api-clients-automation/client-personalization'; +import { personalizationClient } from '@experimental-api-clients-automation/client-personalization'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = personalizationApi(appId, apiKey, 'us', { +const client = personalizationClient(appId, apiKey, 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts index 4f3a90b08e..acfc470f2a 100644 --- a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts +++ b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts @@ -1,11 +1,11 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { querySuggestionsApi } from '@experimental-api-clients-automation/client-query-suggestions'; +import { querySuggestionsClient } from '@experimental-api-clients-automation/client-query-suggestions'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = querySuggestionsApi(appId, apiKey, 'us', { +const client = querySuggestionsClient(appId, apiKey, 'us', { requester: echoRequester(), }); diff --git a/tests/output/javascript/src/methods/requests/recommend.test.ts b/tests/output/javascript/src/methods/requests/recommend.test.ts index d4aba81a2e..5476120514 100644 --- a/tests/output/javascript/src/methods/requests/recommend.test.ts +++ b/tests/output/javascript/src/methods/requests/recommend.test.ts @@ -1,11 +1,11 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { recommendApi } from '@experimental-api-clients-automation/recommend'; +import { recommendClient } from '@experimental-api-clients-automation/recommend'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = recommendApi(appId, apiKey, { requester: echoRequester() }); +const client = recommendClient(appId, apiKey, { requester: echoRequester() }); describe('del', () => { test('allow del method for a custom path with minimal parameters', async () => { diff --git a/tests/output/javascript/src/methods/requests/search.test.ts b/tests/output/javascript/src/methods/requests/search.test.ts index 3774dbee6d..bf914390b5 100644 --- a/tests/output/javascript/src/methods/requests/search.test.ts +++ b/tests/output/javascript/src/methods/requests/search.test.ts @@ -1,11 +1,11 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { searchApi } from '@experimental-api-clients-automation/client-search'; +import { searchClient } from '@experimental-api-clients-automation/client-search'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = searchApi(appId, apiKey, { requester: echoRequester() }); +const client = searchClient(appId, apiKey, { requester: echoRequester() }); describe('addApiKey', () => { test('addApiKey', async () => { diff --git a/tests/output/javascript/src/methods/requests/sources.test.ts b/tests/output/javascript/src/methods/requests/sources.test.ts index 60ba9e7561..e5d2af95fc 100644 --- a/tests/output/javascript/src/methods/requests/sources.test.ts +++ b/tests/output/javascript/src/methods/requests/sources.test.ts @@ -1,11 +1,13 @@ import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; -import { sourcesApi } from '@experimental-api-clients-automation/client-sources'; +import { sourcesClient } from '@experimental-api-clients-automation/client-sources'; import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; -const client = sourcesApi(appId, apiKey, 'us', { requester: echoRequester() }); +const client = sourcesClient(appId, apiKey, 'us', { + requester: echoRequester(), +}); describe('del', () => { test('allow del method for a custom path with minimal parameters', async () => { diff --git a/tests/output/php/src/SearchApiTest.php b/tests/output/php/src/SearchClientTest.php similarity index 80% rename from tests/output/php/src/SearchApiTest.php rename to tests/output/php/src/SearchClientTest.php index cded93a61c..c15a2761bd 100644 --- a/tests/output/php/src/SearchApiTest.php +++ b/tests/output/php/src/SearchClientTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; -class SearchApiTest extends TestCase +class SearchClientTest extends TestCase { public function testTest() { diff --git a/website/docs/addNewLanguage.md b/website/docs/addNewLanguage.md index 3182a63807..44f84c9ce5 100644 --- a/website/docs/addNewLanguage.md +++ b/website/docs/addNewLanguage.md @@ -53,7 +53,7 @@ By default, OpenAPI will put the `AppId` and `ApiKey` in every method parameters The constructor of the client can be edited (from the `.mustache` files) to accept and store those values. - [First implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/pull/7) -- [Current implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/blob/main/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts#L110-L125) +- [Current implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/blob/main/clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts#L110-L125) ### Retry strategy diff --git a/website/docs/gettingStarted.mdx b/website/docs/gettingStarted.mdx index 52c3ed4c9e..6e2ebbfde2 100644 --- a/website/docs/gettingStarted.mdx +++ b/website/docs/gettingStarted.mdx @@ -57,15 +57,15 @@ const personalizationCilent = client.initPersonalization( ``` ```js -import { searchApi } from '@experimental-api-clients-automation/client-search'; +import { searchClient } from '@experimental-api-clients-automation/client-search'; -const client = searchApi(appId, apiKey); +const client = searchClient(appId, apiKey); ``` It is possible to customize the client by passing optional parameters: ```js -const client = searchApi(appId, apiKey, { +const client = searchClient(appId, apiKey, { requester: customRequester(), hosts: [ { @@ -91,7 +91,7 @@ console.log('Search result', res.hits); Or with the `personalization` client ```js -const res = await personalizationCilent.getUserTokenProfile({ +const res = await personalizationClient.getUserTokenProfile({ userToken: 'token', }); From 0b56ceebbe721bda8aaa9051509aa7bbda7b3e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 20 Apr 2022 15:30:18 +0200 Subject: [PATCH 2/6] fix php path variable --- .github/.cache_version | 2 +- .github/workflows/check.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index dcffda3e5c..e9e6e4d233 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.4.1 +8.0.4.2 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 92a4417c08..63df4e882e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -270,14 +270,14 @@ jobs: uses: actions/cache@v2 with: path: | - ${{ format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api) }} - ${{ format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName) }} + ${{ format('{0}/lib/Api/{1}.php', matrix.client.path, matrix.client.api) }} + ${{ format('{0}/lib/Model/{1}/**', matrix.client.path, matrix.client.capitalizedName) }} key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api), - format('{0}/lib/Configuration/{1}.php', matrix.client.folder, matrix.client.config), - format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName), + format('{0}/lib/Api/{1}.php', matrix.client.path, matrix.client.api), + format('{0}/lib/Configuration/{1}.php', matrix.client.path, matrix.client.config), + format('{0}/lib/Model/{1}/**', matrix.client.path, matrix.client.capitalizedName), format('specs/bundled/{0}.yml', matrix.client.name), 'templates/php/**', 'generators/src/**' From 021bc2eb182c09f7887c2adfd2b67a60eef4f932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 20 Apr 2022 15:35:10 +0200 Subject: [PATCH 3/6] fix playground naming --- playground/javascript/browser/app.ts | 9 +++------ playground/javascript/node/predict.ts | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/playground/javascript/browser/app.ts b/playground/javascript/browser/app.ts index 1fe2ba618d..0044cb3633 100644 --- a/playground/javascript/browser/app.ts +++ b/playground/javascript/browser/app.ts @@ -2,17 +2,14 @@ import { searchClient } from '@experimental-api-clients-automation/client-search import './app.css'; -const searchClient = searchClient( - 'QPBQ67WNIG', - 'b590ae1153bf574215ca1605c19eb1fe' -); +const client = searchClient('QPBQ67WNIG', 'b590ae1153bf574215ca1605c19eb1fe'); -searchClient.addUserAgent('Browser playground', '0.0.1'); +client.addUserAgent('Browser playground', '0.0.1'); const searchButton = document.querySelector('#search'); searchButton?.addEventListener('click', async () => { - const results = await searchClient.search({ + const results = await client.search({ indexName: 'docsearch', searchParams: { query: 'docsearch', diff --git a/playground/javascript/node/predict.ts b/playground/javascript/node/predict.ts index 13c42fc6e4..a78f44b53a 100644 --- a/playground/javascript/node/predict.ts +++ b/playground/javascript/node/predict.ts @@ -10,11 +10,11 @@ const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****'; const userId = process.env.USER_ID || 'user1'; // Init client with appId and apiKey -const predictClient = predictClient(appId, apiKey); +const client = predictClient(appId, apiKey); async function testPredict() { try { - const userProfile = await predictClient.fetchUserProfile({ + const userProfile = await client.fetchUserProfile({ userID: userId, params: { modelsToRetrieve: ['funnel_stage', 'order_value', 'affinities'], From edd4f0a88f7e437128e23389b373f801d361cb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 20 Apr 2022 16:04:23 +0200 Subject: [PATCH 4/6] try without deleting files --- .../com/algolia/api/AbtestingApi.java | 955 +++ .../com/algolia/api/AnalyticsApi.java | 3432 +++++++++ .../com/algolia/api/InsightsApi.java | 581 ++ .../com/algolia/api/PersonalizationApi.java | 878 +++ .../com/algolia/api/PredictApi.java | 600 ++ .../com/algolia/api/QuerySuggestionsApi.java | 1154 +++ .../com/algolia/api/RecommendApi.java | 626 ++ .../com/algolia/api/SearchApi.java | 6644 +++++++++++++++++ .../src/algoliasearchLiteApi.ts | 305 + .../client-abtesting/src/abtestingApi.ts | 503 ++ .../client-analytics/src/analyticsApi.ts | 1799 +++++ .../client-insights/src/insightsApi.ts | 305 + .../src/personalizationApi.ts | 434 ++ .../packages/client-predict/src/predictApi.ts | 312 + .../src/querySuggestionsApi.ts | 573 ++ .../packages/client-search/src/searchApi.ts | 3354 +++++++++ .../packages/recommend/src/recommendApi.ts | 325 + .../lib/Api/AbtestingApi.php | 455 ++ .../lib/Api/AnalyticsApi.php | 1771 +++++ .../lib/Api/InsightsApi.php | 319 + .../lib/Api/PersonalizationApi.php | 401 + .../lib/Api/QuerySuggestionsApi.php | 510 ++ .../lib/Api/RecommendApi.php | 320 + .../lib/Api/SearchApi.php | 2713 +++++++ 24 files changed, 29269 insertions(+) create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java create mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java create mode 100644 clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts create mode 100644 clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts create mode 100644 clients/algoliasearch-client-php/lib/Api/AbtestingApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/InsightsApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/RecommendApi.php create mode 100644 clients/algoliasearch-client-php/lib/Api/SearchApi.php diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java new file mode 100644 index 0000000000..d4180e383b --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java @@ -0,0 +1,955 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.abtesting.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class AbtestingApi extends ApiClient { + + public AbtestingApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); + } + + public AbtestingApi(String appId, String apiKey, String region) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); + } + + public AbtestingApi( + String appId, + String apiKey, + String region, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(region)), + userAgentSegments + ); + } + + public AbtestingApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public AbtestingApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Abtesting", userAgentSegments); + } + + private static List getDefaultHosts(String region) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "analytics." + (region == null ? "" : region + ".") + "algolia.com", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for addABTests + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call addABTestsCall( + AddABTestsRequest addABTestsRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = addABTestsRequest; + + // create path and map variables + String requestPath = "/2/abtests"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call addABTestsValidateBeforeCall( + AddABTestsRequest addABTestsRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'addABTestsRequest' is set + if (addABTestsRequest == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'addABTestsRequest' when calling addABTests(Async)" + ); + } + + return addABTestsCall(addABTestsRequest, callback); + } + + /** + * Creates a new A/B test with provided configuration. You can set an A/B test on two different + * indices with different settings, or on the same index with different search parameters by + * providing a customSearchParameters setting on one of the variants. + * + * @param addABTestsRequest (required) + * @return ABTestResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ABTestResponse addABTests(AddABTestsRequest addABTestsRequest) + throws AlgoliaRuntimeException { + Call req = addABTestsValidateBeforeCall(addABTestsRequest, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.AddABTests(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Creates a new A/B test with provided configuration. You can set an A/B test on + * two different indices with different settings, or on the same index with different search + * parameters by providing a customSearchParameters setting on one of the variants. + * + * @param addABTestsRequest (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call addABTestsAsync( + AddABTestsRequest addABTestsRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = addABTestsValidateBeforeCall(addABTestsRequest, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteABTest + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteABTestCall( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/2/abtests/{id}".replaceAll( + "\\{id\\}", + this.escapeString(id.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteABTestValidateBeforeCall( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'id' is set + if (id == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'id' when calling deleteABTest(Async)" + ); + } + + return deleteABTestCall(id, callback); + } + + /** + * Deletes the A/B Test and removes all associated metadata & metrics. + * + * @param id The A/B test ID. (required) + * @return ABTestResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ABTestResponse deleteABTest(Integer id) + throws AlgoliaRuntimeException { + Call req = deleteABTestValidateBeforeCall(id, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.DeleteABTest(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Deletes the A/B Test and removes all associated metadata & metrics. + * + * @param id The A/B test ID. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteABTestAsync( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteABTestValidateBeforeCall(id, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getABTest + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getABTestCall(Integer id, final ApiCallback callback) + throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/2/abtests/{id}".replaceAll( + "\\{id\\}", + this.escapeString(id.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getABTestValidateBeforeCall( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'id' is set + if (id == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'id' when calling getABTest(Async)" + ); + } + + return getABTestCall(id, callback); + } + + /** + * Returns metadata and metrics for A/B test id. Behaves in the same way as GET /2/abtests however + * the endpoint will return 403. + * + * @param id The A/B test ID. (required) + * @return ABTest + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ABTest getABTest(Integer id) throws AlgoliaRuntimeException { + Call req = getABTestValidateBeforeCall(id, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.GetABTest(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Returns metadata and metrics for A/B test id. Behaves in the same way as GET + * /2/abtests however the endpoint will return 403. + * + * @param id The A/B test ID. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getABTestAsync(Integer id, final ApiCallback callback) + throws AlgoliaRuntimeException { + Call call = getABTestValidateBeforeCall(id, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for listABTests + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call listABTestsCall( + Integer offset, + Integer limit, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/abtests"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call listABTestsValidateBeforeCall( + Integer offset, + Integer limit, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return listABTestsCall(offset, limit, callback); + } + + /** + * Fetch all existing A/B tests for App that are available for the current API Key. Returns an + * array of metadata and metrics. When no data has been processed, the metrics will be returned as + * null. + * + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @return ListABTestsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ListABTestsResponse listABTests(Integer offset, Integer limit) + throws AlgoliaRuntimeException { + Call req = listABTestsValidateBeforeCall(offset, limit, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.ListABTests(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public ListABTestsResponse listABTests() throws AlgoliaRuntimeException { + return this.listABTests(0, 10); + } + + /** + * (asynchronously) Fetch all existing A/B tests for App that are available for the current API + * Key. Returns an array of metadata and metrics. When no data has been processed, the metrics + * will be returned as null. + * + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call listABTestsAsync( + Integer offset, + Integer limit, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = listABTestsValidateBeforeCall(offset, limit, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for stopABTest + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call stopABTestCall( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/2/abtests/{id}/stop".replaceAll( + "\\{id\\}", + this.escapeString(id.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call stopABTestValidateBeforeCall( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'id' is set + if (id == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'id' when calling stopABTest(Async)" + ); + } + + return stopABTestCall(id, callback); + } + + /** + * Marks the A/B test as stopped. At this point, the test is over and cannot be restarted. As a + * result, your application is back to normal: index A will perform as usual, receiving 100% of + * all search requests. Associated metadata and metrics are still stored. + * + * @param id The A/B test ID. (required) + * @return ABTestResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ABTestResponse stopABTest(Integer id) throws AlgoliaRuntimeException { + Call req = stopABTestValidateBeforeCall(id, null); + if (req instanceof CallEcho) { + return new EchoResponseAbtesting.StopABTest(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Marks the A/B test as stopped. At this point, the test is over and cannot be + * restarted. As a result, your application is back to normal: index A will perform as usual, + * receiving 100% of all search requests. Associated metadata and metrics are still stored. + * + * @param id The A/B test ID. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call stopABTestAsync( + Integer id, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = stopABTestValidateBeforeCall(id, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java new file mode 100644 index 0000000000..533474b900 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java @@ -0,0 +1,3432 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.analytics.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class AnalyticsApi extends ApiClient { + + public AnalyticsApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); + } + + public AnalyticsApi(String appId, String apiKey, String region) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); + } + + public AnalyticsApi( + String appId, + String apiKey, + String region, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(region)), + userAgentSegments + ); + } + + public AnalyticsApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public AnalyticsApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Analytics", userAgentSegments); + } + + private static List getDefaultHosts(String region) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "analytics." + (region == null ? "" : region + ".") + "algolia.com", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getAverageClickPosition + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getAverageClickPositionCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/clicks/averageClickPosition"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getAverageClickPositionValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getAverageClickPosition(Async)" + ); + } + + return getAverageClickPositionCall( + index, + startDate, + endDate, + tags, + callback + ); + } + + /** + * Returns the average click position. The endpoint returns a value for the complete given time + * range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetAverageClickPositionResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetAverageClickPositionResponse getAverageClickPosition( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getAverageClickPositionValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetAverageClickPosition( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetAverageClickPositionResponse getAverageClickPosition(String index) + throws AlgoliaRuntimeException { + return this.getAverageClickPosition(index, null, null, null); + } + + /** + * (asynchronously) Returns the average click position. The endpoint returns a value for the + * complete given time range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAverageClickPositionAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getAverageClickPositionValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getClickPositions + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getClickPositionsCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/clicks/positions"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getClickPositionsValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getClickPositions(Async)" + ); + } + + return getClickPositionsCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns the distribution of clicks per range of positions. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetClickPositionsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetClickPositionsResponse getClickPositions( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getClickPositionsValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetClickPositions( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetClickPositionsResponse getClickPositions(String index) + throws AlgoliaRuntimeException { + return this.getClickPositions(index, null, null, null); + } + + /** + * (asynchronously) Returns the distribution of clicks per range of positions. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getClickPositionsAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getClickPositionsValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getClickThroughRate + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getClickThroughRateCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/clicks/clickThroughRate"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getClickThroughRateValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getClickThroughRate(Async)" + ); + } + + return getClickThroughRateCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns a click-through rate (CTR). The endpoint returns a value for the complete given time + * range, as well as a value per day. It also returns the count of clicks and searches used to + * compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetClickThroughRateResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetClickThroughRateResponse getClickThroughRate( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getClickThroughRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetClickThroughRate( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetClickThroughRateResponse getClickThroughRate(String index) + throws AlgoliaRuntimeException { + return this.getClickThroughRate(index, null, null, null); + } + + /** + * (asynchronously) Returns a click-through rate (CTR). The endpoint returns a value for the + * complete given time range, as well as a value per day. It also returns the count of clicks and + * searches used to compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getClickThroughRateAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getClickThroughRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getConversationRate + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getConversationRateCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/conversions/conversionRate"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getConversationRateValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getConversationRate(Async)" + ); + } + + return getConversationRateCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns a conversion rate (CR). The endpoint returns a value for the complete given time range, + * as well as a value per day. It also returns the count of conversion and searches used to + * compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetConversationRateResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetConversationRateResponse getConversationRate( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getConversationRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetConversationRate( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetConversationRateResponse getConversationRate(String index) + throws AlgoliaRuntimeException { + return this.getConversationRate(index, null, null, null); + } + + /** + * (asynchronously) Returns a conversion rate (CR). The endpoint returns a value for the complete + * given time range, as well as a value per day. It also returns the count of conversion and + * searches used to compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getConversationRateAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getConversationRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getNoClickRate + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getNoClickRateCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches/noClickRate"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getNoClickRateValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getNoClickRate(Async)" + ); + } + + return getNoClickRateCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns the rate at which searches didn't lead to any clicks. The endpoint returns a value for + * the complete given time range, as well as a value per day. It also returns the count of + * searches and searches without clicks. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetNoClickRateResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetNoClickRateResponse getNoClickRate( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getNoClickRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetNoClickRate( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetNoClickRateResponse getNoClickRate(String index) + throws AlgoliaRuntimeException { + return this.getNoClickRate(index, null, null, null); + } + + /** + * (asynchronously) Returns the rate at which searches didn't lead to any clicks. The endpoint + * returns a value for the complete given time range, as well as a value per day. It also returns + * the count of searches and searches without clicks. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getNoClickRateAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getNoClickRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getNoResultsRate + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getNoResultsRateCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches/noResultRate"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getNoResultsRateValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getNoResultsRate(Async)" + ); + } + + return getNoResultsRateCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns the rate at which searches didn't return any results. The endpoint returns a value for + * the complete given time range, as well as a value per day. It also returns the count of + * searches and searches without results used to compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetNoResultsRateResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetNoResultsRateResponse getNoResultsRate( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getNoResultsRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetNoResultsRate( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetNoResultsRateResponse getNoResultsRate(String index) + throws AlgoliaRuntimeException { + return this.getNoResultsRate(index, null, null, null); + } + + /** + * (asynchronously) Returns the rate at which searches didn't return any results. The endpoint + * returns a value for the complete given time range, as well as a value per day. It also returns + * the count of searches and searches without results used to compute the rates. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getNoResultsRateAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getNoResultsRateValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSearchesCount + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSearchesCountCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches/count"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSearchesCountValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getSearchesCount(Async)" + ); + } + + return getSearchesCountCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns the number of searches across the given time range. The endpoint returns a value for + * the complete given time range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetSearchesCountResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetSearchesCountResponse getSearchesCount( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getSearchesCountValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetSearchesCount( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetSearchesCountResponse getSearchesCount(String index) + throws AlgoliaRuntimeException { + return this.getSearchesCount(index, null, null, null); + } + + /** + * (asynchronously) Returns the number of searches across the given time range. The endpoint + * returns a value for the complete given time range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSearchesCountAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getSearchesCountValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSearchesNoClicks + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSearchesNoClicksCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches/noClicks"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSearchesNoClicksValidateBeforeCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getSearchesNoClicks(Async)" + ); + } + + return getSearchesNoClicksCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top searches that didn't lead to any clicks. Limited to the 1000 most frequent ones. + * For each search, also returns the average number of found hits. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetSearchesNoClicksResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetSearchesNoClicksResponse getSearchesNoClicks( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getSearchesNoClicksValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetSearchesNoClicks( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetSearchesNoClicksResponse getSearchesNoClicks(String index) + throws AlgoliaRuntimeException { + return this.getSearchesNoClicks(index, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top searches that didn't lead to any clicks. Limited to the 1000 + * most frequent ones. For each search, also returns the average number of found hits. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSearchesNoClicksAsync( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getSearchesNoClicksValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSearchesNoResults + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSearchesNoResultsCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches/noResults"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSearchesNoResultsValidateBeforeCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getSearchesNoResults(Async)" + ); + } + + return getSearchesNoResultsCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top searches that didn't return any results. Limited to the 1000 most frequent ones. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetSearchesNoResultsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetSearchesNoResultsResponse getSearchesNoResults( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getSearchesNoResultsValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetSearchesNoResults( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetSearchesNoResultsResponse getSearchesNoResults(String index) + throws AlgoliaRuntimeException { + return this.getSearchesNoResults(index, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top searches that didn't return any results. Limited to the 1000 + * most frequent ones. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSearchesNoResultsAsync( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getSearchesNoResultsValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getStatus + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getStatusCall( + String index, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/status"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getStatusValidateBeforeCall( + String index, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getStatus(Async)" + ); + } + + return getStatusCall(index, callback); + } + + /** + * Returns the latest update time of the analytics API for a given index. If the index has been + * recently created and/or no search has been performed yet the updated time will be null. + * + * @param index The index name to target. (required) + * @return GetStatusResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetStatusResponse getStatus(String index) + throws AlgoliaRuntimeException { + Call req = getStatusValidateBeforeCall(index, null); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetStatus(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Returns the latest update time of the analytics API for a given index. If the + * index has been recently created and/or no search has been performed yet the updated time will + * be null. + * + * @param index The index name to target. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getStatusAsync( + String index, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getStatusValidateBeforeCall(index, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopCountries + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopCountriesCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/countries"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopCountriesValidateBeforeCall( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopCountries(Async)" + ); + } + + return getTopCountriesCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top countries. Limited to the 1000 most frequent ones. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopCountriesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopCountriesResponse getTopCountries( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopCountriesValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopCountries( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetTopCountriesResponse getTopCountries(String index) + throws AlgoliaRuntimeException { + return this.getTopCountries(index, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top countries. Limited to the 1000 most frequent ones. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopCountriesAsync( + String index, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopCountriesValidateBeforeCall( + index, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopFilterAttributes + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopFilterAttributesCall( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/filters"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (search != null) { + queryParams.addAll(this.parameterToPair("search", search)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopFilterAttributesValidateBeforeCall( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopFilterAttributes(Async)" + ); + } + + return getTopFilterAttributesCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top filter attributes. Limited to the 1000 most used filters. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopFilterAttributesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopFilterAttributesResponse getTopFilterAttributes( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopFilterAttributesValidateBeforeCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopFilterAttributes( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetTopFilterAttributesResponse getTopFilterAttributes(String index) + throws AlgoliaRuntimeException { + return this.getTopFilterAttributes(index, null, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top filter attributes. Limited to the 1000 most used filters. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopFilterAttributesAsync( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopFilterAttributesValidateBeforeCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopFilterForAttribute + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopFilterForAttributeCall( + String attribute, + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/2/filters/{attribute}".replaceAll( + "\\{attribute\\}", + this.escapeString(attribute.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (search != null) { + queryParams.addAll(this.parameterToPair("search", search)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopFilterForAttributeValidateBeforeCall( + String attribute, + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'attribute' is set + if (attribute == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'attribute' when calling" + + " getTopFilterForAttribute(Async)" + ); + } + + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopFilterForAttribute(Async)" + ); + } + + return getTopFilterForAttributeCall( + attribute, + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top filters for the given attribute. Limited to the 1000 most used filters. + * + * @param attribute The exact name of the attribute. (required) + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopFilterForAttributeResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopFilterForAttributeResponse getTopFilterForAttribute( + String attribute, + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopFilterForAttributeValidateBeforeCall( + attribute, + index, + search, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopFilterForAttribute( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetTopFilterForAttributeResponse getTopFilterForAttribute( + String attribute, + String index + ) throws AlgoliaRuntimeException { + return this.getTopFilterForAttribute( + attribute, + index, + null, + null, + null, + 10, + 0, + null + ); + } + + /** + * (asynchronously) Returns top filters for the given attribute. Limited to the 1000 most used + * filters. + * + * @param attribute The exact name of the attribute. (required) + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopFilterForAttributeAsync( + String attribute, + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopFilterForAttributeValidateBeforeCall( + attribute, + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopFiltersNoResults + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopFiltersNoResultsCall( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/filters/noResults"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (search != null) { + queryParams.addAll(this.parameterToPair("search", search)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopFiltersNoResultsValidateBeforeCall( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopFiltersNoResults(Async)" + ); + } + + return getTopFiltersNoResultsCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top filters with no results. Limited to the 1000 most used filters. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopFiltersNoResultsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopFiltersNoResultsResponse getTopFiltersNoResults( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopFiltersNoResultsValidateBeforeCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopFiltersNoResults( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public GetTopFiltersNoResultsResponse getTopFiltersNoResults(String index) + throws AlgoliaRuntimeException { + return this.getTopFiltersNoResults(index, null, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top filters with no results. Limited to the 1000 most used filters. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopFiltersNoResultsAsync( + String index, + String search, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopFiltersNoResultsValidateBeforeCall( + index, + search, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopHits + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopHitsCall( + String index, + String search, + Boolean clickAnalytics, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/hits"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (search != null) { + queryParams.addAll(this.parameterToPair("search", search)); + } + + if (clickAnalytics != null) { + queryParams.addAll( + this.parameterToPair("clickAnalytics", clickAnalytics) + ); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopHitsValidateBeforeCall( + String index, + String search, + Boolean clickAnalytics, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopHits(Async)" + ); + } + + return getTopHitsCall( + index, + search, + clickAnalytics, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top hits. Limited to the 1000 most frequent ones. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param clickAnalytics Whether to include the click-through and conversion rates for a search. + * (optional, default to false) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopHitsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopHitsResponse getTopHits( + String index, + String search, + Boolean clickAnalytics, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopHitsValidateBeforeCall( + index, + search, + clickAnalytics, + startDate, + endDate, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopHits(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetTopHitsResponse getTopHits(String index) + throws AlgoliaRuntimeException { + return this.getTopHits(index, null, false, null, null, 10, 0, null); + } + + /** + * (asynchronously) Returns top hits. Limited to the 1000 most frequent ones. + * + * @param index The index name to target. (required) + * @param search The query term to search for. Must match the exact user input. (optional) + * @param clickAnalytics Whether to include the click-through and conversion rates for a search. + * (optional, default to false) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopHitsAsync( + String index, + String search, + Boolean clickAnalytics, + String startDate, + String endDate, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopHitsValidateBeforeCall( + index, + search, + clickAnalytics, + startDate, + endDate, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopSearches + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopSearchesCall( + String index, + Boolean clickAnalytics, + String startDate, + String endDate, + OrderBy orderBy, + Direction direction, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/searches"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (clickAnalytics != null) { + queryParams.addAll( + this.parameterToPair("clickAnalytics", clickAnalytics) + ); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (orderBy != null) { + queryParams.addAll(this.parameterToPair("orderBy", orderBy)); + } + + if (direction != null) { + queryParams.addAll(this.parameterToPair("direction", direction)); + } + + if (limit != null) { + queryParams.addAll(this.parameterToPair("limit", limit)); + } + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopSearchesValidateBeforeCall( + String index, + Boolean clickAnalytics, + String startDate, + String endDate, + OrderBy orderBy, + Direction direction, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getTopSearches(Async)" + ); + } + + return getTopSearchesCall( + index, + clickAnalytics, + startDate, + endDate, + orderBy, + direction, + limit, + offset, + tags, + callback + ); + } + + /** + * Returns top searches. Limited to the 1000 most frequent ones. For each search, also returns the + * average number of hits returned. + * + * @param index The index name to target. (required) + * @param clickAnalytics Whether to include the click-through and conversion rates for a search. + * (optional, default to false) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param orderBy Reorder the results. (optional, default to searchCount) + * @param direction The sorting of the result. (optional, default to asc) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetTopSearchesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopSearchesResponse getTopSearches( + String index, + Boolean clickAnalytics, + String startDate, + String endDate, + OrderBy orderBy, + Direction direction, + Integer limit, + Integer offset, + String tags + ) throws AlgoliaRuntimeException { + Call req = getTopSearchesValidateBeforeCall( + index, + clickAnalytics, + startDate, + endDate, + orderBy, + direction, + limit, + offset, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetTopSearches( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetTopSearchesResponse getTopSearches(String index) + throws AlgoliaRuntimeException { + return this.getTopSearches( + index, + false, + null, + null, + OrderBy.SEARCH_COUNT, + Direction.ASC, + 10, + 0, + null + ); + } + + /** + * (asynchronously) Returns top searches. Limited to the 1000 most frequent ones. For each search, + * also returns the average number of hits returned. + * + * @param index The index name to target. (required) + * @param clickAnalytics Whether to include the click-through and conversion rates for a search. + * (optional, default to false) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param orderBy Reorder the results. (optional, default to searchCount) + * @param direction The sorting of the result. (optional, default to asc) + * @param limit Number of records to return. Limit is the size of the page. (optional, default to + * 10) + * @param offset Position of the starting record. Used for paging. 0 is the first record. + * (optional, default to 0) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopSearchesAsync( + String index, + Boolean clickAnalytics, + String startDate, + String endDate, + OrderBy orderBy, + Direction direction, + Integer limit, + Integer offset, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopSearchesValidateBeforeCall( + index, + clickAnalytics, + startDate, + endDate, + orderBy, + direction, + limit, + offset, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getUsersCount + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getUsersCountCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/2/users/count"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (index != null) { + queryParams.addAll(this.parameterToPair("index", index)); + } + + if (startDate != null) { + queryParams.addAll(this.parameterToPair("startDate", startDate)); + } + + if (endDate != null) { + queryParams.addAll(this.parameterToPair("endDate", endDate)); + } + + if (tags != null) { + queryParams.addAll(this.parameterToPair("tags", tags)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getUsersCountValidateBeforeCall( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'index' is set + if (index == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'index' when calling getUsersCount(Async)" + ); + } + + return getUsersCountCall(index, startDate, endDate, tags, callback); + } + + /** + * Returns the distinct count of users across the given time range. The endpoint returns a value + * for the complete given time range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @return GetUsersCountResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetUsersCountResponse getUsersCount( + String index, + String startDate, + String endDate, + String tags + ) throws AlgoliaRuntimeException { + Call req = getUsersCountValidateBeforeCall( + index, + startDate, + endDate, + tags, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.GetUsersCount( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetUsersCountResponse getUsersCount(String index) + throws AlgoliaRuntimeException { + return this.getUsersCount(index, null, null, null); + } + + /** + * (asynchronously) Returns the distinct count of users across the given time range. The endpoint + * returns a value for the complete given time range, as well as a value per day. + * + * @param index The index name to target. (required) + * @param startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period + * to analyze. (optional) + * @param tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags + * set at search time. Multiple tags can be combined with the operators OR and AND. If a tag + * contains characters like spaces or parentheses, it should be URL encoded. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getUsersCountAsync( + String index, + String startDate, + String endDate, + String tags, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getUsersCountValidateBeforeCall( + index, + startDate, + endDate, + tags, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseAnalytics.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java new file mode 100644 index 0000000000..1f333b2336 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java @@ -0,0 +1,581 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.insights.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class InsightsApi extends ApiClient { + + public InsightsApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); + } + + public InsightsApi(String appId, String apiKey, String region) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); + } + + public InsightsApi( + String appId, + String apiKey, + String region, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(region)), + userAgentSegments + ); + } + + public InsightsApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public InsightsApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Insights", userAgentSegments); + } + + private static List getDefaultHosts(String region) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "insights." + (region == null ? "" : region + ".") + "algolia.io", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseInsights.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseInsights.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseInsights.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for pushEvents + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call pushEventsCall( + InsightEvents insightEvents, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = insightEvents; + + // create path and map variables + String requestPath = "/1/events"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call pushEventsValidateBeforeCall( + InsightEvents insightEvents, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'insightEvents' is set + if (insightEvents == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'insightEvents' when calling pushEvents(Async)" + ); + } + + return pushEventsCall(insightEvents, callback); + } + + /** + * This command pushes an array of events. + * + * @param insightEvents (required) + * @return PushEventsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public PushEventsResponse pushEvents(InsightEvents insightEvents) + throws AlgoliaRuntimeException { + Call req = pushEventsValidateBeforeCall(insightEvents, null); + if (req instanceof CallEcho) { + return new EchoResponseInsights.PushEvents(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) This command pushes an array of events. + * + * @param insightEvents (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call pushEventsAsync( + InsightEvents insightEvents, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = pushEventsValidateBeforeCall(insightEvents, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseInsights.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java new file mode 100644 index 0000000000..69a2f7dc53 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java @@ -0,0 +1,878 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.personalization.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class PersonalizationApi extends ApiClient { + + public PersonalizationApi(String appId, String apiKey, String region) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); + } + + public PersonalizationApi( + String appId, + String apiKey, + String region, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(region)), + userAgentSegments + ); + } + + public PersonalizationApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public PersonalizationApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Personalization", userAgentSegments); + } + + private static List getDefaultHosts(String region) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "personalization." + + (region == null ? "" : region + ".") + + "algolia.com", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteUserProfile + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteUserProfileCall( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/profiles/{userToken}".replaceAll( + "\\{userToken\\}", + this.escapeString(userToken.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteUserProfileValidateBeforeCall( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'userToken' is set + if (userToken == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'userToken' when calling deleteUserProfile(Async)" + ); + } + + return deleteUserProfileCall(userToken, callback); + } + + /** + * Returns, as part of the response, a date until which the data can safely be considered as + * deleted for the given user. This means that if you send events for the given user before this + * date, they will be ignored. Any data received after the deletedUntil date will start building a + * new user profile. It might take a couple hours before for the deletion request to be fully + * processed. + * + * @param userToken userToken representing the user for which to fetch the Personalization + * profile. (required) + * @return DeleteUserProfileResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeleteUserProfileResponse deleteUserProfile(String userToken) + throws AlgoliaRuntimeException { + Call req = deleteUserProfileValidateBeforeCall(userToken, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.DeleteUserProfile( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Returns, as part of the response, a date until which the data can safely be + * considered as deleted for the given user. This means that if you send events for the given user + * before this date, they will be ignored. Any data received after the deletedUntil date will + * start building a new user profile. It might take a couple hours before for the deletion request + * to be fully processed. + * + * @param userToken userToken representing the user for which to fetch the Personalization + * profile. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteUserProfileAsync( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteUserProfileValidateBeforeCall(userToken, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getPersonalizationStrategy + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getPersonalizationStrategyCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/strategies/personalization"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getPersonalizationStrategyValidateBeforeCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return getPersonalizationStrategyCall(callback); + } + + /** + * The strategy contains information on the events and facets that impact user profiles and + * personalized search results. + * + * @return PersonalizationStrategyParams + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public PersonalizationStrategyParams getPersonalizationStrategy() + throws AlgoliaRuntimeException { + Call req = getPersonalizationStrategyValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.GetPersonalizationStrategy( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) The strategy contains information on the events and facets that impact user + * profiles and personalized search results. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getPersonalizationStrategyAsync( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getPersonalizationStrategyValidateBeforeCall(callback); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getUserTokenProfile + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getUserTokenProfileCall( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/profiles/personalization/{userToken}".replaceAll( + "\\{userToken\\}", + this.escapeString(userToken.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getUserTokenProfileValidateBeforeCall( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'userToken' is set + if (userToken == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'userToken' when calling getUserTokenProfile(Async)" + ); + } + + return getUserTokenProfileCall(userToken, callback); + } + + /** + * The profile is structured by facet name used in the strategy. Each facet value is mapped to its + * score. Each score represents the user affinity for a specific facet value given the userToken + * past events and the Personalization strategy defined. Scores are bounded to 20. The last + * processed event timestamp is provided using the ISO 8601 format for debugging purposes. + * + * @param userToken userToken representing the user for which to fetch the Personalization + * profile. (required) + * @return GetUserTokenResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetUserTokenResponse getUserTokenProfile(String userToken) + throws AlgoliaRuntimeException { + Call req = getUserTokenProfileValidateBeforeCall(userToken, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.GetUserTokenProfile( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) The profile is structured by facet name used in the strategy. Each facet value + * is mapped to its score. Each score represents the user affinity for a specific facet value + * given the userToken past events and the Personalization strategy defined. Scores are bounded to + * 20. The last processed event timestamp is provided using the ISO 8601 format for debugging + * purposes. + * + * @param userToken userToken representing the user for which to fetch the Personalization + * profile. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getUserTokenProfileAsync( + String userToken, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getUserTokenProfileValidateBeforeCall(userToken, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for setPersonalizationStrategy + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call setPersonalizationStrategyCall( + PersonalizationStrategyParams personalizationStrategyParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = personalizationStrategyParams; + + // create path and map variables + String requestPath = "/1/strategies/personalization"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call setPersonalizationStrategyValidateBeforeCall( + PersonalizationStrategyParams personalizationStrategyParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'personalizationStrategyParams' is set + if (personalizationStrategyParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'personalizationStrategyParams' when calling" + + " setPersonalizationStrategy(Async)" + ); + } + + return setPersonalizationStrategyCall( + personalizationStrategyParams, + callback + ); + } + + /** + * A strategy defines the events and facets that impact user profiles and personalized search + * results. + * + * @param personalizationStrategyParams (required) + * @return SetPersonalizationStrategyResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SetPersonalizationStrategyResponse setPersonalizationStrategy( + PersonalizationStrategyParams personalizationStrategyParams + ) throws AlgoliaRuntimeException { + Call req = setPersonalizationStrategyValidateBeforeCall( + personalizationStrategyParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponsePersonalization.SetPersonalizationStrategy( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) A strategy defines the events and facets that impact user profiles and + * personalized search results. + * + * @param personalizationStrategyParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call setPersonalizationStrategyAsync( + PersonalizationStrategyParams personalizationStrategyParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = setPersonalizationStrategyValidateBeforeCall( + personalizationStrategyParams, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java new file mode 100644 index 0000000000..902fabbf61 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java @@ -0,0 +1,600 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.predict.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class PredictApi extends ApiClient { + + public PredictApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts()), null); + } + + public PredictApi( + String appId, + String apiKey, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts()), + userAgentSegments + ); + } + + public PredictApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public PredictApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Predict", userAgentSegments); + } + + private static List getDefaultHosts() { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "predict-api-oslcbws3zq-ew.a.run.app", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponsePredict.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for fetchUserProfile + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call fetchUserProfileCall( + String userID, + Params params, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = params; + + // create path and map variables + String requestPath = + "/1/users/{userID}/fetch".replaceAll( + "\\{userID\\}", + this.escapeString(userID.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call fetchUserProfileValidateBeforeCall( + String userID, + Params params, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'userID' is set + if (userID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'userID' when calling fetchUserProfile(Async)" + ); + } + + // verify the required parameter 'params' is set + if (params == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'params' when calling fetchUserProfile(Async)" + ); + } + + return fetchUserProfileCall(userID, params, callback); + } + + /** + * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a + * user profile. + * + * @param userID User ID for authenticated users or cookie ID for non-authenticated repeated users + * (visitors). (required) + * @param params (required) + * @return FetchUserProfileResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public FetchUserProfileResponse fetchUserProfile( + String userID, + Params params + ) throws AlgoliaRuntimeException { + Call req = fetchUserProfileValidateBeforeCall(userID, params, null); + if (req instanceof CallEcho) { + return new EchoResponsePredict.FetchUserProfile( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get predictions, properties (raw, computed or custom) and segments (computed + * or custom) for a user profile. + * + * @param userID User ID for authenticated users or cookie ID for non-authenticated repeated users + * (visitors). (required) + * @param params (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call fetchUserProfileAsync( + String userID, + Params params, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = fetchUserProfileValidateBeforeCall(userID, params, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponsePredict.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponsePredict.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponsePredict.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java new file mode 100644 index 0000000000..ceac70029c --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java @@ -0,0 +1,1154 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.querySuggestions.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.Call; + +public class QuerySuggestionsApi extends ApiClient { + + public QuerySuggestionsApi(String appId, String apiKey, String region) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(region)), null); + } + + public QuerySuggestionsApi( + String appId, + String apiKey, + String region, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(region)), + userAgentSegments + ); + } + + public QuerySuggestionsApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public QuerySuggestionsApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "QuerySuggestions", userAgentSegments); + } + + private static List getDefaultHosts(String region) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + "query-suggestions." + + (region == null ? "" : region + ".") + + "algolia.com", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + return hosts; + } + + /** + * Build call for createConfig + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call createConfigCall( + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = querySuggestionsIndexWithIndexParam; + + // create path and map variables + String requestPath = "/1/configs"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call createConfigValidateBeforeCall( + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'querySuggestionsIndexWithIndexParam' is set + if (querySuggestionsIndexWithIndexParam == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'querySuggestionsIndexWithIndexParam' when calling" + + " createConfig(Async)" + ); + } + + return createConfigCall(querySuggestionsIndexWithIndexParam, callback); + } + + /** + * Create a configuration of a Query Suggestions index. There's a limit of 100 configurations per + * application. + * + * @param querySuggestionsIndexWithIndexParam (required) + * @return SucessResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SucessResponse createConfig( + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam + ) throws AlgoliaRuntimeException { + Call req = createConfigValidateBeforeCall( + querySuggestionsIndexWithIndexParam, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.CreateConfig( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Create a configuration of a Query Suggestions index. There's a limit of + * 100 configurations per application. + * + * @param querySuggestionsIndexWithIndexParam (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call createConfigAsync( + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = createConfigValidateBeforeCall( + querySuggestionsIndexWithIndexParam, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteConfig + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteConfigCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/configs/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteConfigValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteConfig(Async)" + ); + } + + return deleteConfigCall(indexName, callback); + } + + /** + * Delete a configuration of a Query Suggestion's index. By deleting a configuraton, you stop all + * updates to the underlying query suggestion index. Note that when doing this, the underlying + * index does not change - existing suggestions remain untouched. + * + * @param indexName The index in which to perform the request. (required) + * @return SucessResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SucessResponse deleteConfig(String indexName) + throws AlgoliaRuntimeException { + Call req = deleteConfigValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.DeleteConfig( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Delete a configuration of a Query Suggestion's index. By deleting a + * configuraton, you stop all updates to the underlying query suggestion index. Note that when + * doing this, the underlying index does not change - existing suggestions remain untouched. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteConfigAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteConfigValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getAllConfigs + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getAllConfigsCall( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/configs"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getAllConfigsValidateBeforeCall( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + return getAllConfigsCall(callback); + } + + /** + * Get all the configurations of Query Suggestions. For each index, you get a block of JSON with a + * list of its configuration settings. + * + * @return List<QuerySuggestionsIndex> + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public List getAllConfigs() + throws AlgoliaRuntimeException { + Call req = getAllConfigsValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.GetAllConfigs( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken>() {}.getType(); + ApiResponse> res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get all the configurations of Query Suggestions. For each index, you get a + * block of JSON with a list of its configuration settings. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAllConfigsAsync( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Call call = getAllConfigsValidateBeforeCall(callback); + Type returnType = new TypeToken>() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getConfig + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getConfigCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/configs/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getConfigValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getConfig(Async)" + ); + } + + return getConfigCall(indexName, callback); + } + + /** + * Get the configuration of a single Query Suggestions index. + * + * @param indexName The index in which to perform the request. (required) + * @return QuerySuggestionsIndex + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public QuerySuggestionsIndex getConfig(String indexName) + throws AlgoliaRuntimeException { + Call req = getConfigValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.GetConfig( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get the configuration of a single Query Suggestions index. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getConfigAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getConfigValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getConfigStatus + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getConfigStatusCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/configs/{indexName}/status".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getConfigStatusValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getConfigStatus(Async)" + ); + } + + return getConfigStatusCall(indexName, callback); + } + + /** + * Get the status of a Query Suggestion's index. The status includes whether the Query Suggestions + * index is currently in the process of being built, and the last build time. + * + * @param indexName The index in which to perform the request. (required) + * @return Status + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Status getConfigStatus(String indexName) + throws AlgoliaRuntimeException { + Call req = getConfigStatusValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.GetConfigStatus( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get the status of a Query Suggestion's index. The status includes whether + * the Query Suggestions index is currently in the process of being built, and the last build + * time. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getConfigStatusAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getConfigStatusValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getLogFile + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getLogFileCall( + String indexName, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/logs/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getLogFileValidateBeforeCall( + String indexName, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getLogFile(Async)" + ); + } + + return getLogFileCall(indexName, callback); + } + + /** + * Get the log file of the last build of a single Query Suggestion index. + * + * @param indexName The index in which to perform the request. (required) + * @return List<LogFile> + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public List getLogFile(String indexName) + throws AlgoliaRuntimeException { + Call req = getLogFileValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.GetLogFile( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken>() {}.getType(); + ApiResponse> res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get the log file of the last build of a single Query Suggestion index. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getLogFileAsync( + String indexName, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Call call = getLogFileValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken>() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for updateConfig + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call updateConfigCall( + String indexName, + QuerySuggestionsIndexParam querySuggestionsIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = querySuggestionsIndexParam; + + // create path and map variables + String requestPath = + "/1/configs/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call updateConfigValidateBeforeCall( + String indexName, + QuerySuggestionsIndexParam querySuggestionsIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling updateConfig(Async)" + ); + } + + // verify the required parameter 'querySuggestionsIndexParam' is set + if (querySuggestionsIndexParam == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'querySuggestionsIndexParam' when calling" + + " updateConfig(Async)" + ); + } + + return updateConfigCall(indexName, querySuggestionsIndexParam, callback); + } + + /** + * Update the configuration of a Query Suggestions index. + * + * @param indexName The index in which to perform the request. (required) + * @param querySuggestionsIndexParam (required) + * @return SucessResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SucessResponse updateConfig( + String indexName, + QuerySuggestionsIndexParam querySuggestionsIndexParam + ) throws AlgoliaRuntimeException { + Call req = updateConfigValidateBeforeCall( + indexName, + querySuggestionsIndexParam, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseQuerySuggestions.UpdateConfig( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Update the configuration of a Query Suggestions index. + * + * @param indexName The index in which to perform the request. (required) + * @param querySuggestionsIndexParam (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call updateConfigAsync( + String indexName, + QuerySuggestionsIndexParam querySuggestionsIndexParam, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = updateConfigValidateBeforeCall( + indexName, + querySuggestionsIndexParam, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java new file mode 100644 index 0000000000..d9f91ad1f4 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java @@ -0,0 +1,626 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.recommend.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import okhttp3.Call; + +public class RecommendApi extends ApiClient { + + public RecommendApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); + } + + public RecommendApi( + String appId, + String apiKey, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(appId)), + userAgentSegments + ); + } + + public RecommendApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public RecommendApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Recommend", userAgentSegments); + } + + private static List getDefaultHosts(String appId) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + appId + "-dsn.algolia.net", + "https", + EnumSet.of(CallType.READ) + ) + ); + hosts.add( + new StatefulHost( + appId + ".algolia.net", + "https", + EnumSet.of(CallType.WRITE) + ) + ); + + List commonHosts = new ArrayList(); + hosts.add( + new StatefulHost( + appId + "-1.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + hosts.add( + new StatefulHost( + appId + "-2.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + hosts.add( + new StatefulHost( + appId + "-3.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + + Collections.shuffle(commonHosts, new Random()); + + return Stream + .concat(hosts.stream(), commonHosts.stream()) + .collect(Collectors.toList()); + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseRecommend.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseRecommend.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getRecommendations + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getRecommendationsCall( + GetRecommendationsParams getRecommendationsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = getRecommendationsParams; + + // create path and map variables + String requestPath = "/1/indexes/*/recommendations"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getRecommendationsValidateBeforeCall( + GetRecommendationsParams getRecommendationsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'getRecommendationsParams' is set + if (getRecommendationsParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'getRecommendationsParams' when calling" + + " getRecommendations(Async)" + ); + } + + return getRecommendationsCall(getRecommendationsParams, callback); + } + + /** + * Returns recommendations for a specific model and objectID. + * + * @param getRecommendationsParams (required) + * @return GetRecommendationsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetRecommendationsResponse getRecommendations( + GetRecommendationsParams getRecommendationsParams + ) throws AlgoliaRuntimeException { + Call req = getRecommendationsValidateBeforeCall( + getRecommendationsParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseRecommend.GetRecommendations( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Returns recommendations for a specific model and objectID. + * + * @param getRecommendationsParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getRecommendationsAsync( + GetRecommendationsParams getRecommendationsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getRecommendationsValidateBeforeCall( + getRecommendationsParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseRecommend.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseRecommend.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java new file mode 100644 index 0000000000..57dbffd4ea --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java @@ -0,0 +1,6644 @@ +package com.algolia.api; + +import com.algolia.ApiCallback; +import com.algolia.ApiClient; +import com.algolia.ApiResponse; +import com.algolia.Pair; +import com.algolia.exceptions.*; +import com.algolia.model.search.*; +import com.algolia.utils.*; +import com.algolia.utils.echo.*; +import com.algolia.utils.retry.CallType; +import com.algolia.utils.retry.StatefulHost; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import okhttp3.Call; + +public class SearchApi extends ApiClient { + + public SearchApi(String appId, String apiKey) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); + } + + public SearchApi( + String appId, + String apiKey, + UserAgent.Segment[] userAgentSegments + ) { + this( + appId, + apiKey, + new HttpRequester(getDefaultHosts(appId)), + userAgentSegments + ); + } + + public SearchApi(String appId, String apiKey, Requester requester) { + this(appId, apiKey, requester, null); + } + + public SearchApi( + String appId, + String apiKey, + Requester requester, + UserAgent.Segment[] userAgentSegments + ) { + super(appId, apiKey, requester, "Search", userAgentSegments); + } + + private static List getDefaultHosts(String appId) { + List hosts = new ArrayList(); + hosts.add( + new StatefulHost( + appId + "-dsn.algolia.net", + "https", + EnumSet.of(CallType.READ) + ) + ); + hosts.add( + new StatefulHost( + appId + ".algolia.net", + "https", + EnumSet.of(CallType.WRITE) + ) + ); + + List commonHosts = new ArrayList(); + hosts.add( + new StatefulHost( + appId + "-1.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + hosts.add( + new StatefulHost( + appId + "-2.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + hosts.add( + new StatefulHost( + appId + "-3.algolianet.net", + "https", + EnumSet.of(CallType.READ, CallType.WRITE) + ) + ); + + Collections.shuffle(commonHosts, new Random()); + + return Stream + .concat(hosts.stream(), commonHosts.stream()) + .collect(Collectors.toList()); + } + + /** + * Build call for addApiKey + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call addApiKeyCall( + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = apiKey; + + // create path and map variables + String requestPath = "/1/keys"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call addApiKeyValidateBeforeCall( + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'apiKey' is set + if (apiKey == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'apiKey' when calling addApiKey(Async)" + ); + } + + return addApiKeyCall(apiKey, callback); + } + + /** + * Add a new API Key with specific permissions/restrictions. + * + * @param apiKey (required) + * @return AddApiKeyResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public AddApiKeyResponse addApiKey(ApiKey apiKey) + throws AlgoliaRuntimeException { + Call req = addApiKeyValidateBeforeCall(apiKey, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.AddApiKey(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Add a new API Key with specific permissions/restrictions. + * + * @param apiKey (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call addApiKeyAsync( + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = addApiKeyValidateBeforeCall(apiKey, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for addOrUpdateObject + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call addOrUpdateObjectCall( + String indexName, + String objectID, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call addOrUpdateObjectValidateBeforeCall( + String indexName, + String objectID, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling addOrUpdateObject(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling addOrUpdateObject(Async)" + ); + } + + // verify the required parameter 'body' is set + if (body == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'body' when calling addOrUpdateObject(Async)" + ); + } + + return addOrUpdateObjectCall(indexName, objectID, body, callback); + } + + /** + * Add or replace an object with a given object ID. If the object does not exist, it will be + * created. If it already exists, it will be replaced. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param body The Algolia object. (required) + * @return UpdatedAtWithObjectIdResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtWithObjectIdResponse addOrUpdateObject( + String indexName, + String objectID, + Object body + ) throws AlgoliaRuntimeException { + Call req = addOrUpdateObjectValidateBeforeCall( + indexName, + objectID, + body, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.AddOrUpdateObject( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Add or replace an object with a given object ID. If the object does not exist, + * it will be created. If it already exists, it will be replaced. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param body The Algolia object. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call addOrUpdateObjectAsync( + String indexName, + String objectID, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = addOrUpdateObjectValidateBeforeCall( + indexName, + objectID, + body, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for appendSource + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call appendSourceCall( + Source source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = source; + + // create path and map variables + String requestPath = "/1/security/sources/append"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call appendSourceValidateBeforeCall( + Source source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'source' is set + if (source == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'source' when calling appendSource(Async)" + ); + } + + return appendSourceCall(source, callback); + } + + /** + * Add a single source to the list of allowed sources. + * + * @param source The source to add. (required) + * @return CreatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public CreatedAtResponse appendSource(Source source) + throws AlgoliaRuntimeException { + Call req = appendSourceValidateBeforeCall(source, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.AppendSource(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Add a single source to the list of allowed sources. + * + * @param source The source to add. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call appendSourceAsync( + Source source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = appendSourceValidateBeforeCall(source, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for assignUserId + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call assignUserIdCall( + String xAlgoliaUserID, + AssignUserIdParams assignUserIdParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = assignUserIdParams; + + // create path and map variables + String requestPath = "/1/clusters/mapping"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (xAlgoliaUserID != null) { + queryParams.addAll( + this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call assignUserIdValidateBeforeCall( + String xAlgoliaUserID, + AssignUserIdParams assignUserIdParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'xAlgoliaUserID' is set + if (xAlgoliaUserID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'xAlgoliaUserID' when calling assignUserId(Async)" + ); + } + + // verify the required parameter 'assignUserIdParams' is set + if (assignUserIdParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'assignUserIdParams' when calling assignUserId(Async)" + ); + } + + return assignUserIdCall(xAlgoliaUserID, assignUserIdParams, callback); + } + + /** + * Assign or Move a userID to a cluster. The time it takes to migrate (move) a user is + * proportional to the amount of data linked to the userID. Upon success, the response is 200 OK. + * A successful response indicates that the operation has been taken into account, and the userID + * is directly usable. + * + * @param xAlgoliaUserID userID to assign. (required) + * @param assignUserIdParams (required) + * @return CreatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public CreatedAtResponse assignUserId( + String xAlgoliaUserID, + AssignUserIdParams assignUserIdParams + ) throws AlgoliaRuntimeException { + Call req = assignUserIdValidateBeforeCall( + xAlgoliaUserID, + assignUserIdParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.AssignUserId(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Assign or Move a userID to a cluster. The time it takes to migrate (move) a + * user is proportional to the amount of data linked to the userID. Upon success, the response is + * 200 OK. A successful response indicates that the operation has been taken into account, and the + * userID is directly usable. + * + * @param xAlgoliaUserID userID to assign. (required) + * @param assignUserIdParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call assignUserIdAsync( + String xAlgoliaUserID, + AssignUserIdParams assignUserIdParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = assignUserIdValidateBeforeCall( + xAlgoliaUserID, + assignUserIdParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for batch + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call batchCall( + String indexName, + BatchWriteParams batchWriteParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = batchWriteParams; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/batch".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call batchValidateBeforeCall( + String indexName, + BatchWriteParams batchWriteParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling batch(Async)" + ); + } + + // verify the required parameter 'batchWriteParams' is set + if (batchWriteParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'batchWriteParams' when calling batch(Async)" + ); + } + + return batchCall(indexName, batchWriteParams, callback); + } + + /** + * Performs multiple write operations in a single API call. + * + * @param indexName The index in which to perform the request. (required) + * @param batchWriteParams (required) + * @return BatchResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public BatchResponse batch( + String indexName, + BatchWriteParams batchWriteParams + ) throws AlgoliaRuntimeException { + Call req = batchValidateBeforeCall(indexName, batchWriteParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Batch(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Performs multiple write operations in a single API call. + * + * @param indexName The index in which to perform the request. (required) + * @param batchWriteParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call batchAsync( + String indexName, + BatchWriteParams batchWriteParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = batchValidateBeforeCall(indexName, batchWriteParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for batchAssignUserIds + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call batchAssignUserIdsCall( + String xAlgoliaUserID, + BatchAssignUserIdsParams batchAssignUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = batchAssignUserIdsParams; + + // create path and map variables + String requestPath = "/1/clusters/mapping/batch"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (xAlgoliaUserID != null) { + queryParams.addAll( + this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call batchAssignUserIdsValidateBeforeCall( + String xAlgoliaUserID, + BatchAssignUserIdsParams batchAssignUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'xAlgoliaUserID' is set + if (xAlgoliaUserID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'xAlgoliaUserID' when calling batchAssignUserIds(Async)" + ); + } + + // verify the required parameter 'batchAssignUserIdsParams' is set + if (batchAssignUserIdsParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'batchAssignUserIdsParams' when calling" + + " batchAssignUserIds(Async)" + ); + } + + return batchAssignUserIdsCall( + xAlgoliaUserID, + batchAssignUserIdsParams, + callback + ); + } + + /** + * Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A successful + * response indicates that the operation has been taken into account, and the userIDs are directly + * usable. + * + * @param xAlgoliaUserID userID to assign. (required) + * @param batchAssignUserIdsParams (required) + * @return CreatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public CreatedAtResponse batchAssignUserIds( + String xAlgoliaUserID, + BatchAssignUserIdsParams batchAssignUserIdsParams + ) throws AlgoliaRuntimeException { + Call req = batchAssignUserIdsValidateBeforeCall( + xAlgoliaUserID, + batchAssignUserIdsParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.BatchAssignUserIds( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A + * successful response indicates that the operation has been taken into account, and the userIDs + * are directly usable. + * + * @param xAlgoliaUserID userID to assign. (required) + * @param batchAssignUserIdsParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call batchAssignUserIdsAsync( + String xAlgoliaUserID, + BatchAssignUserIdsParams batchAssignUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = batchAssignUserIdsValidateBeforeCall( + xAlgoliaUserID, + batchAssignUserIdsParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for batchDictionaryEntries + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call batchDictionaryEntriesCall( + DictionaryType dictionaryName, + BatchDictionaryEntriesParams batchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = batchDictionaryEntriesParams; + + // create path and map variables + String requestPath = + "/1/dictionaries/{dictionaryName}/batch".replaceAll( + "\\{dictionaryName\\}", + this.escapeString(dictionaryName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call batchDictionaryEntriesValidateBeforeCall( + DictionaryType dictionaryName, + BatchDictionaryEntriesParams batchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'dictionaryName' is set + if (dictionaryName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'dictionaryName' when calling" + + " batchDictionaryEntries(Async)" + ); + } + + // verify the required parameter 'batchDictionaryEntriesParams' is set + if (batchDictionaryEntriesParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'batchDictionaryEntriesParams' when calling" + + " batchDictionaryEntries(Async)" + ); + } + + return batchDictionaryEntriesCall( + dictionaryName, + batchDictionaryEntriesParams, + callback + ); + } + + /** + * Send a batch of dictionary entries. + * + * @param dictionaryName The dictionary to search in. (required) + * @param batchDictionaryEntriesParams (required) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse batchDictionaryEntries( + DictionaryType dictionaryName, + BatchDictionaryEntriesParams batchDictionaryEntriesParams + ) throws AlgoliaRuntimeException { + Call req = batchDictionaryEntriesValidateBeforeCall( + dictionaryName, + batchDictionaryEntriesParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.BatchDictionaryEntries( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Send a batch of dictionary entries. + * + * @param dictionaryName The dictionary to search in. (required) + * @param batchDictionaryEntriesParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call batchDictionaryEntriesAsync( + DictionaryType dictionaryName, + BatchDictionaryEntriesParams batchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = batchDictionaryEntriesValidateBeforeCall( + dictionaryName, + batchDictionaryEntriesParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for batchRules + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call batchRulesCall( + String indexName, + List rule, + Boolean forwardToReplicas, + Boolean clearExistingRules, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = rule; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/batch".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + if (clearExistingRules != null) { + queryParams.addAll( + this.parameterToPair("clearExistingRules", clearExistingRules) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call batchRulesValidateBeforeCall( + String indexName, + List rule, + Boolean forwardToReplicas, + Boolean clearExistingRules, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling batchRules(Async)" + ); + } + + // verify the required parameter 'rule' is set + if (rule == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'rule' when calling batchRules(Async)" + ); + } + + return batchRulesCall( + indexName, + rule, + forwardToReplicas, + clearExistingRules, + callback + ); + } + + /** + * Create or update a batch of Rules. + * + * @param indexName The index in which to perform the request. (required) + * @param rule (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When + * false, existing Rules are kept. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse batchRules( + String indexName, + List rule, + Boolean forwardToReplicas, + Boolean clearExistingRules + ) throws AlgoliaRuntimeException { + Call req = batchRulesValidateBeforeCall( + indexName, + rule, + forwardToReplicas, + clearExistingRules, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.BatchRules(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse batchRules(String indexName, List rule) + throws AlgoliaRuntimeException { + return this.batchRules(indexName, rule, null, null); + } + + /** + * (asynchronously) Create or update a batch of Rules. + * + * @param indexName The index in which to perform the request. (required) + * @param rule (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When + * false, existing Rules are kept. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call batchRulesAsync( + String indexName, + List rule, + Boolean forwardToReplicas, + Boolean clearExistingRules, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = batchRulesValidateBeforeCall( + indexName, + rule, + forwardToReplicas, + clearExistingRules, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for browse + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call browseCall( + String indexName, + BrowseRequest browseRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = browseRequest; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/browse".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call browseValidateBeforeCall( + String indexName, + BrowseRequest browseRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling browse(Async)" + ); + } + + return browseCall(indexName, browseRequest, callback); + } + + /** + * This method allows you to retrieve all index content. It can retrieve up to 1,000 records per + * call and supports full text search and filters. For performance reasons, some features are not + * supported, including `distinct`, sorting by `typos`, `words` or `geo distance`. When there is + * more content to be browsed, the response contains a cursor field. This cursor has to be passed + * to the subsequent call to browse in order to get the next page of results. When the end of the + * index has been reached, the cursor field is absent from the response. + * + * @param indexName The index in which to perform the request. (required) + * @param browseRequest (optional) + * @return BrowseResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public BrowseResponse browse(String indexName, BrowseRequest browseRequest) + throws AlgoliaRuntimeException { + Call req = browseValidateBeforeCall(indexName, browseRequest, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Browse(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public BrowseResponse browse(String indexName) + throws AlgoliaRuntimeException { + return this.browse(indexName, null); + } + + /** + * (asynchronously) This method allows you to retrieve all index content. It can retrieve up to + * 1,000 records per call and supports full text search and filters. For performance reasons, some + * features are not supported, including `distinct`, sorting by `typos`, + * `words` or `geo distance`. When there is more content to be browsed, the + * response contains a cursor field. This cursor has to be passed to the subsequent call to browse + * in order to get the next page of results. When the end of the index has been reached, the + * cursor field is absent from the response. + * + * @param indexName The index in which to perform the request. (required) + * @param browseRequest (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call browseAsync( + String indexName, + BrowseRequest browseRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = browseValidateBeforeCall(indexName, browseRequest, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for clearAllSynonyms + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call clearAllSynonymsCall( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/clear".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call clearAllSynonymsValidateBeforeCall( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling clearAllSynonyms(Async)" + ); + } + + return clearAllSynonymsCall(indexName, forwardToReplicas, callback); + } + + /** + * Remove all synonyms from an index. + * + * @param indexName The index in which to perform the request. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse clearAllSynonyms( + String indexName, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = clearAllSynonymsValidateBeforeCall( + indexName, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ClearAllSynonyms( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse clearAllSynonyms(String indexName) + throws AlgoliaRuntimeException { + return this.clearAllSynonyms(indexName, null); + } + + /** + * (asynchronously) Remove all synonyms from an index. + * + * @param indexName The index in which to perform the request. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call clearAllSynonymsAsync( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = clearAllSynonymsValidateBeforeCall( + indexName, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for clearObjects + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call clearObjectsCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/clear".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call clearObjectsValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling clearObjects(Async)" + ); + } + + return clearObjectsCall(indexName, callback); + } + + /** + * Delete an index's content, but leave settings and index-specific API keys untouched. + * + * @param indexName The index in which to perform the request. (required) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse clearObjects(String indexName) + throws AlgoliaRuntimeException { + Call req = clearObjectsValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ClearObjects(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Delete an index's content, but leave settings and index-specific API keys + * untouched. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call clearObjectsAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = clearObjectsValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for clearRules + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call clearRulesCall( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/clear".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call clearRulesValidateBeforeCall( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling clearRules(Async)" + ); + } + + return clearRulesCall(indexName, forwardToReplicas, callback); + } + + /** + * Delete all Rules in the index. + * + * @param indexName The index in which to perform the request. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse clearRules( + String indexName, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = clearRulesValidateBeforeCall(indexName, forwardToReplicas, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ClearRules(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse clearRules(String indexName) + throws AlgoliaRuntimeException { + return this.clearRules(indexName, null); + } + + /** + * (asynchronously) Delete all Rules in the index. + * + * @param indexName The index in which to perform the request. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call clearRulesAsync( + String indexName, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = clearRulesValidateBeforeCall( + indexName, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for del + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call delCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call delValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling del(Async)" + ); + } + + return delCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object del(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = delValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Del(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object del(String path) throws AlgoliaRuntimeException { + return this.del(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call delAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = delValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteApiKey + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteApiKeyCall( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/keys/{key}".replaceAll( + "\\{key\\}", + this.escapeString(key.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteApiKeyValidateBeforeCall( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'key' is set + if (key == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'key' when calling deleteApiKey(Async)" + ); + } + + return deleteApiKeyCall(key, callback); + } + + /** + * Delete an existing API Key. + * + * @param key API Key string. (required) + * @return DeleteApiKeyResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeleteApiKeyResponse deleteApiKey(String key) + throws AlgoliaRuntimeException { + Call req = deleteApiKeyValidateBeforeCall(key, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteApiKey(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Delete an existing API Key. + * + * @param key API Key string. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteApiKeyAsync( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteApiKeyValidateBeforeCall(key, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteBy + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteByCall( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchParams; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/deleteByQuery".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteByValidateBeforeCall( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteBy(Async)" + ); + } + + // verify the required parameter 'searchParams' is set + if (searchParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'searchParams' when calling deleteBy(Async)" + ); + } + + return deleteByCall(indexName, searchParams, callback); + } + + /** + * Remove all objects matching a filter (including geo filters). This method enables you to delete + * one or more objects based on filters (numeric, facet, tag or geo queries). It doesn't accept + * empty filters or a query. + * + * @param indexName The index in which to perform the request. (required) + * @param searchParams (required) + * @return DeletedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeletedAtResponse deleteBy( + String indexName, + SearchParams searchParams + ) throws AlgoliaRuntimeException { + Call req = deleteByValidateBeforeCall(indexName, searchParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteBy(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Remove all objects matching a filter (including geo filters). This method + * enables you to delete one or more objects based on filters (numeric, facet, tag or geo + * queries). It doesn't accept empty filters or a query. + * + * @param indexName The index in which to perform the request. (required) + * @param searchParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteByAsync( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteByValidateBeforeCall(indexName, searchParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteIndex + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteIndexCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteIndexValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteIndex(Async)" + ); + } + + return deleteIndexCall(indexName, callback); + } + + /** + * Delete an existing index. + * + * @param indexName The index in which to perform the request. (required) + * @return DeletedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeletedAtResponse deleteIndex(String indexName) + throws AlgoliaRuntimeException { + Call req = deleteIndexValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteIndex(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Delete an existing index. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteIndexAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteIndexValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteObject + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteObjectCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteObjectValidateBeforeCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteObject(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling deleteObject(Async)" + ); + } + + return deleteObjectCall(indexName, objectID, callback); + } + + /** + * Delete an existing object. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @return DeletedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeletedAtResponse deleteObject(String indexName, String objectID) + throws AlgoliaRuntimeException { + Call req = deleteObjectValidateBeforeCall(indexName, objectID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteObject(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Delete an existing object. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteObjectAsync( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteObjectValidateBeforeCall(indexName, objectID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteRule + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteRuleCall( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteRuleValidateBeforeCall( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteRule(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling deleteRule(Async)" + ); + } + + return deleteRuleCall(indexName, objectID, forwardToReplicas, callback); + } + + /** + * Delete the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse deleteRule( + String indexName, + String objectID, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = deleteRuleValidateBeforeCall( + indexName, + objectID, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteRule(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse deleteRule(String indexName, String objectID) + throws AlgoliaRuntimeException { + return this.deleteRule(indexName, objectID, null); + } + + /** + * (asynchronously) Delete the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteRuleAsync( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteRuleValidateBeforeCall( + indexName, + objectID, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteSource + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteSourceCall( + String source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/security/sources/{source}".replaceAll( + "\\{source\\}", + this.escapeString(source.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteSourceValidateBeforeCall( + String source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'source' is set + if (source == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'source' when calling deleteSource(Async)" + ); + } + + return deleteSourceCall(source, callback); + } + + /** + * Remove a single source from the list of allowed sources. + * + * @param source The IP range of the source. (required) + * @return DeleteSourceResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeleteSourceResponse deleteSource(String source) + throws AlgoliaRuntimeException { + Call req = deleteSourceValidateBeforeCall(source, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteSource(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Remove a single source from the list of allowed sources. + * + * @param source The IP range of the source. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteSourceAsync( + String source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteSourceValidateBeforeCall(source, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for deleteSynonym + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call deleteSynonymCall( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call deleteSynonymValidateBeforeCall( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling deleteSynonym(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling deleteSynonym(Async)" + ); + } + + return deleteSynonymCall(indexName, objectID, forwardToReplicas, callback); + } + + /** + * Delete a single synonyms set, identified by the given objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return DeletedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public DeletedAtResponse deleteSynonym( + String indexName, + String objectID, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = deleteSynonymValidateBeforeCall( + indexName, + objectID, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.DeleteSynonym(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public DeletedAtResponse deleteSynonym(String indexName, String objectID) + throws AlgoliaRuntimeException { + return this.deleteSynonym(indexName, objectID, null); + } + + /** + * (asynchronously) Delete a single synonyms set, identified by the given objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call deleteSynonymAsync( + String indexName, + String objectID, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = deleteSynonymValidateBeforeCall( + indexName, + objectID, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for get + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getValidateBeforeCall( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling get(Async)" + ); + } + + return getCall(path, parameters, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object get(String path, Map parameters) + throws AlgoliaRuntimeException { + Call req = getValidateBeforeCall(path, parameters, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Get(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object get(String path) throws AlgoliaRuntimeException { + return this.get(path, new HashMap<>()); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getAsync( + String path, + Map parameters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getValidateBeforeCall(path, parameters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getApiKey + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getApiKeyCall(String key, final ApiCallback callback) + throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/keys/{key}".replaceAll( + "\\{key\\}", + this.escapeString(key.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getApiKeyValidateBeforeCall( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'key' is set + if (key == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'key' when calling getApiKey(Async)" + ); + } + + return getApiKeyCall(key, callback); + } + + /** + * Get the permissions of an API key. + * + * @param key API Key string. (required) + * @return Key + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Key getApiKey(String key) throws AlgoliaRuntimeException { + Call req = getApiKeyValidateBeforeCall(key, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetApiKey(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get the permissions of an API key. + * + * @param key API Key string. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getApiKeyAsync(String key, final ApiCallback callback) + throws AlgoliaRuntimeException { + Call call = getApiKeyValidateBeforeCall(key, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getDictionaryLanguages + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getDictionaryLanguagesCall( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/dictionaries/*/languages"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getDictionaryLanguagesValidateBeforeCall( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + return getDictionaryLanguagesCall(callback); + } + + /** + * List dictionaries supported per language. + * + * @return Map<String, Languages> + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Map getDictionaryLanguages() + throws AlgoliaRuntimeException { + Call req = getDictionaryLanguagesValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetDictionaryLanguages( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken>() {}.getType(); + ApiResponse> res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) List dictionaries supported per language. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getDictionaryLanguagesAsync( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Call call = getDictionaryLanguagesValidateBeforeCall(callback); + Type returnType = new TypeToken>() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getDictionarySettings + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getDictionarySettingsCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/dictionaries/*/settings"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getDictionarySettingsValidateBeforeCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return getDictionarySettingsCall(callback); + } + + /** + * Retrieve dictionaries settings. + * + * @return GetDictionarySettingsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetDictionarySettingsResponse getDictionarySettings() + throws AlgoliaRuntimeException { + Call req = getDictionarySettingsValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetDictionarySettings( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Retrieve dictionaries settings. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getDictionarySettingsAsync( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getDictionarySettingsValidateBeforeCall(callback); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getLogs + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getLogsCall( + Integer offset, + Integer length, + String indexName, + LogType type, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/logs"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (offset != null) { + queryParams.addAll(this.parameterToPair("offset", offset)); + } + + if (length != null) { + queryParams.addAll(this.parameterToPair("length", length)); + } + + if (indexName != null) { + queryParams.addAll(this.parameterToPair("indexName", indexName)); + } + + if (type != null) { + queryParams.addAll(this.parameterToPair("type", type)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getLogsValidateBeforeCall( + Integer offset, + Integer length, + String indexName, + LogType type, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return getLogsCall(offset, length, indexName, type, callback); + } + + /** + * Return the lastest log entries. + * + * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, + * therefore 0 designates the most recent log entry. (optional, default to 0) + * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. + * (optional, default to 10) + * @param indexName Index for which log entries should be retrieved. When omitted, log entries are + * retrieved across all indices. (optional) + * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. + * (optional, default to all) + * @return GetLogsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetLogsResponse getLogs( + Integer offset, + Integer length, + String indexName, + LogType type + ) throws AlgoliaRuntimeException { + Call req = getLogsValidateBeforeCall(offset, length, indexName, type, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetLogs(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public GetLogsResponse getLogs() throws AlgoliaRuntimeException { + return this.getLogs(0, 10, null, LogType.ALL); + } + + /** + * (asynchronously) Return the lastest log entries. + * + * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, + * therefore 0 designates the most recent log entry. (optional, default to 0) + * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. + * (optional, default to 10) + * @param indexName Index for which log entries should be retrieved. When omitted, log entries are + * retrieved across all indices. (optional) + * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. + * (optional, default to all) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getLogsAsync( + Integer offset, + Integer length, + String indexName, + LogType type, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getLogsValidateBeforeCall( + offset, + length, + indexName, + type, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getObject + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getObjectCall( + String indexName, + String objectID, + List attributesToRetrieve, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (attributesToRetrieve != null) { + queryParams.addAll( + this.parameterToPair("attributesToRetrieve", attributesToRetrieve) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getObjectValidateBeforeCall( + String indexName, + String objectID, + List attributesToRetrieve, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getObject(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling getObject(Async)" + ); + } + + return getObjectCall(indexName, objectID, attributesToRetrieve, callback); + } + + /** + * Retrieve one object from the index. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable + * attributes are returned. (optional) + * @return Map<String, String> + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Map getObject( + String indexName, + String objectID, + List attributesToRetrieve + ) throws AlgoliaRuntimeException { + Call req = getObjectValidateBeforeCall( + indexName, + objectID, + attributesToRetrieve, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetObject(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken>() {}.getType(); + ApiResponse> res = this.execute(call, returnType); + return res.getData(); + } + + public Map getObject(String indexName, String objectID) + throws AlgoliaRuntimeException { + return this.getObject(indexName, objectID, new ArrayList<>()); + } + + /** + * (asynchronously) Retrieve one object from the index. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable + * attributes are returned. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getObjectAsync( + String indexName, + String objectID, + List attributesToRetrieve, + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + Call call = getObjectValidateBeforeCall( + indexName, + objectID, + attributesToRetrieve, + callback + ); + Type returnType = new TypeToken>() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getObjects + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getObjectsCall( + GetObjectsParams getObjectsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = getObjectsParams; + + // create path and map variables + String requestPath = "/1/indexes/*/objects"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getObjectsValidateBeforeCall( + GetObjectsParams getObjectsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'getObjectsParams' is set + if (getObjectsParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'getObjectsParams' when calling getObjects(Async)" + ); + } + + return getObjectsCall(getObjectsParams, callback); + } + + /** + * Retrieve one or more objects, potentially from different indices, in a single API call. + * + * @param getObjectsParams (required) + * @return GetObjectsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetObjectsResponse getObjects(GetObjectsParams getObjectsParams) + throws AlgoliaRuntimeException { + Call req = getObjectsValidateBeforeCall(getObjectsParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetObjects(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Retrieve one or more objects, potentially from different indices, in a single + * API call. + * + * @param getObjectsParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getObjectsAsync( + GetObjectsParams getObjectsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getObjectsValidateBeforeCall(getObjectsParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getRule + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getRuleCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getRuleValidateBeforeCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getRule(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling getRule(Async)" + ); + } + + return getRuleCall(indexName, objectID, callback); + } + + /** + * Retrieve the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @return Rule + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Rule getRule(String indexName, String objectID) + throws AlgoliaRuntimeException { + Call req = getRuleValidateBeforeCall(indexName, objectID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetRule(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Retrieve the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getRuleAsync( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getRuleValidateBeforeCall(indexName, objectID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSettings + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSettingsCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/settings".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSettingsValidateBeforeCall( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getSettings(Async)" + ); + } + + return getSettingsCall(indexName, callback); + } + + /** + * Retrieve settings of a given indexName. + * + * @param indexName The index in which to perform the request. (required) + * @return IndexSettings + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public IndexSettings getSettings(String indexName) + throws AlgoliaRuntimeException { + Call req = getSettingsValidateBeforeCall(indexName, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetSettings(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Retrieve settings of a given indexName. + * + * @param indexName The index in which to perform the request. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSettingsAsync( + String indexName, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getSettingsValidateBeforeCall(indexName, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSources + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSourcesCall(final ApiCallback> callback) + throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/security/sources"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSourcesValidateBeforeCall( + final ApiCallback> callback + ) throws AlgoliaRuntimeException { + return getSourcesCall(callback); + } + + /** + * List all allowed sources. + * + * @return List<Source> + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public List getSources() throws AlgoliaRuntimeException { + Call req = getSourcesValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetSources(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken>() {}.getType(); + ApiResponse> res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) List all allowed sources. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSourcesAsync(final ApiCallback> callback) + throws AlgoliaRuntimeException { + Call call = getSourcesValidateBeforeCall(callback); + Type returnType = new TypeToken>() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getSynonym + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getSynonymCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getSynonymValidateBeforeCall( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getSynonym(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling getSynonym(Async)" + ); + } + + return getSynonymCall(indexName, objectID, callback); + } + + /** + * Fetch a synonym object identified by its objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @return SynonymHit + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SynonymHit getSynonym(String indexName, String objectID) + throws AlgoliaRuntimeException { + Call req = getSynonymValidateBeforeCall(indexName, objectID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetSynonym(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Fetch a synonym object identified by its objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getSynonymAsync( + String indexName, + String objectID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getSynonymValidateBeforeCall(indexName, objectID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTask + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTaskCall( + String indexName, + Integer taskID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/task/{taskID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{taskID\\}", this.escapeString(taskID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTaskValidateBeforeCall( + String indexName, + Integer taskID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling getTask(Async)" + ); + } + + // verify the required parameter 'taskID' is set + if (taskID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'taskID' when calling getTask(Async)" + ); + } + + return getTaskCall(indexName, taskID, callback); + } + + /** + * Check the current status of a given task. + * + * @param indexName The index in which to perform the request. (required) + * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) + * @return GetTaskResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTaskResponse getTask(String indexName, Integer taskID) + throws AlgoliaRuntimeException { + Call req = getTaskValidateBeforeCall(indexName, taskID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetTask(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Check the current status of a given task. + * + * @param indexName The index in which to perform the request. (required) + * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTaskAsync( + String indexName, + Integer taskID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTaskValidateBeforeCall(indexName, taskID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getTopUserIds + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getTopUserIdsCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/clusters/mapping/top"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getTopUserIdsValidateBeforeCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return getTopUserIdsCall(callback); + } + + /** + * Get the top 10 userIDs with the highest number of records per cluster. The data returned will + * usually be a few seconds behind real time, because userID usage may take up to a few seconds to + * propagate to the different clusters. Upon success, the response is 200 OK and contains the + * following array of userIDs and clusters. + * + * @return GetTopUserIdsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public GetTopUserIdsResponse getTopUserIds() throws AlgoliaRuntimeException { + Call req = getTopUserIdsValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetTopUserIds(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get the top 10 userIDs with the highest number of records per cluster. The + * data returned will usually be a few seconds behind real time, because userID usage may take up + * to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK + * and contains the following array of userIDs and clusters. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getTopUserIdsAsync( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = getTopUserIdsValidateBeforeCall(callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for getUserId + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call getUserIdCall(String userID, final ApiCallback callback) + throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/clusters/mapping/{userID}".replaceAll( + "\\{userID\\}", + this.escapeString(userID.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call getUserIdValidateBeforeCall( + String userID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'userID' is set + if (userID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'userID' when calling getUserId(Async)" + ); + } + + return getUserIdCall(userID, callback); + } + + /** + * Returns the userID data stored in the mapping. The data returned will usually be a few seconds + * behind real time, because userID usage may take up to a few seconds to propagate to the + * different clusters. Upon success, the response is 200 OK and contains the following userID + * data. + * + * @param userID userID to assign. (required) + * @return UserId + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UserId getUserId(String userID) throws AlgoliaRuntimeException { + Call req = getUserIdValidateBeforeCall(userID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.GetUserId(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Returns the userID data stored in the mapping. The data returned will usually + * be a few seconds behind real time, because userID usage may take up to a few seconds to + * propagate to the different clusters. Upon success, the response is 200 OK and contains the + * following userID data. + * + * @param userID userID to assign. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call getUserIdAsync(String userID, final ApiCallback callback) + throws AlgoliaRuntimeException { + Call call = getUserIdValidateBeforeCall(userID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for hasPendingMappings + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call hasPendingMappingsCall( + Boolean getClusters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/clusters/mapping/pending"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (getClusters != null) { + queryParams.addAll(this.parameterToPair("getClusters", getClusters)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call hasPendingMappingsValidateBeforeCall( + Boolean getClusters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return hasPendingMappingsCall(getClusters, callback); + } + + /** + * Get the status of your clusters' migrations or user creations. Creating a large batch of users + * or migrating your multi-cluster may take quite some time. This method lets you retrieve the + * status of the migration, so you can know when it's done. Upon success, the response is 200 OK. + * A successful response indicates that the operation has been taken into account, and the userIDs + * are directly usable. + * + * @param getClusters Whether to get clusters or not. (optional) + * @return CreatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public CreatedAtResponse hasPendingMappings(Boolean getClusters) + throws AlgoliaRuntimeException { + Call req = hasPendingMappingsValidateBeforeCall(getClusters, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.HasPendingMappings( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public CreatedAtResponse hasPendingMappings() throws AlgoliaRuntimeException { + return this.hasPendingMappings(null); + } + + /** + * (asynchronously) Get the status of your clusters' migrations or user creations. Creating a + * large batch of users or migrating your multi-cluster may take quite some time. This method lets + * you retrieve the status of the migration, so you can know when it's done. Upon success, the + * response is 200 OK. A successful response indicates that the operation has been taken into + * account, and the userIDs are directly usable. + * + * @param getClusters Whether to get clusters or not. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call hasPendingMappingsAsync( + Boolean getClusters, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = hasPendingMappingsValidateBeforeCall(getClusters, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for listApiKeys + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call listApiKeysCall(final ApiCallback callback) + throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/keys"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call listApiKeysValidateBeforeCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return listApiKeysCall(callback); + } + + /** + * List API keys, along with their associated rights. + * + * @return ListApiKeysResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ListApiKeysResponse listApiKeys() throws AlgoliaRuntimeException { + Call req = listApiKeysValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ListApiKeys(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) List API keys, along with their associated rights. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call listApiKeysAsync(final ApiCallback callback) + throws AlgoliaRuntimeException { + Call call = listApiKeysValidateBeforeCall(callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for listClusters + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call listClustersCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/clusters"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call listClustersValidateBeforeCall( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return listClustersCall(callback); + } + + /** + * List the clusters available in a multi-clusters setup for a single appID. Upon success, the + * response is 200 OK and contains the following clusters. + * + * @return ListClustersResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ListClustersResponse listClusters() throws AlgoliaRuntimeException { + Call req = listClustersValidateBeforeCall(null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ListClusters(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) List the clusters available in a multi-clusters setup for a single appID. Upon + * success, the response is 200 OK and contains the following clusters. + * + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call listClustersAsync( + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = listClustersValidateBeforeCall(callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for listIndices + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call listIndicesCall( + Integer page, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/indexes"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (page != null) { + queryParams.addAll(this.parameterToPair("page", page)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call listIndicesValidateBeforeCall( + Integer page, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return listIndicesCall(page, callback); + } + + /** + * List existing indexes from an application. + * + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional) + * @return ListIndicesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ListIndicesResponse listIndices(Integer page) + throws AlgoliaRuntimeException { + Call req = listIndicesValidateBeforeCall(page, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ListIndices(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public ListIndicesResponse listIndices() throws AlgoliaRuntimeException { + return this.listIndices(null); + } + + /** + * (asynchronously) List existing indexes from an application. + * + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call listIndicesAsync( + Integer page, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = listIndicesValidateBeforeCall(page, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for listUserIds + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call listUserIdsCall( + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = "/1/clusters/mapping"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (page != null) { + queryParams.addAll(this.parameterToPair("page", page)); + } + + if (hitsPerPage != null) { + queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "GET", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call listUserIdsValidateBeforeCall( + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + return listUserIdsCall(page, hitsPerPage, callback); + } + + /** + * List the userIDs assigned to a multi-clusters appID. The data returned will usually be a few + * seconds behind real time, because userID usage may take up to a few seconds to propagate to the + * different clusters. Upon success, the response is 200 OK and contains the following userIDs + * data. + * + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional) + * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * @return ListUserIdsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ListUserIdsResponse listUserIds(Integer page, Integer hitsPerPage) + throws AlgoliaRuntimeException { + Call req = listUserIdsValidateBeforeCall(page, hitsPerPage, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ListUserIds(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public ListUserIdsResponse listUserIds() throws AlgoliaRuntimeException { + return this.listUserIds(null, 100); + } + + /** + * (asynchronously) List the userIDs assigned to a multi-clusters appID. The data returned will + * usually be a few seconds behind real time, because userID usage may take up to a few seconds to + * propagate to the different clusters. Upon success, the response is 200 OK and contains the + * following userIDs data. + * + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional) + * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call listUserIdsAsync( + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = listUserIdsValidateBeforeCall(page, hitsPerPage, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for multipleBatch + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call multipleBatchCall( + BatchParams batchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = batchParams; + + // create path and map variables + String requestPath = "/1/indexes/*/batch"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call multipleBatchValidateBeforeCall( + BatchParams batchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'batchParams' is set + if (batchParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'batchParams' when calling multipleBatch(Async)" + ); + } + + return multipleBatchCall(batchParams, callback); + } + + /** + * Perform multiple write operations, potentially targeting multiple indices, in a single API + * call. + * + * @param batchParams (required) + * @return MultipleBatchResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public MultipleBatchResponse multipleBatch(BatchParams batchParams) + throws AlgoliaRuntimeException { + Call req = multipleBatchValidateBeforeCall(batchParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.MultipleBatch(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Perform multiple write operations, potentially targeting multiple indices, in + * a single API call. + * + * @param batchParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call multipleBatchAsync( + BatchParams batchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = multipleBatchValidateBeforeCall(batchParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for multipleQueries + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call multipleQueriesCall( + MultipleQueriesParams multipleQueriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = multipleQueriesParams; + + // create path and map variables + String requestPath = "/1/indexes/*/queries"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call multipleQueriesValidateBeforeCall( + MultipleQueriesParams multipleQueriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'multipleQueriesParams' is set + if (multipleQueriesParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'multipleQueriesParams' when calling" + + " multipleQueries(Async)" + ); + } + + return multipleQueriesCall(multipleQueriesParams, callback); + } + + /** + * Get search results for the given requests. + * + * @param multipleQueriesParams (required) + * @return MultipleQueriesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public MultipleQueriesResponse multipleQueries( + MultipleQueriesParams multipleQueriesParams + ) throws AlgoliaRuntimeException { + Call req = multipleQueriesValidateBeforeCall(multipleQueriesParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.MultipleQueries(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get search results for the given requests. + * + * @param multipleQueriesParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call multipleQueriesAsync( + MultipleQueriesParams multipleQueriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = multipleQueriesValidateBeforeCall( + multipleQueriesParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for operationIndex + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call operationIndexCall( + String indexName, + OperationIndexParams operationIndexParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = operationIndexParams; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/operation".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call operationIndexValidateBeforeCall( + String indexName, + OperationIndexParams operationIndexParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling operationIndex(Async)" + ); + } + + // verify the required parameter 'operationIndexParams' is set + if (operationIndexParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'operationIndexParams' when calling" + + " operationIndex(Async)" + ); + } + + return operationIndexCall(indexName, operationIndexParams, callback); + } + + /** + * Peforms a copy or a move operation on a index. + * + * @param indexName The index in which to perform the request. (required) + * @param operationIndexParams (required) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse operationIndex( + String indexName, + OperationIndexParams operationIndexParams + ) throws AlgoliaRuntimeException { + Call req = operationIndexValidateBeforeCall( + indexName, + operationIndexParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.OperationIndex(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Peforms a copy or a move operation on a index. + * + * @param indexName The index in which to perform the request. (required) + * @param operationIndexParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call operationIndexAsync( + String indexName, + OperationIndexParams operationIndexParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = operationIndexValidateBeforeCall( + indexName, + operationIndexParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for partialUpdateObject + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call partialUpdateObjectCall( + String indexName, + String objectID, + List> attributeOrBuiltInOperation, + Boolean createIfNotExists, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = attributeOrBuiltInOperation; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/{objectID}/partial".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (createIfNotExists != null) { + queryParams.addAll( + this.parameterToPair("createIfNotExists", createIfNotExists) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call partialUpdateObjectValidateBeforeCall( + String indexName, + String objectID, + List> attributeOrBuiltInOperation, + Boolean createIfNotExists, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling partialUpdateObject(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling partialUpdateObject(Async)" + ); + } + + // verify the required parameter 'attributeOrBuiltInOperation' is set + if (attributeOrBuiltInOperation == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'attributeOrBuiltInOperation' when calling" + + " partialUpdateObject(Async)" + ); + } + + return partialUpdateObjectCall( + indexName, + objectID, + attributeOrBuiltInOperation, + createIfNotExists, + callback + ); + } + + /** + * Update one or more attributes of an existing object. This method lets you update only a part of + * an existing object, either by adding new attributes or updating existing ones. You can + * partially update several objects in a single method call. If the index targeted by this + * operation doesn't exist yet, it's automatically created. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param attributeOrBuiltInOperation List of attributes to update. (required) + * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to + * true) + * @return UpdatedAtWithObjectIdResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtWithObjectIdResponse partialUpdateObject( + String indexName, + String objectID, + List> attributeOrBuiltInOperation, + Boolean createIfNotExists + ) throws AlgoliaRuntimeException { + Call req = partialUpdateObjectValidateBeforeCall( + indexName, + objectID, + attributeOrBuiltInOperation, + createIfNotExists, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.PartialUpdateObject( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtWithObjectIdResponse partialUpdateObject( + String indexName, + String objectID, + List> attributeOrBuiltInOperation + ) throws AlgoliaRuntimeException { + return this.partialUpdateObject( + indexName, + objectID, + attributeOrBuiltInOperation, + true + ); + } + + /** + * (asynchronously) Update one or more attributes of an existing object. This method lets you + * update only a part of an existing object, either by adding new attributes or updating existing + * ones. You can partially update several objects in a single method call. If the index targeted + * by this operation doesn't exist yet, it's automatically created. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param attributeOrBuiltInOperation List of attributes to update. (required) + * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to + * true) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call partialUpdateObjectAsync( + String indexName, + String objectID, + List> attributeOrBuiltInOperation, + Boolean createIfNotExists, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = partialUpdateObjectValidateBeforeCall( + indexName, + objectID, + attributeOrBuiltInOperation, + createIfNotExists, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for post + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call postCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call postValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling post(Async)" + ); + } + + return postCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object post(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = postValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Post(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object post(String path) throws AlgoliaRuntimeException { + return this.post(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call postAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = postValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for put + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call putCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.addAll( + this.parameterToPair(parameter.getKey(), parameter.getValue()) + ); + } + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call putValidateBeforeCall( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'path' is set + if (path == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'path' when calling put(Async)" + ); + } + + return putCall(path, parameters, body, callback); + } + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @return Object + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public Object put(String path, Map parameters, Object body) + throws AlgoliaRuntimeException { + Call req = putValidateBeforeCall(path, parameters, body, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Put(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public Object put(String path) throws AlgoliaRuntimeException { + return this.put(path, new HashMap<>(), null); + } + + /** + * (asynchronously) This method allow you to send requests to the Algolia REST API. + * + * @param path The path of the API endpoint to target, anything after the /1 needs to be + * specified. (required) + * @param parameters Query parameters to be applied to the current query. (optional) + * @param body The parameters to send with the custom request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call putAsync( + String path, + Map parameters, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = putValidateBeforeCall(path, parameters, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for removeUserId + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call removeUserIdCall( + String userID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/clusters/mapping/{userID}".replaceAll( + "\\{userID\\}", + this.escapeString(userID.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "DELETE", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call removeUserIdValidateBeforeCall( + String userID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'userID' is set + if (userID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'userID' when calling removeUserId(Async)" + ); + } + + return removeUserIdCall(userID, callback); + } + + /** + * Remove a userID and its associated data from the multi-clusters. Upon success, the response is + * 200 OK and a task is created to remove the userID data and mapping. + * + * @param userID userID to assign. (required) + * @return RemoveUserIdResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public RemoveUserIdResponse removeUserId(String userID) + throws AlgoliaRuntimeException { + Call req = removeUserIdValidateBeforeCall(userID, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.RemoveUserId(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Remove a userID and its associated data from the multi-clusters. Upon success, + * the response is 200 OK and a task is created to remove the userID data and mapping. + * + * @param userID userID to assign. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call removeUserIdAsync( + String userID, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = removeUserIdValidateBeforeCall(userID, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for replaceSources + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call replaceSourcesCall( + List source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = source; + + // create path and map variables + String requestPath = "/1/security/sources"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call replaceSourcesValidateBeforeCall( + List source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'source' is set + if (source == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'source' when calling replaceSources(Async)" + ); + } + + return replaceSourcesCall(source, callback); + } + + /** + * Replace all allowed sources. + * + * @param source The sources to allow. (required) + * @return ReplaceSourceResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public ReplaceSourceResponse replaceSources(List source) + throws AlgoliaRuntimeException { + Call req = replaceSourcesValidateBeforeCall(source, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.ReplaceSources(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Replace all allowed sources. + * + * @param source The sources to allow. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call replaceSourcesAsync( + List source, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = replaceSourcesValidateBeforeCall(source, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for restoreApiKey + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call restoreApiKeyCall( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/keys/{key}/restore".replaceAll( + "\\{key\\}", + this.escapeString(key.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call restoreApiKeyValidateBeforeCall( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'key' is set + if (key == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'key' when calling restoreApiKey(Async)" + ); + } + + return restoreApiKeyCall(key, callback); + } + + /** + * Restore a deleted API key, along with its associated rights. + * + * @param key API Key string. (required) + * @return AddApiKeyResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public AddApiKeyResponse restoreApiKey(String key) + throws AlgoliaRuntimeException { + Call req = restoreApiKeyValidateBeforeCall(key, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.RestoreApiKey(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Restore a deleted API key, along with its associated rights. + * + * @param key API Key string. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call restoreApiKeyAsync( + String key, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = restoreApiKeyValidateBeforeCall(key, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for saveObject + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call saveObjectCall( + String indexName, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = body; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call saveObjectValidateBeforeCall( + String indexName, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling saveObject(Async)" + ); + } + + // verify the required parameter 'body' is set + if (body == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'body' when calling saveObject(Async)" + ); + } + + return saveObjectCall(indexName, body, callback); + } + + /** + * Add an object to the index, automatically assigning it an object ID. + * + * @param indexName The index in which to perform the request. (required) + * @param body The Algolia record. (required) + * @return SaveObjectResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SaveObjectResponse saveObject(String indexName, Object body) + throws AlgoliaRuntimeException { + Call req = saveObjectValidateBeforeCall(indexName, body, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SaveObject(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Add an object to the index, automatically assigning it an object ID. + * + * @param indexName The index in which to perform the request. (required) + * @param body The Algolia record. (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call saveObjectAsync( + String indexName, + Object body, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = saveObjectValidateBeforeCall(indexName, body, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for saveRule + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call saveRuleCall( + String indexName, + String objectID, + Rule rule, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = rule; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call saveRuleValidateBeforeCall( + String indexName, + String objectID, + Rule rule, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling saveRule(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling saveRule(Async)" + ); + } + + // verify the required parameter 'rule' is set + if (rule == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'rule' when calling saveRule(Async)" + ); + } + + return saveRuleCall(indexName, objectID, rule, forwardToReplicas, callback); + } + + /** + * Create or update the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param rule (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return UpdatedRuleResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedRuleResponse saveRule( + String indexName, + String objectID, + Rule rule, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = saveRuleValidateBeforeCall( + indexName, + objectID, + rule, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SaveRule(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedRuleResponse saveRule( + String indexName, + String objectID, + Rule rule + ) throws AlgoliaRuntimeException { + return this.saveRule(indexName, objectID, rule, null); + } + + /** + * (asynchronously) Create or update the Rule with the specified objectID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param rule (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call saveRuleAsync( + String indexName, + String objectID, + Rule rule, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = saveRuleValidateBeforeCall( + indexName, + objectID, + rule, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for saveSynonym + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call saveSynonymCall( + String indexName, + String objectID, + SynonymHit synonymHit, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = synonymHit; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call saveSynonymValidateBeforeCall( + String indexName, + String objectID, + SynonymHit synonymHit, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling saveSynonym(Async)" + ); + } + + // verify the required parameter 'objectID' is set + if (objectID == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'objectID' when calling saveSynonym(Async)" + ); + } + + // verify the required parameter 'synonymHit' is set + if (synonymHit == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'synonymHit' when calling saveSynonym(Async)" + ); + } + + return saveSynonymCall( + indexName, + objectID, + synonymHit, + forwardToReplicas, + callback + ); + } + + /** + * Create a new synonym object or update the existing synonym object with the given object ID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param synonymHit (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return SaveSynonymResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SaveSynonymResponse saveSynonym( + String indexName, + String objectID, + SynonymHit synonymHit, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = saveSynonymValidateBeforeCall( + indexName, + objectID, + synonymHit, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SaveSynonym(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public SaveSynonymResponse saveSynonym( + String indexName, + String objectID, + SynonymHit synonymHit + ) throws AlgoliaRuntimeException { + return this.saveSynonym(indexName, objectID, synonymHit, null); + } + + /** + * (asynchronously) Create a new synonym object or update the existing synonym object with the + * given object ID. + * + * @param indexName The index in which to perform the request. (required) + * @param objectID Unique identifier of an object. (required) + * @param synonymHit (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call saveSynonymAsync( + String indexName, + String objectID, + SynonymHit synonymHit, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = saveSynonymValidateBeforeCall( + indexName, + objectID, + synonymHit, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for saveSynonyms + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call saveSynonymsCall( + String indexName, + List synonymHit, + Boolean forwardToReplicas, + Boolean replaceExistingSynonyms, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = synonymHit; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/batch".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + if (replaceExistingSynonyms != null) { + queryParams.addAll( + this.parameterToPair("replaceExistingSynonyms", replaceExistingSynonyms) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call saveSynonymsValidateBeforeCall( + String indexName, + List synonymHit, + Boolean forwardToReplicas, + Boolean replaceExistingSynonyms, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling saveSynonyms(Async)" + ); + } + + // verify the required parameter 'synonymHit' is set + if (synonymHit == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'synonymHit' when calling saveSynonyms(Async)" + ); + } + + return saveSynonymsCall( + indexName, + synonymHit, + forwardToReplicas, + replaceExistingSynonyms, + callback + ); + } + + /** + * Create/update multiple synonym objects at once, potentially replacing the entire list of + * synonyms if replaceExistingSynonyms is true. + * + * @param indexName The index in which to perform the request. (required) + * @param synonymHit (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this + * request. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse saveSynonyms( + String indexName, + List synonymHit, + Boolean forwardToReplicas, + Boolean replaceExistingSynonyms + ) throws AlgoliaRuntimeException { + Call req = saveSynonymsValidateBeforeCall( + indexName, + synonymHit, + forwardToReplicas, + replaceExistingSynonyms, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SaveSynonyms(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse saveSynonyms( + String indexName, + List synonymHit + ) throws AlgoliaRuntimeException { + return this.saveSynonyms(indexName, synonymHit, null, null); + } + + /** + * (asynchronously) Create/update multiple synonym objects at once, potentially replacing the + * entire list of synonyms if replaceExistingSynonyms is true. + * + * @param indexName The index in which to perform the request. (required) + * @param synonymHit (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this + * request. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call saveSynonymsAsync( + String indexName, + List synonymHit, + Boolean forwardToReplicas, + Boolean replaceExistingSynonyms, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = saveSynonymsValidateBeforeCall( + indexName, + synonymHit, + forwardToReplicas, + replaceExistingSynonyms, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for search + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchCall( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchParams; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/query".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchValidateBeforeCall( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling search(Async)" + ); + } + + // verify the required parameter 'searchParams' is set + if (searchParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'searchParams' when calling search(Async)" + ); + } + + return searchCall(indexName, searchParams, callback); + } + + /** + * Get search results. + * + * @param indexName The index in which to perform the request. (required) + * @param searchParams (required) + * @return SearchResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SearchResponse search(String indexName, SearchParams searchParams) + throws AlgoliaRuntimeException { + Call req = searchValidateBeforeCall(indexName, searchParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.Search(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Get search results. + * + * @param indexName The index in which to perform the request. (required) + * @param searchParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchAsync( + String indexName, + SearchParams searchParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchValidateBeforeCall(indexName, searchParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for searchDictionaryEntries + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchDictionaryEntriesCall( + DictionaryType dictionaryName, + SearchDictionaryEntriesParams searchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchDictionaryEntriesParams; + + // create path and map variables + String requestPath = + "/1/dictionaries/{dictionaryName}/search".replaceAll( + "\\{dictionaryName\\}", + this.escapeString(dictionaryName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchDictionaryEntriesValidateBeforeCall( + DictionaryType dictionaryName, + SearchDictionaryEntriesParams searchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'dictionaryName' is set + if (dictionaryName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'dictionaryName' when calling" + + " searchDictionaryEntries(Async)" + ); + } + + // verify the required parameter 'searchDictionaryEntriesParams' is set + if (searchDictionaryEntriesParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'searchDictionaryEntriesParams' when calling" + + " searchDictionaryEntries(Async)" + ); + } + + return searchDictionaryEntriesCall( + dictionaryName, + searchDictionaryEntriesParams, + callback + ); + } + + /** + * Search the dictionary entries. + * + * @param dictionaryName The dictionary to search in. (required) + * @param searchDictionaryEntriesParams (required) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse searchDictionaryEntries( + DictionaryType dictionaryName, + SearchDictionaryEntriesParams searchDictionaryEntriesParams + ) throws AlgoliaRuntimeException { + Call req = searchDictionaryEntriesValidateBeforeCall( + dictionaryName, + searchDictionaryEntriesParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SearchDictionaryEntries( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Search the dictionary entries. + * + * @param dictionaryName The dictionary to search in. (required) + * @param searchDictionaryEntriesParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchDictionaryEntriesAsync( + DictionaryType dictionaryName, + SearchDictionaryEntriesParams searchDictionaryEntriesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchDictionaryEntriesValidateBeforeCall( + dictionaryName, + searchDictionaryEntriesParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for searchForFacetValues + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchForFacetValuesCall( + String indexName, + String facetName, + SearchForFacetValuesRequest searchForFacetValuesRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchForFacetValuesRequest; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/facets/{facetName}/query".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ) + .replaceAll("\\{facetName\\}", this.escapeString(facetName.toString())); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchForFacetValuesValidateBeforeCall( + String indexName, + String facetName, + SearchForFacetValuesRequest searchForFacetValuesRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling searchForFacetValues(Async)" + ); + } + + // verify the required parameter 'facetName' is set + if (facetName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'facetName' when calling searchForFacetValues(Async)" + ); + } + + return searchForFacetValuesCall( + indexName, + facetName, + searchForFacetValuesRequest, + callback + ); + } + + /** + * Search for values of a given facet, optionally restricting the returned values to those + * contained in objects matching other search criteria. + * + * @param indexName The index in which to perform the request. (required) + * @param facetName The facet name. (required) + * @param searchForFacetValuesRequest (optional) + * @return SearchForFacetValuesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SearchForFacetValuesResponse searchForFacetValues( + String indexName, + String facetName, + SearchForFacetValuesRequest searchForFacetValuesRequest + ) throws AlgoliaRuntimeException { + Call req = searchForFacetValuesValidateBeforeCall( + indexName, + facetName, + searchForFacetValuesRequest, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SearchForFacetValues( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {} + .getType(); + ApiResponse res = + this.execute(call, returnType); + return res.getData(); + } + + public SearchForFacetValuesResponse searchForFacetValues( + String indexName, + String facetName + ) throws AlgoliaRuntimeException { + return this.searchForFacetValues(indexName, facetName, null); + } + + /** + * (asynchronously) Search for values of a given facet, optionally restricting the returned values + * to those contained in objects matching other search criteria. + * + * @param indexName The index in which to perform the request. (required) + * @param facetName The facet name. (required) + * @param searchForFacetValuesRequest (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchForFacetValuesAsync( + String indexName, + String facetName, + SearchForFacetValuesRequest searchForFacetValuesRequest, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchForFacetValuesValidateBeforeCall( + indexName, + facetName, + searchForFacetValuesRequest, + callback + ); + Type returnType = new TypeToken() {} + .getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for searchRules + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchRulesCall( + String indexName, + SearchRulesParams searchRulesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchRulesParams; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/rules/search".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchRulesValidateBeforeCall( + String indexName, + SearchRulesParams searchRulesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling searchRules(Async)" + ); + } + + // verify the required parameter 'searchRulesParams' is set + if (searchRulesParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'searchRulesParams' when calling searchRules(Async)" + ); + } + + return searchRulesCall(indexName, searchRulesParams, callback); + } + + /** + * Search for rules matching various criteria. + * + * @param indexName The index in which to perform the request. (required) + * @param searchRulesParams (required) + * @return SearchRulesResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SearchRulesResponse searchRules( + String indexName, + SearchRulesParams searchRulesParams + ) throws AlgoliaRuntimeException { + Call req = searchRulesValidateBeforeCall( + indexName, + searchRulesParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SearchRules(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Search for rules matching various criteria. + * + * @param indexName The index in which to perform the request. (required) + * @param searchRulesParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchRulesAsync( + String indexName, + SearchRulesParams searchRulesParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchRulesValidateBeforeCall( + indexName, + searchRulesParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for searchSynonyms + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchSynonymsCall( + String indexName, + String query, + SynonymType type, + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = null; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/synonyms/search".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (query != null) { + queryParams.addAll(this.parameterToPair("query", query)); + } + + if (type != null) { + queryParams.addAll(this.parameterToPair("type", type)); + } + + if (page != null) { + queryParams.addAll(this.parameterToPair("page", page)); + } + + if (hitsPerPage != null) { + queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchSynonymsValidateBeforeCall( + String indexName, + String query, + SynonymType type, + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling searchSynonyms(Async)" + ); + } + + return searchSynonymsCall( + indexName, + query, + type, + page, + hitsPerPage, + callback + ); + } + + /** + * Search or browse all synonyms, optionally filtering them by type. + * + * @param indexName The index in which to perform the request. (required) + * @param query Search for specific synonyms matching this string. (optional, default to ) + * @param type Only search for specific types of synonyms. (optional) + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional, default to 0) + * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * @return SearchSynonymsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SearchSynonymsResponse searchSynonyms( + String indexName, + String query, + SynonymType type, + Integer page, + Integer hitsPerPage + ) throws AlgoliaRuntimeException { + Call req = searchSynonymsValidateBeforeCall( + indexName, + query, + type, + page, + hitsPerPage, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SearchSynonyms(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public SearchSynonymsResponse searchSynonyms(String indexName) + throws AlgoliaRuntimeException { + return this.searchSynonyms(indexName, "", null, 0, 100); + } + + /** + * (asynchronously) Search or browse all synonyms, optionally filtering them by type. + * + * @param indexName The index in which to perform the request. (required) + * @param query Search for specific synonyms matching this string. (optional, default to ) + * @param type Only search for specific types of synonyms. (optional) + * @param page Requested page (zero-based). When specified, will retrieve a specific page; the + * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * (optional, default to 0) + * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchSynonymsAsync( + String indexName, + String query, + SynonymType type, + Integer page, + Integer hitsPerPage, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchSynonymsValidateBeforeCall( + indexName, + query, + type, + page, + hitsPerPage, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for searchUserIds + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call searchUserIdsCall( + SearchUserIdsParams searchUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = searchUserIdsParams; + + // create path and map variables + String requestPath = "/1/clusters/mapping/search"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "POST", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call searchUserIdsValidateBeforeCall( + SearchUserIdsParams searchUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'searchUserIdsParams' is set + if (searchUserIdsParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'searchUserIdsParams' when calling searchUserIds(Async)" + ); + } + + return searchUserIdsCall(searchUserIdsParams, callback); + } + + /** + * Search for userIDs. The data returned will usually be a few seconds behind real time, because + * userID usage may take up to a few seconds propagate to the different clusters. To keep updates + * moving quickly, the index of userIDs isn't built synchronously with the mapping. Instead, the + * index is built once every 12h, at the same time as the update of userID usage. For example, + * when you perform a modification like adding or moving a userID, the search will report an + * outdated value until the next rebuild of the mapping, which takes place every 12h. Upon + * success, the response is 200 OK and contains the following userIDs data. + * + * @param searchUserIdsParams (required) + * @return SearchUserIdsResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public SearchUserIdsResponse searchUserIds( + SearchUserIdsParams searchUserIdsParams + ) throws AlgoliaRuntimeException { + Call req = searchUserIdsValidateBeforeCall(searchUserIdsParams, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SearchUserIds(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Search for userIDs. The data returned will usually be a few seconds behind + * real time, because userID usage may take up to a few seconds propagate to the different + * clusters. To keep updates moving quickly, the index of userIDs isn't built synchronously + * with the mapping. Instead, the index is built once every 12h, at the same time as the update of + * userID usage. For example, when you perform a modification like adding or moving a userID, the + * search will report an outdated value until the next rebuild of the mapping, which takes place + * every 12h. Upon success, the response is 200 OK and contains the following userIDs data. + * + * @param searchUserIdsParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call searchUserIdsAsync( + SearchUserIdsParams searchUserIdsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = searchUserIdsValidateBeforeCall(searchUserIdsParams, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for setDictionarySettings + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call setDictionarySettingsCall( + DictionarySettingsParams dictionarySettingsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = dictionarySettingsParams; + + // create path and map variables + String requestPath = "/1/dictionaries/*/settings"; + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call setDictionarySettingsValidateBeforeCall( + DictionarySettingsParams dictionarySettingsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'dictionarySettingsParams' is set + if (dictionarySettingsParams == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'dictionarySettingsParams' when calling" + + " setDictionarySettings(Async)" + ); + } + + return setDictionarySettingsCall(dictionarySettingsParams, callback); + } + + /** + * Set dictionary settings. + * + * @param dictionarySettingsParams (required) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse setDictionarySettings( + DictionarySettingsParams dictionarySettingsParams + ) throws AlgoliaRuntimeException { + Call req = setDictionarySettingsValidateBeforeCall( + dictionarySettingsParams, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SetDictionarySettings( + ((CallEcho) req).request() + ); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Set dictionary settings. + * + * @param dictionarySettingsParams (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call setDictionarySettingsAsync( + DictionarySettingsParams dictionarySettingsParams, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = setDictionarySettingsValidateBeforeCall( + dictionarySettingsParams, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for setSettings + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call setSettingsCall( + String indexName, + IndexSettings indexSettings, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = indexSettings; + + // create path and map variables + String requestPath = + "/1/indexes/{indexName}/settings".replaceAll( + "\\{indexName\\}", + this.escapeString(indexName.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + if (forwardToReplicas != null) { + queryParams.addAll( + this.parameterToPair("forwardToReplicas", forwardToReplicas) + ); + } + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call setSettingsValidateBeforeCall( + String indexName, + IndexSettings indexSettings, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'indexName' is set + if (indexName == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexName' when calling setSettings(Async)" + ); + } + + // verify the required parameter 'indexSettings' is set + if (indexSettings == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'indexSettings' when calling setSettings(Async)" + ); + } + + return setSettingsCall( + indexName, + indexSettings, + forwardToReplicas, + callback + ); + } + + /** + * Update settings of a given indexName. Only specified settings are overridden; unspecified + * settings are left unchanged. Specifying null for a setting resets it to its default value. + * + * @param indexName The index in which to perform the request. (required) + * @param indexSettings (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @return UpdatedAtResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdatedAtResponse setSettings( + String indexName, + IndexSettings indexSettings, + Boolean forwardToReplicas + ) throws AlgoliaRuntimeException { + Call req = setSettingsValidateBeforeCall( + indexName, + indexSettings, + forwardToReplicas, + null + ); + if (req instanceof CallEcho) { + return new EchoResponseSearch.SetSettings(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + public UpdatedAtResponse setSettings( + String indexName, + IndexSettings indexSettings + ) throws AlgoliaRuntimeException { + return this.setSettings(indexName, indexSettings, null); + } + + /** + * (asynchronously) Update settings of a given indexName. Only specified settings are overridden; + * unspecified settings are left unchanged. Specifying null for a setting resets it to its default + * value. + * + * @param indexName The index in which to perform the request. (required) + * @param indexSettings (required) + * @param forwardToReplicas When true, changes are also propagated to replicas of the given + * indexName. (optional) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call setSettingsAsync( + String indexName, + IndexSettings indexSettings, + Boolean forwardToReplicas, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = setSettingsValidateBeforeCall( + indexName, + indexSettings, + forwardToReplicas, + callback + ); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } + + /** + * Build call for updateApiKey + * + * @param callback Callback for upload/download progress + * @return Call to execute + * @throws AlgoliaRuntimeException If fail to serialize the request body object + */ + private Call updateApiKeyCall( + String key, + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Object bodyObj = apiKey; + + // create path and map variables + String requestPath = + "/1/keys/{key}".replaceAll( + "\\{key\\}", + this.escapeString(key.toString()) + ); + + List queryParams = new ArrayList(); + Map headers = new HashMap(); + + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + return this.buildCall( + requestPath, + "PUT", + queryParams, + bodyObj, + headers, + callback + ); + } + + private Call updateApiKeyValidateBeforeCall( + String key, + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + // verify the required parameter 'key' is set + if (key == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'key' when calling updateApiKey(Async)" + ); + } + + // verify the required parameter 'apiKey' is set + if (apiKey == null) { + throw new AlgoliaRuntimeException( + "Missing the required parameter 'apiKey' when calling updateApiKey(Async)" + ); + } + + return updateApiKeyCall(key, apiKey, callback); + } + + /** + * Replace every permission of an existing API key. + * + * @param key API Key string. (required) + * @param apiKey (required) + * @return UpdateApiKeyResponse + * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot + * deserialize the response body + */ + public UpdateApiKeyResponse updateApiKey(String key, ApiKey apiKey) + throws AlgoliaRuntimeException { + Call req = updateApiKeyValidateBeforeCall(key, apiKey, null); + if (req instanceof CallEcho) { + return new EchoResponseSearch.UpdateApiKey(((CallEcho) req).request()); + } + Call call = (Call) req; + Type returnType = new TypeToken() {}.getType(); + ApiResponse res = this.execute(call, returnType); + return res.getData(); + } + + /** + * (asynchronously) Replace every permission of an existing API key. + * + * @param key API Key string. (required) + * @param apiKey (required) + * @param callback The callback to be executed when the API call finishes + * @return The request call + * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request + * body object + */ + public Call updateApiKeyAsync( + String key, + ApiKey apiKey, + final ApiCallback callback + ) throws AlgoliaRuntimeException { + Call call = updateApiKeyValidateBeforeCall(key, apiKey, callback); + Type returnType = new TypeToken() {}.getType(); + this.executeAsync(call, returnType, callback); + return call; + } +} diff --git a/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts b/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts new file mode 100644 index 0000000000..54b4e0b70c --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteApi.ts @@ -0,0 +1,305 @@ +import { + createAuth, + createTransporter, + getUserAgent, + shuffle, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { MultipleQueriesParams } from '../model/multipleQueriesParams'; +import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; +import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest'; +import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse'; +import type { SearchParams } from '../model/searchParams'; +import type { SearchResponse } from '../model/searchResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +function getDefaultHosts(appId: string): Host[] { + return ( + [ + { + url: `${appId}-dsn.algolia.net`, + accept: 'read', + protocol: 'https', + }, + { + url: `${appId}.algolia.net`, + accept: 'write', + protocol: 'https', + }, + ] as Host[] + ).concat( + shuffle([ + { + url: `${appId}-1.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-2.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-3.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]) + ); +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createAlgoliasearchLiteApi(options: CreateClientOptions) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.appId), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'AlgoliasearchLite', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * Get search results for the given requests. + * + * @summary Get search results for the given requests. + * @param multipleQueriesParams - The multipleQueriesParams object. + */ + multipleQueries( + multipleQueriesParams: MultipleQueriesParams, + requestOptions?: RequestOptions + ): Promise { + if (!multipleQueriesParams) { + throw new Error( + 'Parameter `multipleQueriesParams` is required when calling `multipleQueries`.' + ); + } + + if (!multipleQueriesParams.requests) { + throw new Error( + 'Parameter `multipleQueriesParams.requests` is required when calling `multipleQueries`.' + ); + } + + const requestPath = '/1/indexes/*/queries'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: multipleQueriesParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get search results. + * + * @summary Get search results. + * @param search - The search object. + * @param search.indexName - The index in which to perform the request. + * @param search.searchParams - The searchParams object. + */ + search( + { indexName, searchParams }: SearchProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `search`.' + ); + } + + if (!searchParams) { + throw new Error( + 'Parameter `searchParams` is required when calling `search`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/query'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search for values of a given facet, optionally restricting the returned values to those contained in objects matching other search criteria. + * + * @summary Search for values of a given facet. + * @param searchForFacetValues - The searchForFacetValues object. + * @param searchForFacetValues.indexName - The index in which to perform the request. + * @param searchForFacetValues.facetName - The facet name. + * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object. + */ + searchForFacetValues( + { + indexName, + facetName, + searchForFacetValuesRequest, + }: SearchForFacetValuesProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `searchForFacetValues`.' + ); + } + + if (!facetName) { + throw new Error( + 'Parameter `facetName` is required when calling `searchForFacetValues`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/facets/{facetName}/query' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{facetName}', encodeURIComponent(facetName)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchForFacetValuesRequest, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type AlgoliasearchLiteApi = ReturnType< + typeof createAlgoliasearchLiteApi +>; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type SearchProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + searchParams: SearchParams; +}; + +export type SearchForFacetValuesProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * The facet name. + */ + facetName: string; + searchForFacetValuesRequest?: SearchForFacetValuesRequest; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts new file mode 100644 index 0000000000..c03d450203 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts @@ -0,0 +1,503 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { ABTest } from '../model/aBTest'; +import type { ABTestResponse } from '../model/aBTestResponse'; +import type { AddABTestsRequest } from '../model/addABTestsRequest'; +import type { ListABTestsResponse } from '../model/listABTestsResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +export type Region = 'de' | 'us'; + +function getDefaultHosts(region?: Region): Host[] { + const regionHost = region ? `.${region}.` : '.'; + + return [ + { + url: `analytics${regionHost}algolia.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createAbtestingApi( + options: CreateClientOptions & { region?: Region } +) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.region), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Abtesting', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * Creates a new A/B test with provided configuration. You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants. + * + * @summary Creates a new A/B test with provided configuration. + * @param addABTestsRequest - The addABTestsRequest object. + */ + addABTests( + addABTestsRequest: AddABTestsRequest, + requestOptions?: RequestOptions + ): Promise { + if (!addABTestsRequest) { + throw new Error( + 'Parameter `addABTestsRequest` is required when calling `addABTests`.' + ); + } + + if (!addABTestsRequest.name) { + throw new Error( + 'Parameter `addABTestsRequest.name` is required when calling `addABTests`.' + ); + } + if (!addABTestsRequest.variant) { + throw new Error( + 'Parameter `addABTestsRequest.variant` is required when calling `addABTests`.' + ); + } + if (!addABTestsRequest.endAt) { + throw new Error( + 'Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.' + ); + } + + const requestPath = '/2/abtests'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: addABTestsRequest, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Deletes the A/B Test and removes all associated metadata & metrics. + * + * @summary Deletes the A/B Test. + * @param deleteABTest - The deleteABTest object. + * @param deleteABTest.id - The A/B test ID. + */ + deleteABTest( + { id }: DeleteABTestProps, + requestOptions?: RequestOptions + ): Promise { + if (!id) { + throw new Error( + 'Parameter `id` is required when calling `deleteABTest`.' + ); + } + + const requestPath = '/2/abtests/{id}'.replace( + '{id}', + encodeURIComponent(id) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns metadata and metrics for A/B test id. Behaves in the same way as GET /2/abtests however the endpoint will return 403. + * + * @summary Returns metadata and metrics for A/B test id. + * @param getABTest - The getABTest object. + * @param getABTest.id - The A/B test ID. + */ + getABTest( + { id }: GetABTestProps, + requestOptions?: RequestOptions + ): Promise { + if (!id) { + throw new Error('Parameter `id` is required when calling `getABTest`.'); + } + + const requestPath = '/2/abtests/{id}'.replace( + '{id}', + encodeURIComponent(id) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Fetch all existing A/B tests for App that are available for the current API Key. Returns an array of metadata and metrics. When no data has been processed, the metrics will be returned as null. + * + * @summary Fetch all existing A/B tests for App that are available for the current API Key. + * @param listABTests - The listABTests object. + * @param listABTests.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param listABTests.limit - Number of records to return. Limit is the size of the page. + */ + listABTests( + { offset, limit }: ListABTestsProps, + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/2/abtests'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Marks the A/B test as stopped. At this point, the test is over and cannot be restarted. As a result, your application is back to normal: index A will perform as usual, receiving 100% of all search requests. Associated metadata and metrics are still stored. + * + * @summary Marks the A/B test as stopped. + * @param stopABTest - The stopABTest object. + * @param stopABTest.id - The A/B test ID. + */ + stopABTest( + { id }: StopABTestProps, + requestOptions?: RequestOptions + ): Promise { + if (!id) { + throw new Error( + 'Parameter `id` is required when calling `stopABTest`.' + ); + } + + const requestPath = '/2/abtests/{id}/stop'.replace( + '{id}', + encodeURIComponent(id) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type AbtestingApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type DeleteABTestProps = { + /** + * The A/B test ID. + */ + id: number; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetABTestProps = { + /** + * The A/B test ID. + */ + id: number; +}; + +export type ListABTestsProps = { + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type StopABTestProps = { + /** + * The A/B test ID. + */ + id: number; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts b/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts new file mode 100644 index 0000000000..77d5a7e04c --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts @@ -0,0 +1,1799 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { Direction } from '../model/direction'; +import type { GetAverageClickPositionResponse } from '../model/getAverageClickPositionResponse'; +import type { GetClickPositionsResponse } from '../model/getClickPositionsResponse'; +import type { GetClickThroughRateResponse } from '../model/getClickThroughRateResponse'; +import type { GetConversationRateResponse } from '../model/getConversationRateResponse'; +import type { GetNoClickRateResponse } from '../model/getNoClickRateResponse'; +import type { GetNoResultsRateResponse } from '../model/getNoResultsRateResponse'; +import type { GetSearchesCountResponse } from '../model/getSearchesCountResponse'; +import type { GetSearchesNoClicksResponse } from '../model/getSearchesNoClicksResponse'; +import type { GetSearchesNoResultsResponse } from '../model/getSearchesNoResultsResponse'; +import type { GetStatusResponse } from '../model/getStatusResponse'; +import type { GetTopCountriesResponse } from '../model/getTopCountriesResponse'; +import type { GetTopFilterAttributesResponse } from '../model/getTopFilterAttributesResponse'; +import type { GetTopFilterForAttributeResponse } from '../model/getTopFilterForAttributeResponse'; +import type { GetTopFiltersNoResultsResponse } from '../model/getTopFiltersNoResultsResponse'; +import type { GetTopHitsResponse } from '../model/getTopHitsResponse'; +import type { GetTopSearchesResponse } from '../model/getTopSearchesResponse'; +import type { GetUsersCountResponse } from '../model/getUsersCountResponse'; +import type { OrderBy } from '../model/orderBy'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +export type Region = 'de' | 'us'; + +function getDefaultHosts(region?: Region): Host[] { + const regionHost = region ? `.${region}.` : '.'; + + return [ + { + url: `analytics${regionHost}algolia.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createAnalyticsApi( + options: CreateClientOptions & { region?: Region } +) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.region), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Analytics', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the average click position. The endpoint returns a value for the complete given time range, as well as a value per day. + * + * @summary Returns the average click position. + * @param getAverageClickPosition - The getAverageClickPosition object. + * @param getAverageClickPosition.index - The index name to target. + * @param getAverageClickPosition.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getAverageClickPosition.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getAverageClickPosition.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getAverageClickPosition( + { index, startDate, endDate, tags }: GetAverageClickPositionProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getAverageClickPosition`.' + ); + } + + const requestPath = '/2/clicks/averageClickPosition'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the distribution of clicks per range of positions. + * + * @summary Returns the distribution of clicks per range of positions. + * @param getClickPositions - The getClickPositions object. + * @param getClickPositions.index - The index name to target. + * @param getClickPositions.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getClickPositions.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getClickPositions.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getClickPositions( + { index, startDate, endDate, tags }: GetClickPositionsProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getClickPositions`.' + ); + } + + const requestPath = '/2/clicks/positions'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns a click-through rate (CTR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of clicks and searches used to compute the rates. + * + * @summary Returns a click-through rate (CTR). + * @param getClickThroughRate - The getClickThroughRate object. + * @param getClickThroughRate.index - The index name to target. + * @param getClickThroughRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getClickThroughRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getClickThroughRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getClickThroughRate( + { index, startDate, endDate, tags }: GetClickThroughRateProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getClickThroughRate`.' + ); + } + + const requestPath = '/2/clicks/clickThroughRate'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns a conversion rate (CR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of conversion and searches used to compute the rates. + * + * @summary Returns a conversion rate (CR). + * @param getConversationRate - The getConversationRate object. + * @param getConversationRate.index - The index name to target. + * @param getConversationRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getConversationRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getConversationRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getConversationRate( + { index, startDate, endDate, tags }: GetConversationRateProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getConversationRate`.' + ); + } + + const requestPath = '/2/conversions/conversionRate'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the rate at which searches didn\'t lead to any clicks. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without clicks. + * + * @summary Returns the rate at which searches didn\'t lead to any clicks. + * @param getNoClickRate - The getNoClickRate object. + * @param getNoClickRate.index - The index name to target. + * @param getNoClickRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getNoClickRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getNoClickRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getNoClickRate( + { index, startDate, endDate, tags }: GetNoClickRateProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getNoClickRate`.' + ); + } + + const requestPath = '/2/searches/noClickRate'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the rate at which searches didn\'t return any results. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without results used to compute the rates. + * + * @summary Returns the rate at which searches didn\'t return any results. + * @param getNoResultsRate - The getNoResultsRate object. + * @param getNoResultsRate.index - The index name to target. + * @param getNoResultsRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getNoResultsRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getNoResultsRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getNoResultsRate( + { index, startDate, endDate, tags }: GetNoResultsRateProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getNoResultsRate`.' + ); + } + + const requestPath = '/2/searches/noResultRate'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the number of searches across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day. + * + * @summary Returns the number of searches across the given time range. + * @param getSearchesCount - The getSearchesCount object. + * @param getSearchesCount.index - The index name to target. + * @param getSearchesCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getSearchesCount( + { index, startDate, endDate, tags }: GetSearchesCountProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getSearchesCount`.' + ); + } + + const requestPath = '/2/searches/count'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top searches that didn\'t lead to any clicks. Limited to the 1000 most frequent ones. For each search, also returns the average number of found hits. + * + * @summary Returns top searches that didn\'t lead to any clicks. + * @param getSearchesNoClicks - The getSearchesNoClicks object. + * @param getSearchesNoClicks.index - The index name to target. + * @param getSearchesNoClicks.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesNoClicks.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesNoClicks.limit - Number of records to return. Limit is the size of the page. + * @param getSearchesNoClicks.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getSearchesNoClicks.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getSearchesNoClicks( + { + index, + startDate, + endDate, + limit, + offset, + tags, + }: GetSearchesNoClicksProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getSearchesNoClicks`.' + ); + } + + const requestPath = '/2/searches/noClicks'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top searches that didn\'t return any results. Limited to the 1000 most frequent ones. + * + * @summary Returns top searches that didn\'t return any results. + * @param getSearchesNoResults - The getSearchesNoResults object. + * @param getSearchesNoResults.index - The index name to target. + * @param getSearchesNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getSearchesNoResults.limit - Number of records to return. Limit is the size of the page. + * @param getSearchesNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getSearchesNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getSearchesNoResults( + { + index, + startDate, + endDate, + limit, + offset, + tags, + }: GetSearchesNoResultsProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getSearchesNoResults`.' + ); + } + + const requestPath = '/2/searches/noResults'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the latest update time of the analytics API for a given index. If the index has been recently created and/or no search has been performed yet the updated time will be null. + * + * @summary Get latest update time of the analytics API. + * @param getStatus - The getStatus object. + * @param getStatus.index - The index name to target. + */ + getStatus( + { index }: GetStatusProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getStatus`.' + ); + } + + const requestPath = '/2/status'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top countries. Limited to the 1000 most frequent ones. + * + * @summary Returns top countries. + * @param getTopCountries - The getTopCountries object. + * @param getTopCountries.index - The index name to target. + * @param getTopCountries.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopCountries.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopCountries.limit - Number of records to return. Limit is the size of the page. + * @param getTopCountries.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopCountries.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopCountries( + { index, startDate, endDate, limit, offset, tags }: GetTopCountriesProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopCountries`.' + ); + } + + const requestPath = '/2/countries'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top filter attributes. Limited to the 1000 most used filters. + * + * @summary Returns top filter attributes. + * @param getTopFilterAttributes - The getTopFilterAttributes object. + * @param getTopFilterAttributes.index - The index name to target. + * @param getTopFilterAttributes.search - The query term to search for. Must match the exact user input. + * @param getTopFilterAttributes.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFilterAttributes.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFilterAttributes.limit - Number of records to return. Limit is the size of the page. + * @param getTopFilterAttributes.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopFilterAttributes.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopFilterAttributes( + { + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFilterAttributesProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopFilterAttributes`.' + ); + } + + const requestPath = '/2/filters'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (search !== undefined) { + queryParameters.search = search.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top filters for the given attribute. Limited to the 1000 most used filters. + * + * @summary Returns top filters for the given attribute. + * @param getTopFilterForAttribute - The getTopFilterForAttribute object. + * @param getTopFilterForAttribute.attribute - The exact name of the attribute. + * @param getTopFilterForAttribute.index - The index name to target. + * @param getTopFilterForAttribute.search - The query term to search for. Must match the exact user input. + * @param getTopFilterForAttribute.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFilterForAttribute.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFilterForAttribute.limit - Number of records to return. Limit is the size of the page. + * @param getTopFilterForAttribute.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopFilterForAttribute.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopFilterForAttribute( + { + attribute, + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFilterForAttributeProps, + requestOptions?: RequestOptions + ): Promise { + if (!attribute) { + throw new Error( + 'Parameter `attribute` is required when calling `getTopFilterForAttribute`.' + ); + } + + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopFilterForAttribute`.' + ); + } + + const requestPath = '/2/filters/{attribute}'.replace( + '{attribute}', + encodeURIComponent(attribute) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (search !== undefined) { + queryParameters.search = search.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top filters with no results. Limited to the 1000 most used filters. + * + * @summary Returns top filters with no results. + * @param getTopFiltersNoResults - The getTopFiltersNoResults object. + * @param getTopFiltersNoResults.index - The index name to target. + * @param getTopFiltersNoResults.search - The query term to search for. Must match the exact user input. + * @param getTopFiltersNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFiltersNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopFiltersNoResults.limit - Number of records to return. Limit is the size of the page. + * @param getTopFiltersNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopFiltersNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopFiltersNoResults( + { + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFiltersNoResultsProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopFiltersNoResults`.' + ); + } + + const requestPath = '/2/filters/noResults'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (search !== undefined) { + queryParameters.search = search.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top hits. Limited to the 1000 most frequent ones. + * + * @summary Returns top hits. + * @param getTopHits - The getTopHits object. + * @param getTopHits.index - The index name to target. + * @param getTopHits.search - The query term to search for. Must match the exact user input. + * @param getTopHits.clickAnalytics - Whether to include the click-through and conversion rates for a search. + * @param getTopHits.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopHits.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopHits.limit - Number of records to return. Limit is the size of the page. + * @param getTopHits.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopHits.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopHits( + { + index, + search, + clickAnalytics, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopHitsProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopHits`.' + ); + } + + const requestPath = '/2/hits'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (search !== undefined) { + queryParameters.search = search.toString(); + } + + if (clickAnalytics !== undefined) { + queryParameters.clickAnalytics = clickAnalytics.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns top searches. Limited to the 1000 most frequent ones. For each search, also returns the average number of hits returned. + * + * @summary Returns top searches. + * @param getTopSearches - The getTopSearches object. + * @param getTopSearches.index - The index name to target. + * @param getTopSearches.clickAnalytics - Whether to include the click-through and conversion rates for a search. + * @param getTopSearches.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopSearches.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getTopSearches.orderBy - Reorder the results. + * @param getTopSearches.direction - The sorting of the result. + * @param getTopSearches.limit - Number of records to return. Limit is the size of the page. + * @param getTopSearches.offset - Position of the starting record. Used for paging. 0 is the first record. + * @param getTopSearches.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getTopSearches( + { + index, + clickAnalytics, + startDate, + endDate, + orderBy, + direction, + limit, + offset, + tags, + }: GetTopSearchesProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getTopSearches`.' + ); + } + + const requestPath = '/2/searches'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (clickAnalytics !== undefined) { + queryParameters.clickAnalytics = clickAnalytics.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (orderBy !== undefined) { + queryParameters.orderBy = orderBy.toString(); + } + + if (direction !== undefined) { + queryParameters.direction = direction.toString(); + } + + if (limit !== undefined) { + queryParameters.limit = limit.toString(); + } + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the distinct count of users across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day. + * + * @summary Returns the distinct count of users across the given time range. + * @param getUsersCount - The getUsersCount object. + * @param getUsersCount.index - The index name to target. + * @param getUsersCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getUsersCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + * @param getUsersCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + getUsersCount( + { index, startDate, endDate, tags }: GetUsersCountProps, + requestOptions?: RequestOptions + ): Promise { + if (!index) { + throw new Error( + 'Parameter `index` is required when calling `getUsersCount`.' + ); + } + + const requestPath = '/2/users/count'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (index !== undefined) { + queryParameters.index = index.toString(); + } + + if (startDate !== undefined) { + queryParameters.startDate = startDate.toString(); + } + + if (endDate !== undefined) { + queryParameters.endDate = endDate.toString(); + } + + if (tags !== undefined) { + queryParameters.tags = tags.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type AnalyticsApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetAverageClickPositionProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetClickPositionsProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetClickThroughRateProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetConversationRateProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetNoClickRateProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetNoResultsRateProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetSearchesCountProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetSearchesNoClicksProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetSearchesNoResultsProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetStatusProps = { + /** + * The index name to target. + */ + index: string; +}; + +export type GetTopCountriesProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetTopFilterAttributesProps = { + /** + * The index name to target. + */ + index: string; + /** + * The query term to search for. Must match the exact user input. + */ + search?: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetTopFilterForAttributeProps = { + /** + * The exact name of the attribute. + */ + attribute: string; + /** + * The index name to target. + */ + index: string; + /** + * The query term to search for. Must match the exact user input. + */ + search?: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetTopFiltersNoResultsProps = { + /** + * The index name to target. + */ + index: string; + /** + * The query term to search for. Must match the exact user input. + */ + search?: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetTopHitsProps = { + /** + * The index name to target. + */ + index: string; + /** + * The query term to search for. Must match the exact user input. + */ + search?: string; + /** + * Whether to include the click-through and conversion rates for a search. + */ + clickAnalytics?: boolean; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetTopSearchesProps = { + /** + * The index name to target. + */ + index: string; + /** + * Whether to include the click-through and conversion rates for a search. + */ + clickAnalytics?: boolean; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Reorder the results. + */ + orderBy?: OrderBy; + /** + * The sorting of the result. + */ + direction?: Direction; + /** + * Number of records to return. Limit is the size of the page. + */ + limit?: number; + /** + * Position of the starting record. Used for paging. 0 is the first record. + */ + offset?: number; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type GetUsersCountProps = { + /** + * The index name to target. + */ + index: string; + /** + * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + startDate?: string; + /** + * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. + */ + endDate?: string; + /** + * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. + */ + tags?: string; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts b/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts new file mode 100644 index 0000000000..ae999a5043 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts @@ -0,0 +1,305 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { InsightEvents } from '../model/insightEvents'; +import type { PushEventsResponse } from '../model/pushEventsResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +export type Region = 'de' | 'us'; + +function getDefaultHosts(region?: Region): Host[] { + const regionHost = region ? `.${region}.` : '.'; + + return [ + { + url: `insights${regionHost}algolia.io`, + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createInsightsApi( + options: CreateClientOptions & { region?: Region } +) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.region), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Insights', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This command pushes an array of events. + * + * @summary Pushes an array of events. + * @param insightEvents - The insightEvents object. + */ + pushEvents( + insightEvents: InsightEvents, + requestOptions?: RequestOptions + ): Promise { + if (!insightEvents) { + throw new Error( + 'Parameter `insightEvents` is required when calling `pushEvents`.' + ); + } + + if (!insightEvents.events) { + throw new Error( + 'Parameter `insightEvents.events` is required when calling `pushEvents`.' + ); + } + + const requestPath = '/1/events'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: insightEvents, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type InsightsApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts b/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts new file mode 100644 index 0000000000..588889af0d --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts @@ -0,0 +1,434 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { DeleteUserProfileResponse } from '../model/deleteUserProfileResponse'; +import type { GetUserTokenResponse } from '../model/getUserTokenResponse'; +import type { PersonalizationStrategyParams } from '../model/personalizationStrategyParams'; +import type { SetPersonalizationStrategyResponse } from '../model/setPersonalizationStrategyResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +export type Region = 'eu' | 'us'; + +function getDefaultHosts(region: Region): Host[] { + return [ + { + url: `personalization.${region}.algolia.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createPersonalizationApi( + options: CreateClientOptions & { region: Region } +) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.region), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Personalization', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns, as part of the response, a date until which the data can safely be considered as deleted for the given user. This means that if you send events for the given user before this date, they will be ignored. Any data received after the deletedUntil date will start building a new user profile. It might take a couple hours before for the deletion request to be fully processed. + * + * @summary Delete the user profile and all its associated data. + * @param deleteUserProfile - The deleteUserProfile object. + * @param deleteUserProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. + */ + deleteUserProfile( + { userToken }: DeleteUserProfileProps, + requestOptions?: RequestOptions + ): Promise { + if (!userToken) { + throw new Error( + 'Parameter `userToken` is required when calling `deleteUserProfile`.' + ); + } + + const requestPath = '/1/profiles/{userToken}'.replace( + '{userToken}', + encodeURIComponent(userToken) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * The strategy contains information on the events and facets that impact user profiles and personalized search results. + * + * @summary Get the current personalization strategy. + */ + getPersonalizationStrategy( + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/strategies/personalization'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * The profile is structured by facet name used in the strategy. Each facet value is mapped to its score. Each score represents the user affinity for a specific facet value given the userToken past events and the Personalization strategy defined. Scores are bounded to 20. The last processed event timestamp is provided using the ISO 8601 format for debugging purposes. + * + * @summary Get the user profile built from Personalization strategy. + * @param getUserTokenProfile - The getUserTokenProfile object. + * @param getUserTokenProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. + */ + getUserTokenProfile( + { userToken }: GetUserTokenProfileProps, + requestOptions?: RequestOptions + ): Promise { + if (!userToken) { + throw new Error( + 'Parameter `userToken` is required when calling `getUserTokenProfile`.' + ); + } + + const requestPath = '/1/profiles/personalization/{userToken}'.replace( + '{userToken}', + encodeURIComponent(userToken) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * A strategy defines the events and facets that impact user profiles and personalized search results. + * + * @summary Set a new personalization strategy. + * @param personalizationStrategyParams - The personalizationStrategyParams object. + */ + setPersonalizationStrategy( + personalizationStrategyParams: PersonalizationStrategyParams, + requestOptions?: RequestOptions + ): Promise { + if (!personalizationStrategyParams) { + throw new Error( + 'Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.' + ); + } + + if (!personalizationStrategyParams.eventScoring) { + throw new Error( + 'Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.' + ); + } + if (!personalizationStrategyParams.facetScoring) { + throw new Error( + 'Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.' + ); + } + if (!personalizationStrategyParams.personalizationImpact) { + throw new Error( + 'Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.' + ); + } + + const requestPath = '/1/strategies/personalization'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: personalizationStrategyParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type PersonalizationApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type DeleteUserProfileProps = { + /** + * UserToken representing the user for which to fetch the Personalization profile. + */ + userToken: string; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetUserTokenProfileProps = { + /** + * UserToken representing the user for which to fetch the Personalization profile. + */ + userToken: string; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts new file mode 100644 index 0000000000..ca2946d3b4 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts @@ -0,0 +1,312 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; +import type { Params } from '../model/params'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +function getDefaultHosts(): Host[] { + return [ + { + url: 'predict-api-oslcbws3zq-ew.a.run.app', + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createPredictApi(options: CreateClientOptions) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Predict', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile. + * + * @summary Get user profile. + * @param fetchUserProfile - The fetchUserProfile object. + * @param fetchUserProfile.userID - User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). + * @param fetchUserProfile.params - The params object. + */ + fetchUserProfile( + { userID, params }: FetchUserProfileProps, + requestOptions?: RequestOptions + ): Promise { + if (!userID) { + throw new Error( + 'Parameter `userID` is required when calling `fetchUserProfile`.' + ); + } + + if (!params) { + throw new Error( + 'Parameter `params` is required when calling `fetchUserProfile`.' + ); + } + + const requestPath = '/1/users/{userID}/fetch'.replace( + '{userID}', + encodeURIComponent(userID) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: params, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type PredictApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type FetchUserProfileProps = { + /** + * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). + */ + userID: string; + params: Params; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts new file mode 100644 index 0000000000..63033fe47d --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts @@ -0,0 +1,573 @@ +import { + createAuth, + createTransporter, + getUserAgent, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { LogFile } from '../model/logFile'; +import type { QuerySuggestionsIndex } from '../model/querySuggestionsIndex'; +import type { QuerySuggestionsIndexParam } from '../model/querySuggestionsIndexParam'; +import type { QuerySuggestionsIndexWithIndexParam } from '../model/querySuggestionsIndexWithIndexParam'; +import type { Status } from '../model/status'; +import type { SucessResponse } from '../model/sucessResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +export type Region = 'eu' | 'us'; + +function getDefaultHosts(region: Region): Host[] { + return [ + { + url: `query-suggestions.${region}.algolia.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]; +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createQuerySuggestionsApi( + options: CreateClientOptions & { region: Region } +) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.region), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'QuerySuggestions', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * Create a configuration of a Query Suggestions index. There\'s a limit of 100 configurations per application. + * + * @summary Create a configuration of a Query Suggestions index. + * @param querySuggestionsIndexWithIndexParam - The querySuggestionsIndexWithIndexParam object. + */ + createConfig( + querySuggestionsIndexWithIndexParam: QuerySuggestionsIndexWithIndexParam, + requestOptions?: RequestOptions + ): Promise { + if (!querySuggestionsIndexWithIndexParam) { + throw new Error( + 'Parameter `querySuggestionsIndexWithIndexParam` is required when calling `createConfig`.' + ); + } + + const requestPath = '/1/configs'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: querySuggestionsIndexWithIndexParam, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete a configuration of a Query Suggestion\'s index. By deleting a configuraton, you stop all updates to the underlying query suggestion index. Note that when doing this, the underlying index does not change - existing suggestions remain untouched. + * + * @summary Delete a configuration of a Query Suggestion\'s index. + * @param deleteConfig - The deleteConfig object. + * @param deleteConfig.indexName - The index in which to perform the request. + */ + deleteConfig( + { indexName }: DeleteConfigProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteConfig`.' + ); + } + + const requestPath = '/1/configs/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get all the configurations of Query Suggestions. For each index, you get a block of JSON with a list of its configuration settings. + * + * @summary Get all the configurations of Query Suggestions. + */ + getAllConfigs( + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/configs'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the configuration of a single Query Suggestions index. + * + * @summary Get the configuration of a single Query Suggestions index. + * @param getConfig - The getConfig object. + * @param getConfig.indexName - The index in which to perform the request. + */ + getConfig( + { indexName }: GetConfigProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getConfig`.' + ); + } + + const requestPath = '/1/configs/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the status of a Query Suggestion\'s index. The status includes whether the Query Suggestions index is currently in the process of being built, and the last build time. + * + * @summary Get the status of a Query Suggestion\'s index. + * @param getConfigStatus - The getConfigStatus object. + * @param getConfigStatus.indexName - The index in which to perform the request. + */ + getConfigStatus( + { indexName }: GetConfigStatusProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getConfigStatus`.' + ); + } + + const requestPath = '/1/configs/{indexName}/status'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the log file of the last build of a single Query Suggestion index. + * + * @summary Get the log file of the last build of a single Query Suggestion index. + * @param getLogFile - The getLogFile object. + * @param getLogFile.indexName - The index in which to perform the request. + */ + getLogFile( + { indexName }: GetLogFileProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getLogFile`.' + ); + } + + const requestPath = '/1/logs/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Update the configuration of a Query Suggestions index. + * + * @summary Update the configuration of a Query Suggestions index. + * @param updateConfig - The updateConfig object. + * @param updateConfig.indexName - The index in which to perform the request. + * @param updateConfig.querySuggestionsIndexParam - The querySuggestionsIndexParam object. + */ + updateConfig( + { indexName, querySuggestionsIndexParam }: UpdateConfigProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `updateConfig`.' + ); + } + + if (!querySuggestionsIndexParam) { + throw new Error( + 'Parameter `querySuggestionsIndexParam` is required when calling `updateConfig`.' + ); + } + + if (!querySuggestionsIndexParam.sourceIndices) { + throw new Error( + 'Parameter `querySuggestionsIndexParam.sourceIndices` is required when calling `updateConfig`.' + ); + } + + const requestPath = '/1/configs/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: querySuggestionsIndexParam, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type QuerySuggestionsApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type DeleteConfigProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetConfigProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type GetConfigStatusProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type GetLogFileProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type UpdateConfigProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + querySuggestionsIndexParam: QuerySuggestionsIndexParam; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts b/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts new file mode 100644 index 0000000000..bf0da9ac02 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts @@ -0,0 +1,3354 @@ +import { + createAuth, + createTransporter, + getUserAgent, + shuffle, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { AddApiKeyResponse } from '../model/addApiKeyResponse'; +import type { ApiKey } from '../model/apiKey'; +import type { AssignUserIdParams } from '../model/assignUserIdParams'; +import type { AttributeOrBuiltInOperation } from '../model/attributeOrBuiltInOperation'; +import type { BatchAssignUserIdsParams } from '../model/batchAssignUserIdsParams'; +import type { BatchDictionaryEntriesParams } from '../model/batchDictionaryEntriesParams'; +import type { BatchParams } from '../model/batchParams'; +import type { BatchResponse } from '../model/batchResponse'; +import type { BatchWriteParams } from '../model/batchWriteParams'; +import type { BrowseRequest } from '../model/browseRequest'; +import type { BrowseResponse } from '../model/browseResponse'; +import type { CreatedAtResponse } from '../model/createdAtResponse'; +import type { DeleteApiKeyResponse } from '../model/deleteApiKeyResponse'; +import type { DeleteSourceResponse } from '../model/deleteSourceResponse'; +import type { DeletedAtResponse } from '../model/deletedAtResponse'; +import type { DictionarySettingsParams } from '../model/dictionarySettingsParams'; +import type { DictionaryType } from '../model/dictionaryType'; +import type { GetDictionarySettingsResponse } from '../model/getDictionarySettingsResponse'; +import type { GetLogsResponse } from '../model/getLogsResponse'; +import type { GetObjectsParams } from '../model/getObjectsParams'; +import type { GetObjectsResponse } from '../model/getObjectsResponse'; +import type { GetTaskResponse } from '../model/getTaskResponse'; +import type { GetTopUserIdsResponse } from '../model/getTopUserIdsResponse'; +import type { IndexSettings } from '../model/indexSettings'; +import type { Key } from '../model/key'; +import type { Languages } from '../model/languages'; +import type { ListApiKeysResponse } from '../model/listApiKeysResponse'; +import type { ListClustersResponse } from '../model/listClustersResponse'; +import type { ListIndicesResponse } from '../model/listIndicesResponse'; +import type { ListUserIdsResponse } from '../model/listUserIdsResponse'; +import type { LogType } from '../model/logType'; +import type { MultipleBatchResponse } from '../model/multipleBatchResponse'; +import type { MultipleQueriesParams } from '../model/multipleQueriesParams'; +import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; +import type { OperationIndexParams } from '../model/operationIndexParams'; +import type { RemoveUserIdResponse } from '../model/removeUserIdResponse'; +import type { ReplaceSourceResponse } from '../model/replaceSourceResponse'; +import type { Rule } from '../model/rule'; +import type { SaveObjectResponse } from '../model/saveObjectResponse'; +import type { SaveSynonymResponse } from '../model/saveSynonymResponse'; +import type { SearchDictionaryEntriesParams } from '../model/searchDictionaryEntriesParams'; +import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest'; +import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse'; +import type { SearchParams } from '../model/searchParams'; +import type { SearchResponse } from '../model/searchResponse'; +import type { SearchRulesParams } from '../model/searchRulesParams'; +import type { SearchRulesResponse } from '../model/searchRulesResponse'; +import type { SearchSynonymsResponse } from '../model/searchSynonymsResponse'; +import type { SearchUserIdsParams } from '../model/searchUserIdsParams'; +import type { SearchUserIdsResponse } from '../model/searchUserIdsResponse'; +import type { Source } from '../model/source'; +import type { SynonymHit } from '../model/synonymHit'; +import type { SynonymType } from '../model/synonymType'; +import type { UpdateApiKeyResponse } from '../model/updateApiKeyResponse'; +import type { UpdatedAtResponse } from '../model/updatedAtResponse'; +import type { UpdatedAtWithObjectIdResponse } from '../model/updatedAtWithObjectIdResponse'; +import type { UpdatedRuleResponse } from '../model/updatedRuleResponse'; +import type { UserId } from '../model/userId'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +function getDefaultHosts(appId: string): Host[] { + return ( + [ + { + url: `${appId}-dsn.algolia.net`, + accept: 'read', + protocol: 'https', + }, + { + url: `${appId}.algolia.net`, + accept: 'write', + protocol: 'https', + }, + ] as Host[] + ).concat( + shuffle([ + { + url: `${appId}-1.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-2.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-3.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]) + ); +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createSearchApi(options: CreateClientOptions) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.appId), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Search', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * Add a new API Key with specific permissions/restrictions. + * + * @summary Create a new API key. + * @param apiKey - The apiKey object. + */ + addApiKey( + apiKey: ApiKey, + requestOptions?: RequestOptions + ): Promise { + if (!apiKey) { + throw new Error( + 'Parameter `apiKey` is required when calling `addApiKey`.' + ); + } + + if (!apiKey.acl) { + throw new Error( + 'Parameter `apiKey.acl` is required when calling `addApiKey`.' + ); + } + + const requestPath = '/1/keys'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: apiKey, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Add or replace an object with a given object ID. If the object does not exist, it will be created. If it already exists, it will be replaced. + * + * @summary Add or replace an object with a given object ID. + * @param addOrUpdateObject - The addOrUpdateObject object. + * @param addOrUpdateObject.indexName - The index in which to perform the request. + * @param addOrUpdateObject.objectID - Unique identifier of an object. + * @param addOrUpdateObject.body - The Algolia object. + */ + addOrUpdateObject( + { indexName, objectID, body }: AddOrUpdateObjectProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `addOrUpdateObject`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `addOrUpdateObject`.' + ); + } + + if (!body) { + throw new Error( + 'Parameter `body` is required when calling `addOrUpdateObject`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Add a single source to the list of allowed sources. + * + * @summary Add a single source. + * @param source - The source to add. + */ + appendSource( + source: Source, + requestOptions?: RequestOptions + ): Promise { + if (!source) { + throw new Error( + 'Parameter `source` is required when calling `appendSource`.' + ); + } + + const requestPath = '/1/security/sources/append'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: source, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Assign or Move a userID to a cluster. The time it takes to migrate (move) a user is proportional to the amount of data linked to the userID. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userID is directly usable. + * + * @summary Assign or Move userID. + * @param assignUserId - The assignUserId object. + * @param assignUserId.xAlgoliaUserID - UserID to assign. + * @param assignUserId.assignUserIdParams - The assignUserIdParams object. + */ + assignUserId( + { xAlgoliaUserID, assignUserIdParams }: AssignUserIdProps, + requestOptions?: RequestOptions + ): Promise { + if (!xAlgoliaUserID) { + throw new Error( + 'Parameter `xAlgoliaUserID` is required when calling `assignUserId`.' + ); + } + + if (!assignUserIdParams) { + throw new Error( + 'Parameter `assignUserIdParams` is required when calling `assignUserId`.' + ); + } + + if (!assignUserIdParams.cluster) { + throw new Error( + 'Parameter `assignUserIdParams.cluster` is required when calling `assignUserId`.' + ); + } + + const requestPath = '/1/clusters/mapping'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (xAlgoliaUserID !== undefined) { + queryParameters['X-Algolia-User-ID'] = xAlgoliaUserID.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + data: assignUserIdParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Performs multiple write operations in a single API call. + * + * @summary Performs multiple write operations in a single API call. + * @param batch - The batch object. + * @param batch.indexName - The index in which to perform the request. + * @param batch.batchWriteParams - The batchWriteParams object. + */ + batch( + { indexName, batchWriteParams }: BatchProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `batch`.' + ); + } + + if (!batchWriteParams) { + throw new Error( + 'Parameter `batchWriteParams` is required when calling `batch`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/batch'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: batchWriteParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userIDs are directly usable. + * + * @summary Batch assign userIDs. + * @param batchAssignUserIds - The batchAssignUserIds object. + * @param batchAssignUserIds.xAlgoliaUserID - UserID to assign. + * @param batchAssignUserIds.batchAssignUserIdsParams - The batchAssignUserIdsParams object. + */ + batchAssignUserIds( + { xAlgoliaUserID, batchAssignUserIdsParams }: BatchAssignUserIdsProps, + requestOptions?: RequestOptions + ): Promise { + if (!xAlgoliaUserID) { + throw new Error( + 'Parameter `xAlgoliaUserID` is required when calling `batchAssignUserIds`.' + ); + } + + if (!batchAssignUserIdsParams) { + throw new Error( + 'Parameter `batchAssignUserIdsParams` is required when calling `batchAssignUserIds`.' + ); + } + + if (!batchAssignUserIdsParams.cluster) { + throw new Error( + 'Parameter `batchAssignUserIdsParams.cluster` is required when calling `batchAssignUserIds`.' + ); + } + if (!batchAssignUserIdsParams.users) { + throw new Error( + 'Parameter `batchAssignUserIdsParams.users` is required when calling `batchAssignUserIds`.' + ); + } + + const requestPath = '/1/clusters/mapping/batch'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (xAlgoliaUserID !== undefined) { + queryParameters['X-Algolia-User-ID'] = xAlgoliaUserID.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + data: batchAssignUserIdsParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Send a batch of dictionary entries. + * + * @summary Send a batch of dictionary entries. + * @param batchDictionaryEntries - The batchDictionaryEntries object. + * @param batchDictionaryEntries.dictionaryName - The dictionary to search in. + * @param batchDictionaryEntries.batchDictionaryEntriesParams - The batchDictionaryEntriesParams object. + */ + batchDictionaryEntries( + { + dictionaryName, + batchDictionaryEntriesParams, + }: BatchDictionaryEntriesProps, + requestOptions?: RequestOptions + ): Promise { + if (!dictionaryName) { + throw new Error( + 'Parameter `dictionaryName` is required when calling `batchDictionaryEntries`.' + ); + } + + if (!batchDictionaryEntriesParams) { + throw new Error( + 'Parameter `batchDictionaryEntriesParams` is required when calling `batchDictionaryEntries`.' + ); + } + + if (!batchDictionaryEntriesParams.requests) { + throw new Error( + 'Parameter `batchDictionaryEntriesParams.requests` is required when calling `batchDictionaryEntries`.' + ); + } + + const requestPath = '/1/dictionaries/{dictionaryName}/batch'.replace( + '{dictionaryName}', + encodeURIComponent(dictionaryName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: batchDictionaryEntriesParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Create or update a batch of Rules. + * + * @summary Batch Rules. + * @param batchRules - The batchRules object. + * @param batchRules.indexName - The index in which to perform the request. + * @param batchRules.rule - The rule object. + * @param batchRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + * @param batchRules.clearExistingRules - When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. + */ + batchRules( + { + indexName, + rule, + forwardToReplicas, + clearExistingRules, + }: BatchRulesProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `batchRules`.' + ); + } + + if (!rule) { + throw new Error( + 'Parameter `rule` is required when calling `batchRules`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/batch'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + if (clearExistingRules !== undefined) { + queryParameters.clearExistingRules = clearExistingRules.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + data: rule, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allows you to retrieve all index content. It can retrieve up to 1,000 records per call and supports full text search and filters. For performance reasons, some features are not supported, including `distinct`, sorting by `typos`, `words` or `geo distance`. When there is more content to be browsed, the response contains a cursor field. This cursor has to be passed to the subsequent call to browse in order to get the next page of results. When the end of the index has been reached, the cursor field is absent from the response. + * + * @summary Retrieve all index content. + * @param browse - The browse object. + * @param browse.indexName - The index in which to perform the request. + * @param browse.browseRequest - The browseRequest object. + */ + browse( + { indexName, browseRequest }: BrowseProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `browse`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/browse'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: browseRequest, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Remove all synonyms from an index. + * + * @summary Clear all synonyms. + * @param clearAllSynonyms - The clearAllSynonyms object. + * @param clearAllSynonyms.indexName - The index in which to perform the request. + * @param clearAllSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + clearAllSynonyms( + { indexName, forwardToReplicas }: ClearAllSynonymsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `clearAllSynonyms`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/clear'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete an index\'s content, but leave settings and index-specific API keys untouched. + * + * @summary Clear all objects from an index. + * @param clearObjects - The clearObjects object. + * @param clearObjects.indexName - The index in which to perform the request. + */ + clearObjects( + { indexName }: ClearObjectsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `clearObjects`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/clear'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete all Rules in the index. + * + * @summary Clear Rules. + * @param clearRules - The clearRules object. + * @param clearRules.indexName - The index in which to perform the request. + * @param clearRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + clearRules( + { indexName, forwardToReplicas }: ClearRulesProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `clearRules`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/clear'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete an existing API Key. + * + * @summary Delete an API key. + * @param deleteApiKey - The deleteApiKey object. + * @param deleteApiKey.key - API Key string. + */ + deleteApiKey( + { key }: DeleteApiKeyProps, + requestOptions?: RequestOptions + ): Promise { + if (!key) { + throw new Error( + 'Parameter `key` is required when calling `deleteApiKey`.' + ); + } + + const requestPath = '/1/keys/{key}'.replace( + '{key}', + encodeURIComponent(key) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Remove all objects matching a filter (including geo filters). This method enables you to delete one or more objects based on filters (numeric, facet, tag or geo queries). It doesn\'t accept empty filters or a query. + * + * @summary Delete all records matching the query. + * @param deleteBy - The deleteBy object. + * @param deleteBy.indexName - The index in which to perform the request. + * @param deleteBy.searchParams - The searchParams object. + */ + deleteBy( + { indexName, searchParams }: DeleteByProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteBy`.' + ); + } + + if (!searchParams) { + throw new Error( + 'Parameter `searchParams` is required when calling `deleteBy`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/deleteByQuery'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete an existing index. + * + * @summary Delete index. + * @param deleteIndex - The deleteIndex object. + * @param deleteIndex.indexName - The index in which to perform the request. + */ + deleteIndex( + { indexName }: DeleteIndexProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteIndex`.' + ); + } + + const requestPath = '/1/indexes/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete an existing object. + * + * @summary Delete object. + * @param deleteObject - The deleteObject object. + * @param deleteObject.indexName - The index in which to perform the request. + * @param deleteObject.objectID - Unique identifier of an object. + */ + deleteObject( + { indexName, objectID }: DeleteObjectProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteObject`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `deleteObject`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete the Rule with the specified objectID. + * + * @summary Delete a rule. + * @param deleteRule - The deleteRule object. + * @param deleteRule.indexName - The index in which to perform the request. + * @param deleteRule.objectID - Unique identifier of an object. + * @param deleteRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + deleteRule( + { indexName, objectID, forwardToReplicas }: DeleteRuleProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteRule`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `deleteRule`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Remove a single source from the list of allowed sources. + * + * @summary Remove a single source. + * @param deleteSource - The deleteSource object. + * @param deleteSource.source - The IP range of the source. + */ + deleteSource( + { source }: DeleteSourceProps, + requestOptions?: RequestOptions + ): Promise { + if (!source) { + throw new Error( + 'Parameter `source` is required when calling `deleteSource`.' + ); + } + + const requestPath = '/1/security/sources/{source}'.replace( + '{source}', + encodeURIComponent(source) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Delete a single synonyms set, identified by the given objectID. + * + * @summary Delete synonym. + * @param deleteSynonym - The deleteSynonym object. + * @param deleteSynonym.indexName - The index in which to perform the request. + * @param deleteSynonym.objectID - Unique identifier of an object. + * @param deleteSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + deleteSynonym( + { indexName, objectID, forwardToReplicas }: DeleteSynonymProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `deleteSynonym`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `deleteSynonym`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the permissions of an API key. + * + * @summary Get an API key. + * @param getApiKey - The getApiKey object. + * @param getApiKey.key - API Key string. + */ + getApiKey( + { key }: GetApiKeyProps, + requestOptions?: RequestOptions + ): Promise { + if (!key) { + throw new Error( + 'Parameter `key` is required when calling `getApiKey`.' + ); + } + + const requestPath = '/1/keys/{key}'.replace( + '{key}', + encodeURIComponent(key) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List dictionaries supported per language. + * + * @summary List dictionaries supported per language. + */ + getDictionaryLanguages( + requestOptions?: RequestOptions + ): Promise<{ [key: string]: Languages }> { + const requestPath = '/1/dictionaries/*/languages'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Retrieve dictionaries settings. + * + * @summary Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values. + */ + getDictionarySettings( + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/dictionaries/*/settings'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Return the lastest log entries. + * + * @summary Return the lastest log entries. + * @param getLogs - The getLogs object. + * @param getLogs.offset - First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. + * @param getLogs.length - Maximum number of entries to retrieve. The maximum allowed value is 1000. + * @param getLogs.indexName - Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. + * @param getLogs.type - Type of log entries to retrieve. When omitted, all log entries are retrieved. + */ + getLogs( + { offset, length, indexName, type }: GetLogsProps, + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/logs'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (offset !== undefined) { + queryParameters.offset = offset.toString(); + } + + if (length !== undefined) { + queryParameters.length = length.toString(); + } + + if (indexName !== undefined) { + queryParameters.indexName = indexName.toString(); + } + + if (type !== undefined) { + queryParameters.type = type.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Retrieve one object from the index. + * + * @summary Retrieve one object from the index. + * @param getObject - The getObject object. + * @param getObject.indexName - The index in which to perform the request. + * @param getObject.objectID - Unique identifier of an object. + * @param getObject.attributesToRetrieve - List of attributes to retrieve. If not specified, all retrievable attributes are returned. + */ + getObject( + { indexName, objectID, attributesToRetrieve }: GetObjectProps, + requestOptions?: RequestOptions + ): Promise<{ [key: string]: string }> { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getObject`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `getObject`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (attributesToRetrieve !== undefined) { + queryParameters.attributesToRetrieve = attributesToRetrieve.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Retrieve one or more objects, potentially from different indices, in a single API call. + * + * @summary Retrieve one or more objects. + * @param getObjectsParams - The getObjectsParams object. + */ + getObjects( + getObjectsParams: GetObjectsParams, + requestOptions?: RequestOptions + ): Promise { + if (!getObjectsParams) { + throw new Error( + 'Parameter `getObjectsParams` is required when calling `getObjects`.' + ); + } + + const requestPath = '/1/indexes/*/objects'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: getObjectsParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Retrieve the Rule with the specified objectID. + * + * @summary Get a rule. + * @param getRule - The getRule object. + * @param getRule.indexName - The index in which to perform the request. + * @param getRule.objectID - Unique identifier of an object. + */ + getRule( + { indexName, objectID }: GetRuleProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getRule`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `getRule`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Retrieve settings of a given indexName. + * + * @summary Retrieve settings of a given indexName. + * @param getSettings - The getSettings object. + * @param getSettings.indexName - The index in which to perform the request. + */ + getSettings( + { indexName }: GetSettingsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getSettings`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/settings'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List all allowed sources. + * + * @summary List all allowed sources. + */ + getSources(requestOptions?: RequestOptions): Promise { + const requestPath = '/1/security/sources'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Fetch a synonym object identified by its objectID. + * + * @summary Get synonym. + * @param getSynonym - The getSynonym object. + * @param getSynonym.indexName - The index in which to perform the request. + * @param getSynonym.objectID - Unique identifier of an object. + */ + getSynonym( + { indexName, objectID }: GetSynonymProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getSynonym`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `getSynonym`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Check the current status of a given task. + * + * @summary Check the current status of a given task. + * @param getTask - The getTask object. + * @param getTask.indexName - The index in which to perform the request. + * @param getTask.taskID - Unique identifier of an task. Numeric value (up to 64bits). + */ + getTask( + { indexName, taskID }: GetTaskProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `getTask`.' + ); + } + + if (!taskID) { + throw new Error( + 'Parameter `taskID` is required when calling `getTask`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/task/{taskID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{taskID}', encodeURIComponent(taskID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the top 10 userIDs with the highest number of records per cluster. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following array of userIDs and clusters. + * + * @summary Get top userID. + */ + getTopUserIds( + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/clusters/mapping/top'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns the userID data stored in the mapping. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following userID data. + * + * @summary Get userID. + * @param getUserId - The getUserId object. + * @param getUserId.userID - UserID to assign. + */ + getUserId( + { userID }: GetUserIdProps, + requestOptions?: RequestOptions + ): Promise { + if (!userID) { + throw new Error( + 'Parameter `userID` is required when calling `getUserId`.' + ); + } + + const requestPath = '/1/clusters/mapping/{userID}'.replace( + '{userID}', + encodeURIComponent(userID) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get the status of your clusters\' migrations or user creations. Creating a large batch of users or migrating your multi-cluster may take quite some time. This method lets you retrieve the status of the migration, so you can know when it\'s done. Upon success, the response is 200 OK. A successful response indicates that the operation has been taken into account, and the userIDs are directly usable. + * + * @summary Has pending mappings. + * @param hasPendingMappings - The hasPendingMappings object. + * @param hasPendingMappings.getClusters - Whether to get clusters or not. + */ + hasPendingMappings( + { getClusters }: HasPendingMappingsProps, + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/clusters/mapping/pending'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (getClusters !== undefined) { + queryParameters.getClusters = getClusters.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List API keys, along with their associated rights. + * + * @summary Get the full list of API Keys. + */ + listApiKeys(requestOptions?: RequestOptions): Promise { + const requestPath = '/1/keys'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List the clusters available in a multi-clusters setup for a single appID. Upon success, the response is 200 OK and contains the following clusters. + * + * @summary List clusters. + */ + listClusters( + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/clusters'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List existing indexes from an application. + * + * @summary List existing indexes. + * @param listIndices - The listIndices object. + * @param listIndices.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + */ + listIndices( + { page }: ListIndicesProps, + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/indexes'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (page !== undefined) { + queryParameters.page = page.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * List the userIDs assigned to a multi-clusters appID. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK and contains the following userIDs data. + * + * @summary List userIDs. + * @param listUserIds - The listUserIds object. + * @param listUserIds.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * @param listUserIds.hitsPerPage - Maximum number of objects to retrieve. + */ + listUserIds( + { page, hitsPerPage }: ListUserIdsProps, + requestOptions?: RequestOptions + ): Promise { + const requestPath = '/1/clusters/mapping'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (page !== undefined) { + queryParameters.page = page.toString(); + } + + if (hitsPerPage !== undefined) { + queryParameters.hitsPerPage = hitsPerPage.toString(); + } + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Perform multiple write operations, potentially targeting multiple indices, in a single API call. + * + * @summary Perform multiple write operations. + * @param batchParams - The batchParams object. + */ + multipleBatch( + batchParams: BatchParams, + requestOptions?: RequestOptions + ): Promise { + if (!batchParams) { + throw new Error( + 'Parameter `batchParams` is required when calling `multipleBatch`.' + ); + } + + const requestPath = '/1/indexes/*/batch'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: batchParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get search results for the given requests. + * + * @summary Get search results for the given requests. + * @param multipleQueriesParams - The multipleQueriesParams object. + */ + multipleQueries( + multipleQueriesParams: MultipleQueriesParams, + requestOptions?: RequestOptions + ): Promise { + if (!multipleQueriesParams) { + throw new Error( + 'Parameter `multipleQueriesParams` is required when calling `multipleQueries`.' + ); + } + + if (!multipleQueriesParams.requests) { + throw new Error( + 'Parameter `multipleQueriesParams.requests` is required when calling `multipleQueries`.' + ); + } + + const requestPath = '/1/indexes/*/queries'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: multipleQueriesParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Peforms a copy or a move operation on a index. + * + * @summary Copy/move index. + * @param operationIndex - The operationIndex object. + * @param operationIndex.indexName - The index in which to perform the request. + * @param operationIndex.operationIndexParams - The operationIndexParams object. + */ + operationIndex( + { indexName, operationIndexParams }: OperationIndexProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `operationIndex`.' + ); + } + + if (!operationIndexParams) { + throw new Error( + 'Parameter `operationIndexParams` is required when calling `operationIndex`.' + ); + } + + if (!operationIndexParams.operation) { + throw new Error( + 'Parameter `operationIndexParams.operation` is required when calling `operationIndex`.' + ); + } + if (!operationIndexParams.destination) { + throw new Error( + 'Parameter `operationIndexParams.destination` is required when calling `operationIndex`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/operation'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: operationIndexParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Update one or more attributes of an existing object. This method lets you update only a part of an existing object, either by adding new attributes or updating existing ones. You can partially update several objects in a single method call. If the index targeted by this operation doesn\'t exist yet, it\'s automatically created. + * + * @summary Partially update an object. + * @param partialUpdateObject - The partialUpdateObject object. + * @param partialUpdateObject.indexName - The index in which to perform the request. + * @param partialUpdateObject.objectID - Unique identifier of an object. + * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update. + * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet. + */ + partialUpdateObject( + { + indexName, + objectID, + attributeOrBuiltInOperation, + createIfNotExists, + }: PartialUpdateObjectProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `partialUpdateObject`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `partialUpdateObject`.' + ); + } + + if (!attributeOrBuiltInOperation) { + throw new Error( + 'Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/{objectID}/partial' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (createIfNotExists !== undefined) { + queryParameters.createIfNotExists = createIfNotExists.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + data: attributeOrBuiltInOperation, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Remove a userID and its associated data from the multi-clusters. Upon success, the response is 200 OK and a task is created to remove the userID data and mapping. + * + * @summary Remove userID. + * @param removeUserId - The removeUserId object. + * @param removeUserId.userID - UserID to assign. + */ + removeUserId( + { userID }: RemoveUserIdProps, + requestOptions?: RequestOptions + ): Promise { + if (!userID) { + throw new Error( + 'Parameter `userID` is required when calling `removeUserId`.' + ); + } + + const requestPath = '/1/clusters/mapping/{userID}'.replace( + '{userID}', + encodeURIComponent(userID) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Replace all allowed sources. + * + * @summary Replace all allowed sources. + * @param replaceSources - The replaceSources object. + * @param replaceSources.source - The sources to allow. + */ + replaceSources( + { source }: ReplaceSourcesProps, + requestOptions?: RequestOptions + ): Promise { + if (!source) { + throw new Error( + 'Parameter `source` is required when calling `replaceSources`.' + ); + } + + const requestPath = '/1/security/sources'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: source, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Restore a deleted API key, along with its associated rights. + * + * @summary Restore an API key. + * @param restoreApiKey - The restoreApiKey object. + * @param restoreApiKey.key - API Key string. + */ + restoreApiKey( + { key }: RestoreApiKeyProps, + requestOptions?: RequestOptions + ): Promise { + if (!key) { + throw new Error( + 'Parameter `key` is required when calling `restoreApiKey`.' + ); + } + + const requestPath = '/1/keys/{key}/restore'.replace( + '{key}', + encodeURIComponent(key) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Add an object to the index, automatically assigning it an object ID. + * + * @summary Add an object to the index. + * @param saveObject - The saveObject object. + * @param saveObject.indexName - The index in which to perform the request. + * @param saveObject.body - The Algolia record. + */ + saveObject( + { indexName, body }: SaveObjectProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `saveObject`.' + ); + } + + if (!body) { + throw new Error( + 'Parameter `body` is required when calling `saveObject`.' + ); + } + + const requestPath = '/1/indexes/{indexName}'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Create or update the Rule with the specified objectID. + * + * @summary Save/Update a rule. + * @param saveRule - The saveRule object. + * @param saveRule.indexName - The index in which to perform the request. + * @param saveRule.objectID - Unique identifier of an object. + * @param saveRule.rule - The rule object. + * @param saveRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + saveRule( + { indexName, objectID, rule, forwardToReplicas }: SaveRuleProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `saveRule`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `saveRule`.' + ); + } + + if (!rule) { + throw new Error( + 'Parameter `rule` is required when calling `saveRule`.' + ); + } + + if (!rule.objectID) { + throw new Error( + 'Parameter `rule.objectID` is required when calling `saveRule`.' + ); + } + if (!rule.consequence) { + throw new Error( + 'Parameter `rule.consequence` is required when calling `saveRule`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'PUT', + path: requestPath, + data: rule, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Create a new synonym object or update the existing synonym object with the given object ID. + * + * @summary Save synonym. + * @param saveSynonym - The saveSynonym object. + * @param saveSynonym.indexName - The index in which to perform the request. + * @param saveSynonym.objectID - Unique identifier of an object. + * @param saveSynonym.synonymHit - The synonymHit object. + * @param saveSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + saveSynonym( + { indexName, objectID, synonymHit, forwardToReplicas }: SaveSynonymProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `saveSynonym`.' + ); + } + + if (!objectID) { + throw new Error( + 'Parameter `objectID` is required when calling `saveSynonym`.' + ); + } + + if (!synonymHit) { + throw new Error( + 'Parameter `synonymHit` is required when calling `saveSynonym`.' + ); + } + + if (!synonymHit.objectID) { + throw new Error( + 'Parameter `synonymHit.objectID` is required when calling `saveSynonym`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{objectID}', encodeURIComponent(objectID)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'PUT', + path: requestPath, + data: synonymHit, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Create/update multiple synonym objects at once, potentially replacing the entire list of synonyms if replaceExistingSynonyms is true. + * + * @summary Save a batch of synonyms. + * @param saveSynonyms - The saveSynonyms object. + * @param saveSynonyms.indexName - The index in which to perform the request. + * @param saveSynonyms.synonymHit - The synonymHit object. + * @param saveSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + * @param saveSynonyms.replaceExistingSynonyms - Replace all synonyms of the index with the ones sent with this request. + */ + saveSynonyms( + { + indexName, + synonymHit, + forwardToReplicas, + replaceExistingSynonyms, + }: SaveSynonymsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `saveSynonyms`.' + ); + } + + if (!synonymHit) { + throw new Error( + 'Parameter `synonymHit` is required when calling `saveSynonyms`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/batch'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + if (replaceExistingSynonyms !== undefined) { + queryParameters.replaceExistingSynonyms = + replaceExistingSynonyms.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + data: synonymHit, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Get search results. + * + * @summary Get search results. + * @param search - The search object. + * @param search.indexName - The index in which to perform the request. + * @param search.searchParams - The searchParams object. + */ + search( + { indexName, searchParams }: SearchProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `search`.' + ); + } + + if (!searchParams) { + throw new Error( + 'Parameter `searchParams` is required when calling `search`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/query'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search the dictionary entries. + * + * @summary Search the dictionary entries. + * @param searchDictionaryEntries - The searchDictionaryEntries object. + * @param searchDictionaryEntries.dictionaryName - The dictionary to search in. + * @param searchDictionaryEntries.searchDictionaryEntriesParams - The searchDictionaryEntriesParams object. + */ + searchDictionaryEntries( + { + dictionaryName, + searchDictionaryEntriesParams, + }: SearchDictionaryEntriesProps, + requestOptions?: RequestOptions + ): Promise { + if (!dictionaryName) { + throw new Error( + 'Parameter `dictionaryName` is required when calling `searchDictionaryEntries`.' + ); + } + + if (!searchDictionaryEntriesParams) { + throw new Error( + 'Parameter `searchDictionaryEntriesParams` is required when calling `searchDictionaryEntries`.' + ); + } + + if (!searchDictionaryEntriesParams.query) { + throw new Error( + 'Parameter `searchDictionaryEntriesParams.query` is required when calling `searchDictionaryEntries`.' + ); + } + + const requestPath = '/1/dictionaries/{dictionaryName}/search'.replace( + '{dictionaryName}', + encodeURIComponent(dictionaryName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchDictionaryEntriesParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search for values of a given facet, optionally restricting the returned values to those contained in objects matching other search criteria. + * + * @summary Search for values of a given facet. + * @param searchForFacetValues - The searchForFacetValues object. + * @param searchForFacetValues.indexName - The index in which to perform the request. + * @param searchForFacetValues.facetName - The facet name. + * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object. + */ + searchForFacetValues( + { + indexName, + facetName, + searchForFacetValuesRequest, + }: SearchForFacetValuesProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `searchForFacetValues`.' + ); + } + + if (!facetName) { + throw new Error( + 'Parameter `facetName` is required when calling `searchForFacetValues`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/facets/{facetName}/query' + .replace('{indexName}', encodeURIComponent(indexName)) + .replace('{facetName}', encodeURIComponent(facetName)); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchForFacetValuesRequest, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search for rules matching various criteria. + * + * @summary Search for rules. + * @param searchRules - The searchRules object. + * @param searchRules.indexName - The index in which to perform the request. + * @param searchRules.searchRulesParams - The searchRulesParams object. + */ + searchRules( + { indexName, searchRulesParams }: SearchRulesProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `searchRules`.' + ); + } + + if (!searchRulesParams) { + throw new Error( + 'Parameter `searchRulesParams` is required when calling `searchRules`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/rules/search'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchRulesParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search or browse all synonyms, optionally filtering them by type. + * + * @summary Get all synonyms that match a query. + * @param searchSynonyms - The searchSynonyms object. + * @param searchSynonyms.indexName - The index in which to perform the request. + * @param searchSynonyms.query - Search for specific synonyms matching this string. + * @param searchSynonyms.type - Only search for specific types of synonyms. + * @param searchSynonyms.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + * @param searchSynonyms.hitsPerPage - Maximum number of objects to retrieve. + */ + searchSynonyms( + { indexName, query, type, page, hitsPerPage }: SearchSynonymsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `searchSynonyms`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/synonyms/search'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (query !== undefined) { + queryParameters.query = query.toString(); + } + + if (type !== undefined) { + queryParameters.type = type.toString(); + } + + if (page !== undefined) { + queryParameters.page = page.toString(); + } + + if (hitsPerPage !== undefined) { + queryParameters.hitsPerPage = hitsPerPage.toString(); + } + + const request: Request = { + method: 'POST', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Search for userIDs. The data returned will usually be a few seconds behind real time, because userID usage may take up to a few seconds propagate to the different clusters. To keep updates moving quickly, the index of userIDs isn\'t built synchronously with the mapping. Instead, the index is built once every 12h, at the same time as the update of userID usage. For example, when you perform a modification like adding or moving a userID, the search will report an outdated value until the next rebuild of the mapping, which takes place every 12h. Upon success, the response is 200 OK and contains the following userIDs data. + * + * @summary Search userID. + * @param searchUserIdsParams - The searchUserIdsParams object. + */ + searchUserIds( + searchUserIdsParams: SearchUserIdsParams, + requestOptions?: RequestOptions + ): Promise { + if (!searchUserIdsParams) { + throw new Error( + 'Parameter `searchUserIdsParams` is required when calling `searchUserIds`.' + ); + } + + if (!searchUserIdsParams.query) { + throw new Error( + 'Parameter `searchUserIdsParams.query` is required when calling `searchUserIds`.' + ); + } + + const requestPath = '/1/clusters/mapping/search'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: searchUserIdsParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Set dictionary settings. + * + * @summary Set dictionary settings. + * @param dictionarySettingsParams - The dictionarySettingsParams object. + */ + setDictionarySettings( + dictionarySettingsParams: DictionarySettingsParams, + requestOptions?: RequestOptions + ): Promise { + if (!dictionarySettingsParams) { + throw new Error( + 'Parameter `dictionarySettingsParams` is required when calling `setDictionarySettings`.' + ); + } + + if (!dictionarySettingsParams.disableStandardEntries) { + throw new Error( + 'Parameter `dictionarySettingsParams.disableStandardEntries` is required when calling `setDictionarySettings`.' + ); + } + + const requestPath = '/1/dictionaries/*/settings'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: dictionarySettingsParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Update settings of a given indexName. Only specified settings are overridden; unspecified settings are left unchanged. Specifying null for a setting resets it to its default value. + * + * @summary Update settings of a given indexName. + * @param setSettings - The setSettings object. + * @param setSettings.indexName - The index in which to perform the request. + * @param setSettings.indexSettings - The indexSettings object. + * @param setSettings.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. + */ + setSettings( + { indexName, indexSettings, forwardToReplicas }: SetSettingsProps, + requestOptions?: RequestOptions + ): Promise { + if (!indexName) { + throw new Error( + 'Parameter `indexName` is required when calling `setSettings`.' + ); + } + + if (!indexSettings) { + throw new Error( + 'Parameter `indexSettings` is required when calling `setSettings`.' + ); + } + + const requestPath = '/1/indexes/{indexName}/settings'.replace( + '{indexName}', + encodeURIComponent(indexName) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + if (forwardToReplicas !== undefined) { + queryParameters.forwardToReplicas = forwardToReplicas.toString(); + } + + const request: Request = { + method: 'PUT', + path: requestPath, + data: indexSettings, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Replace every permission of an existing API key. + * + * @summary Update an API key. + * @param updateApiKey - The updateApiKey object. + * @param updateApiKey.key - API Key string. + * @param updateApiKey.apiKey - The apiKey object. + */ + updateApiKey( + { key, apiKey }: UpdateApiKeyProps, + requestOptions?: RequestOptions + ): Promise { + if (!key) { + throw new Error( + 'Parameter `key` is required when calling `updateApiKey`.' + ); + } + + if (!apiKey) { + throw new Error( + 'Parameter `apiKey` is required when calling `updateApiKey`.' + ); + } + + if (!apiKey.acl) { + throw new Error( + 'Parameter `apiKey.acl` is required when calling `updateApiKey`.' + ); + } + + const requestPath = '/1/keys/{key}'.replace( + '{key}', + encodeURIComponent(key) + ); + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: apiKey, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type SearchApi = ReturnType; + +export type AddOrUpdateObjectProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + /** + * The Algolia object. + */ + body: Record; +}; + +export type AssignUserIdProps = { + /** + * UserID to assign. + */ + xAlgoliaUserID: string; + assignUserIdParams: AssignUserIdParams; +}; + +export type BatchProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + batchWriteParams: BatchWriteParams; +}; + +export type BatchAssignUserIdsProps = { + /** + * UserID to assign. + */ + xAlgoliaUserID: string; + batchAssignUserIdsParams: BatchAssignUserIdsParams; +}; + +export type BatchDictionaryEntriesProps = { + /** + * The dictionary to search in. + */ + dictionaryName: DictionaryType; + batchDictionaryEntriesParams: BatchDictionaryEntriesParams; +}; + +export type BatchRulesProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + rule: Rule[]; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; + /** + * When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. + */ + clearExistingRules?: boolean; +}; + +export type BrowseProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + browseRequest?: BrowseRequest; +}; + +export type ClearAllSynonymsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type ClearObjectsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type ClearRulesProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type DeleteApiKeyProps = { + /** + * API Key string. + */ + key: string; +}; + +export type DeleteByProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + searchParams: SearchParams; +}; + +export type DeleteIndexProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type DeleteObjectProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; +}; + +export type DeleteRuleProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type DeleteSourceProps = { + /** + * The IP range of the source. + */ + source: string; +}; + +export type DeleteSynonymProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetApiKeyProps = { + /** + * API Key string. + */ + key: string; +}; + +export type GetLogsProps = { + /** + * First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. + */ + offset?: number; + /** + * Maximum number of entries to retrieve. The maximum allowed value is 1000. + */ + length?: number; + /** + * Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. + */ + indexName?: string; + /** + * Type of log entries to retrieve. When omitted, all log entries are retrieved. + */ + type?: LogType; +}; + +export type GetObjectProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + /** + * List of attributes to retrieve. If not specified, all retrievable attributes are returned. + */ + attributesToRetrieve?: string[]; +}; + +export type GetRuleProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; +}; + +export type GetSettingsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; +}; + +export type GetSynonymProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; +}; + +export type GetTaskProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an task. Numeric value (up to 64bits). + */ + taskID: number; +}; + +export type GetUserIdProps = { + /** + * UserID to assign. + */ + userID: string; +}; + +export type HasPendingMappingsProps = { + /** + * Whether to get clusters or not. + */ + getClusters?: boolean; +}; + +export type ListIndicesProps = { + /** + * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + */ + page?: number; +}; + +export type ListUserIdsProps = { + /** + * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + */ + page?: number; + /** + * Maximum number of objects to retrieve. + */ + hitsPerPage?: number; +}; + +export type OperationIndexProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + operationIndexParams: OperationIndexParams; +}; + +export type PartialUpdateObjectProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + /** + * List of attributes to update. + */ + attributeOrBuiltInOperation: Array<{ + [key: string]: AttributeOrBuiltInOperation; + }>; + /** + * Creates the record if it does not exist yet. + */ + createIfNotExists?: boolean; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type RemoveUserIdProps = { + /** + * UserID to assign. + */ + userID: string; +}; + +export type ReplaceSourcesProps = { + /** + * The sources to allow. + */ + source: Source[]; +}; + +export type RestoreApiKeyProps = { + /** + * API Key string. + */ + key: string; +}; + +export type SaveObjectProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * The Algolia record. + */ + body: Record; +}; + +export type SaveRuleProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + rule: Rule; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type SaveSynonymProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Unique identifier of an object. + */ + objectID: string; + synonymHit: SynonymHit; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type SaveSynonymsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + synonymHit: SynonymHit[]; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; + /** + * Replace all synonyms of the index with the ones sent with this request. + */ + replaceExistingSynonyms?: boolean; +}; + +export type SearchProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + searchParams: SearchParams; +}; + +export type SearchDictionaryEntriesProps = { + /** + * The dictionary to search in. + */ + dictionaryName: DictionaryType; + searchDictionaryEntriesParams: SearchDictionaryEntriesParams; +}; + +export type SearchForFacetValuesProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * The facet name. + */ + facetName: string; + searchForFacetValuesRequest?: SearchForFacetValuesRequest; +}; + +export type SearchRulesProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + searchRulesParams: SearchRulesParams; +}; + +export type SearchSynonymsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + /** + * Search for specific synonyms matching this string. + */ + query?: string; + /** + * Only search for specific types of synonyms. + */ + type?: SynonymType; + /** + * Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). + */ + page?: number; + /** + * Maximum number of objects to retrieve. + */ + hitsPerPage?: number; +}; + +export type SetSettingsProps = { + /** + * The index in which to perform the request. + */ + indexName: string; + indexSettings: IndexSettings; + /** + * When true, changes are also propagated to replicas of the given indexName. + */ + forwardToReplicas?: boolean; +}; + +export type UpdateApiKeyProps = { + /** + * API Key string. + */ + key: string; + apiKey: ApiKey; +}; diff --git a/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts b/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts new file mode 100644 index 0000000000..cb6f6caa70 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts @@ -0,0 +1,325 @@ +import { + createAuth, + createTransporter, + getUserAgent, + shuffle, +} from '@experimental-api-clients-automation/client-common'; +import type { + CreateClientOptions, + Headers, + Host, + Request, + RequestOptions, + QueryParameters, +} from '@experimental-api-clients-automation/client-common'; + +import type { GetRecommendationsParams } from '../model/getRecommendationsParams'; +import type { GetRecommendationsResponse } from '../model/getRecommendationsResponse'; + +export * from '../model'; +export const apiClientVersion = '0.0.5'; + +function getDefaultHosts(appId: string): Host[] { + return ( + [ + { + url: `${appId}-dsn.algolia.net`, + accept: 'read', + protocol: 'https', + }, + { + url: `${appId}.algolia.net`, + accept: 'write', + protocol: 'https', + }, + ] as Host[] + ).concat( + shuffle([ + { + url: `${appId}-1.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-2.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-3.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + ]) + ); +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export function createRecommendApi(options: CreateClientOptions) { + const auth = createAuth(options.appId, options.apiKey, options.authMode); + const transporter = createTransporter({ + hosts: options?.hosts ?? getDefaultHosts(options.appId), + hostsCache: options.hostsCache, + requestsCache: options.requestsCache, + responsesCache: options.responsesCache, + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded', + ...auth.headers(), + }, + baseQueryParameters: auth.queryParameters(), + userAgent: getUserAgent({ + userAgents: options.userAgents, + client: 'Recommend', + version: apiClientVersion, + }), + timeouts: options.timeouts, + requester: options.requester, + }); + + function addUserAgent(segment: string, version?: string): void { + transporter.userAgent.add({ segment, version }); + } + + return { + addUserAgent, + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param del - The del object. + * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param del.parameters - Query parameters to be applied to the current query. + */ + del( + { path, parameters }: DelProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `del`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'DELETE', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param get - The get object. + * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param get.parameters - Query parameters to be applied to the current query. + */ + get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `get`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'GET', + path: requestPath, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * Returns recommendations for a specific model and objectID. + * + * @summary Returns recommendations for a specific model and objectID. + * @param getRecommendationsParams - The getRecommendationsParams object. + */ + getRecommendations( + getRecommendationsParams: GetRecommendationsParams, + requestOptions?: RequestOptions + ): Promise { + if (!getRecommendationsParams) { + throw new Error( + 'Parameter `getRecommendationsParams` is required when calling `getRecommendations`.' + ); + } + + if (!getRecommendationsParams.requests) { + throw new Error( + 'Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.' + ); + } + + const requestPath = '/1/indexes/*/recommendations'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: getRecommendationsParams, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param post - The post object. + * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param post.parameters - Query parameters to be applied to the current query. + * @param post.body - The parameters to send with the custom request. + */ + post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `post`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'POST', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + + /** + * This method allow you to send requests to the Algolia REST API. + * + * @summary Send requests to the Algolia REST API. + * @param put - The put object. + * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. + * @param put.parameters - Query parameters to be applied to the current query. + * @param put.body - The parameters to send with the custom request. + */ + put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { + if (!path) { + throw new Error('Parameter `path` is required when calling `put`.'); + } + + const requestPath = '/1{path}'.replace('{path}', path); + const headers: Headers = {}; + const queryParameters: QueryParameters = parameters || {}; + + const request: Request = { + method: 'PUT', + path: requestPath, + data: body, + }; + + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); + }, + }; +} + +export type RecommendApi = ReturnType; + +export type DelProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type GetProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; +}; + +export type PostProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; + +export type PutProps = { + /** + * The path of the API endpoint to target, anything after the /1 needs to be specified. + */ + path: string; + /** + * Query parameters to be applied to the current query. + */ + parameters?: Record; + /** + * The parameters to send with the custom request. + */ + body?: Record; +}; diff --git a/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php b/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php new file mode 100644 index 0000000000..3795eae75a --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/AbtestingApi.php @@ -0,0 +1,455 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials and region + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + * @param string $region Region + */ + public static function create($appId = null, $apiKey = null, $region = null) + { + $allowedRegions = explode('-', 'us-de'); + $config = AbtestingConfig::create($appId, $apiKey, $region, $allowedRegions); + + return static::createWithConfig($config); + } + + /** + * Instantiate the client with configuration + * + * @param AbtestingConfig $config Configuration + */ + public static function createWithConfig(AbtestingConfig $config) + { + $config = clone $config; + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } else { + $clusterHosts = ClusterHosts::create('analytics.'.$config->getRegion().'.algolia.com'); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return AbtestingConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Creates a new A/B test with provided configuration. + * + * @param array $addABTestsRequest addABTestsRequest (required) + * - $addABTestsRequest['name'] => (string) A/B test name. (required) + * - $addABTestsRequest['variant'] => (array) List of 2 variants for the A/B test. (required) + * - $addABTestsRequest['endAt'] => (string) End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsRequest + * + * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse + */ + public function addABTests($addABTestsRequest) + { + // verify the required parameter 'addABTestsRequest' is set + if ($addABTestsRequest === null || (is_array($addABTestsRequest) && count($addABTestsRequest) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $addABTestsRequest when calling addABTests' + ); + } + + $resourcePath = '/2/abtests'; + $queryParams = []; + $httpBody = []; + + if (isset($addABTestsRequest)) { + $httpBody = $addABTestsRequest; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Deletes the A/B Test. + * + * @param int $id The A/B test ID. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse + */ + public function deleteABTest($id) + { + // verify the required parameter 'id' is set + if ($id === null || (is_array($id) && count($id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $id when calling deleteABTest' + ); + } + + $resourcePath = '/2/abtests/{id}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($id !== null) { + $resourcePath = str_replace( + '{id}', + ObjectSerializer::toPathValue($id), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns metadata and metrics for A/B test id. + * + * @param int $id The A/B test ID. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTest + */ + public function getABTest($id) + { + // verify the required parameter 'id' is set + if ($id === null || (is_array($id) && count($id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $id when calling getABTest' + ); + } + + $resourcePath = '/2/abtests/{id}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($id !== null) { + $resourcePath = str_replace( + '{id}', + ObjectSerializer::toPathValue($id), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Fetch all existing A/B tests for App that are available for the current API Key. + * + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * + * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ListABTestsResponse + */ + public function listABTests($offset = 0, $limit = 10) + { + $resourcePath = '/2/abtests'; + $queryParams = []; + $httpBody = []; + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Marks the A/B test as stopped. + * + * @param int $id The A/B test ID. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse + */ + public function stopABTest($id) + { + // verify the required parameter 'id' is set + if ($id === null || (is_array($id) && count($id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $id when calling stopABTest' + ); + } + + $resourcePath = '/2/abtests/{id}/stop'; + $queryParams = []; + $httpBody = []; + + // path params + if ($id !== null) { + $resourcePath = str_replace( + '{id}', + ObjectSerializer::toPathValue($id), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php b/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php new file mode 100644 index 0000000000..a38c328e4a --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php @@ -0,0 +1,1771 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials and region + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + * @param string $region Region + */ + public static function create($appId = null, $apiKey = null, $region = null) + { + $allowedRegions = explode('-', 'us-de'); + $config = AnalyticsConfig::create($appId, $apiKey, $region, $allowedRegions); + + return static::createWithConfig($config); + } + + /** + * Instantiate the client with configuration + * + * @param AnalyticsConfig $config Configuration + */ + public static function createWithConfig(AnalyticsConfig $config) + { + $config = clone $config; + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } else { + $clusterHosts = ClusterHosts::create('analytics.'.$config->getRegion().'.algolia.com'); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return AnalyticsConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the average click position. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetAverageClickPositionResponse + */ + public function getAverageClickPosition($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getAverageClickPosition' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getAverageClickPosition, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getAverageClickPosition, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/clicks/averageClickPosition'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the distribution of clicks per range of positions. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetClickPositionsResponse + */ + public function getClickPositions($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getClickPositions' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getClickPositions, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getClickPositions, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/clicks/positions'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns a click-through rate (CTR). + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetClickThroughRateResponse + */ + public function getClickThroughRate($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getClickThroughRate' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getClickThroughRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getClickThroughRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/clicks/clickThroughRate'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns a conversion rate (CR). + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetConversationRateResponse + */ + public function getConversationRate($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getConversationRate' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getConversationRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getConversationRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/conversions/conversionRate'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the rate at which searches didn't lead to any clicks. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetNoClickRateResponse + */ + public function getNoClickRate($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getNoClickRate' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getNoClickRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getNoClickRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches/noClickRate'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the rate at which searches didn't return any results. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetNoResultsRateResponse + */ + public function getNoResultsRate($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getNoResultsRate' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getNoResultsRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getNoResultsRate, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches/noResultRate'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the number of searches across the given time range. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesCountResponse + */ + public function getSearchesCount($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getSearchesCount' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches/count'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top searches that didn't lead to any clicks. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesNoClicksResponse + */ + public function getSearchesNoClicks($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getSearchesNoClicks' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesNoClicks, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesNoClicks, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches/noClicks'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top searches that didn't return any results. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetSearchesNoResultsResponse + */ + public function getSearchesNoResults($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getSearchesNoResults' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getSearchesNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getSearchesNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches/noResults'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get latest update time of the analytics API. + * + * @param string $index The index name to target. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetStatusResponse + */ + public function getStatus($index) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getStatus' + ); + } + + $resourcePath = '/2/status'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top countries. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopCountriesResponse + */ + public function getTopCountries($index, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopCountries' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopCountries, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopCountries, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/countries'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top filter attributes. + * + * @param string $index The index name to target. (required) + * @param string $search The query term to search for. Must match the exact user input. (optional) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFilterAttributesResponse + */ + public function getTopFilterAttributes($index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopFilterAttributes' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFilterAttributes, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFilterAttributes, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/filters'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($search !== null) { + if ('form' === 'form' && is_array($search)) { + foreach ($search as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['search'] = $search; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top filters for the given attribute. + * + * @param string $attribute The exact name of the attribute. (required) + * @param string $index The index name to target. (required) + * @param string $search The query term to search for. Must match the exact user input. (optional) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFilterForAttributeResponse + */ + public function getTopFilterForAttribute($attribute, $index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'attribute' is set + if ($attribute === null || (is_array($attribute) && count($attribute) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $attribute when calling getTopFilterForAttribute' + ); + } + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopFilterForAttribute' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFilterForAttribute, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFilterForAttribute, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/filters/{attribute}'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($search !== null) { + if ('form' === 'form' && is_array($search)) { + foreach ($search as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['search'] = $search; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + // path params + if ($attribute !== null) { + $resourcePath = str_replace( + '{attribute}', + ObjectSerializer::toPathValue($attribute), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top filters with no results. + * + * @param string $index The index name to target. (required) + * @param string $search The query term to search for. Must match the exact user input. (optional) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopFiltersNoResultsResponse + */ + public function getTopFiltersNoResults($index, $search = null, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopFiltersNoResults' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopFiltersNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopFiltersNoResults, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/filters/noResults'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($search !== null) { + if ('form' === 'form' && is_array($search)) { + foreach ($search as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['search'] = $search; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top hits. + * + * @param string $index The index name to target. (required) + * @param string $search The query term to search for. Must match the exact user input. (optional) + * @param bool $clickAnalytics Whether to include the click-through and conversion rates for a search. (optional, default to false) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopHitsResponse + */ + public function getTopHits($index, $search = null, $clickAnalytics = false, $startDate = null, $endDate = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopHits' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopHits, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopHits, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/hits'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($search !== null) { + if ('form' === 'form' && is_array($search)) { + foreach ($search as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['search'] = $search; + } + } + + if ($clickAnalytics !== null) { + if ('form' === 'form' && is_array($clickAnalytics)) { + foreach ($clickAnalytics as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['clickAnalytics'] = $clickAnalytics; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns top searches. + * + * @param string $index The index name to target. (required) + * @param bool $clickAnalytics Whether to include the click-through and conversion rates for a search. (optional, default to false) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param array $orderBy Reorder the results. (optional) + * @param array $direction The sorting of the result. (optional) + * @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10) + * @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetTopSearchesResponse + */ + public function getTopSearches($index, $clickAnalytics = false, $startDate = null, $endDate = null, $orderBy = null, $direction = null, $limit = 10, $offset = 0, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getTopSearches' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getTopSearches, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getTopSearches, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/searches'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($clickAnalytics !== null) { + if ('form' === 'form' && is_array($clickAnalytics)) { + foreach ($clickAnalytics as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['clickAnalytics'] = $clickAnalytics; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($orderBy !== null) { + if ('form' === 'form' && is_array($orderBy)) { + foreach ($orderBy as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['orderBy'] = $orderBy; + } + } + + if ($direction !== null) { + if ('form' === 'form' && is_array($direction)) { + foreach ($direction as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['direction'] = $direction; + } + } + + if ($limit !== null) { + if ('form' === 'form' && is_array($limit)) { + foreach ($limit as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['limit'] = $limit; + } + } + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns the distinct count of users across the given time range. + * + * @param string $index The index name to target. (required) + * @param string $startDate The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $endDate The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. (optional) + * @param string $tags Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Analytics\GetUsersCountResponse + */ + public function getUsersCount($index, $startDate = null, $endDate = null, $tags = null) + { + // verify the required parameter 'index' is set + if ($index === null || (is_array($index) && count($index) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $index when calling getUsersCount' + ); + } + if ($startDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $startDate)) { + throw new \InvalidArgumentException('invalid value for "startDate" when calling AnalyticsApi.getUsersCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + if ($endDate !== null && !preg_match('/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $endDate)) { + throw new \InvalidArgumentException('invalid value for "endDate" when calling AnalyticsApi.getUsersCount, must conform to the pattern /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.'); + } + + $resourcePath = '/2/users/count'; + $queryParams = []; + $httpBody = []; + + if ($index !== null) { + if ('form' === 'form' && is_array($index)) { + foreach ($index as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['index'] = $index; + } + } + + if ($startDate !== null) { + if ('form' === 'form' && is_array($startDate)) { + foreach ($startDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['startDate'] = $startDate; + } + } + + if ($endDate !== null) { + if ('form' === 'form' && is_array($endDate)) { + foreach ($endDate as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['endDate'] = $endDate; + } + } + + if ($tags !== null) { + if ('form' === 'form' && is_array($tags)) { + foreach ($tags as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['tags'] = $tags; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/InsightsApi.php b/clients/algoliasearch-client-php/lib/Api/InsightsApi.php new file mode 100644 index 0000000000..858783fa6f --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/InsightsApi.php @@ -0,0 +1,319 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials and region + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + * @param string $region Region + */ + public static function create($appId = null, $apiKey = null, $region = null) + { + $allowedRegions = explode('-', 'us-de'); + $config = InsightsConfig::create($appId, $apiKey, $region, $allowedRegions); + + return static::createWithConfig($config); + } + + /** + * Instantiate the client with configuration + * + * @param InsightsConfig $config Configuration + */ + public static function createWithConfig(InsightsConfig $config) + { + $config = clone $config; + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } else { + $clusterHosts = ClusterHosts::create('insights.'.$config->getRegion().'.algolia.io'); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return InsightsConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Pushes an array of events. + * + * @param array $insightEvents insightEvents (required) + * - $insightEvents['events'] => (array) Array of events sent. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Insights\InsightEvents + * + * @return array|\Algolia\AlgoliaSearch\Model\Insights\PushEventsResponse + */ + public function pushEvents($insightEvents) + { + // verify the required parameter 'insightEvents' is set + if ($insightEvents === null || (is_array($insightEvents) && count($insightEvents) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $insightEvents when calling pushEvents' + ); + } + + $resourcePath = '/1/events'; + $queryParams = []; + $httpBody = []; + + if (isset($insightEvents)) { + $httpBody = $insightEvents; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php b/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php new file mode 100644 index 0000000000..9cda894221 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php @@ -0,0 +1,401 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials and region + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + * @param string $region Region + */ + public static function create($appId = null, $apiKey = null, $region = null) + { + $allowedRegions = explode('-', 'us-eu'); + $config = PersonalizationConfig::create($appId, $apiKey, $region, $allowedRegions); + + return static::createWithConfig($config); + } + + /** + * Instantiate the client with configuration + * + * @param PersonalizationConfig $config Configuration + */ + public static function createWithConfig(PersonalizationConfig $config) + { + $config = clone $config; + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } else { + $clusterHosts = ClusterHosts::create('personalization.'.$config->getRegion().'.algolia.com'); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return PersonalizationConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete the user profile and all its associated data. + * + * @param string $userToken userToken representing the user for which to fetch the Personalization profile. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Personalization\DeleteUserProfileResponse + */ + public function deleteUserProfile($userToken) + { + // verify the required parameter 'userToken' is set + if ($userToken === null || (is_array($userToken) && count($userToken) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $userToken when calling deleteUserProfile' + ); + } + + $resourcePath = '/1/profiles/{userToken}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($userToken !== null) { + $resourcePath = str_replace( + '{userToken}', + ObjectSerializer::toPathValue($userToken), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the current personalization strategy. + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Personalization\PersonalizationStrategyParams + */ + public function getPersonalizationStrategy() + { + $resourcePath = '/1/strategies/personalization'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the user profile built from Personalization strategy. + * + * @param string $userToken userToken representing the user for which to fetch the Personalization profile. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Personalization\GetUserTokenResponse + */ + public function getUserTokenProfile($userToken) + { + // verify the required parameter 'userToken' is set + if ($userToken === null || (is_array($userToken) && count($userToken) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $userToken when calling getUserTokenProfile' + ); + } + + $resourcePath = '/1/profiles/personalization/{userToken}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($userToken !== null) { + $resourcePath = str_replace( + '{userToken}', + ObjectSerializer::toPathValue($userToken), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Set a new personalization strategy. + * + * @param array $personalizationStrategyParams personalizationStrategyParams (required) + * - $personalizationStrategyParams['eventScoring'] => (array) Scores associated with the events. (required) + * - $personalizationStrategyParams['facetScoring'] => (array) Scores associated with the facets. (required) + * - $personalizationStrategyParams['personalizationImpact'] => (int) The impact that personalization has on search results: a number between 0 (personalization disabled) and 100 (personalization fully enabled). (required) + * + * @see \Algolia\AlgoliaSearch\Model\Personalization\PersonalizationStrategyParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Personalization\SetPersonalizationStrategyResponse + */ + public function setPersonalizationStrategy($personalizationStrategyParams) + { + // verify the required parameter 'personalizationStrategyParams' is set + if ($personalizationStrategyParams === null || (is_array($personalizationStrategyParams) && count($personalizationStrategyParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $personalizationStrategyParams when calling setPersonalizationStrategy' + ); + } + + $resourcePath = '/1/strategies/personalization'; + $queryParams = []; + $httpBody = []; + + if (isset($personalizationStrategyParams)) { + $httpBody = $personalizationStrategyParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php b/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php new file mode 100644 index 0000000000..ae21d7a7a0 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php @@ -0,0 +1,510 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials and region + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + * @param string $region Region + */ + public static function create($appId = null, $apiKey = null, $region = null) + { + $allowedRegions = explode('-', 'us-eu'); + $config = QuerySuggestionsConfig::create($appId, $apiKey, $region, $allowedRegions); + + return static::createWithConfig($config); + } + + /** + * Instantiate the client with configuration + * + * @param QuerySuggestionsConfig $config Configuration + */ + public static function createWithConfig(QuerySuggestionsConfig $config) + { + $config = clone $config; + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } else { + $clusterHosts = ClusterHosts::create('query-suggestions.'.$config->getRegion().'.algolia.com'); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return QuerySuggestionsConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Create a configuration of a Query Suggestions index. + * + * @param array $querySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam (required) + * + * @see \Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndexWithIndexParam + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse + */ + public function createConfig($querySuggestionsIndexWithIndexParam) + { + // verify the required parameter 'querySuggestionsIndexWithIndexParam' is set + if ($querySuggestionsIndexWithIndexParam === null || (is_array($querySuggestionsIndexWithIndexParam) && count($querySuggestionsIndexWithIndexParam) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $querySuggestionsIndexWithIndexParam when calling createConfig' + ); + } + + $resourcePath = '/1/configs'; + $queryParams = []; + $httpBody = []; + + if (isset($querySuggestionsIndexWithIndexParam)) { + $httpBody = $querySuggestionsIndexWithIndexParam; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete a configuration of a Query Suggestion's index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse + */ + public function deleteConfig($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteConfig' + ); + } + + $resourcePath = '/1/configs/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get all the configurations of Query Suggestions. + * + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndex[] + */ + public function getAllConfigs() + { + $resourcePath = '/1/configs'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the configuration of a single Query Suggestions index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndex + */ + public function getConfig($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getConfig' + ); + } + + $resourcePath = '/1/configs/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the status of a Query Suggestion's index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\Status + */ + public function getConfigStatus($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getConfigStatus' + ); + } + + $resourcePath = '/1/configs/{indexName}/status'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the log file of the last build of a single Query Suggestion index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\LogFile[] + */ + public function getLogFile($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getLogFile' + ); + } + + $resourcePath = '/1/logs/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Update the configuration of a Query Suggestions index. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $querySuggestionsIndexParam querySuggestionsIndexParam (required) + * - $querySuggestionsIndexParam['sourceIndices'] => (array) List of source indices used to generate a Query Suggestions index. (required) + * - $querySuggestionsIndexParam['languages'] => (array) De-duplicate singular and plural suggestions. For example, let's say your index contains English content, and that two suggestions “shoe” and “shoes” end up in your Query Suggestions index. If the English language is configured, only the most popular of those two suggestions would remain. + * - $querySuggestionsIndexParam['exclude'] => (array) List of words and patterns to exclude from the Query Suggestions index. + * + * @see \Algolia\AlgoliaSearch\Model\QuerySuggestions\QuerySuggestionsIndexParam + * + * @return array|\Algolia\AlgoliaSearch\Model\QuerySuggestions\SucessResponse + */ + public function updateConfig($indexName, $querySuggestionsIndexParam) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling updateConfig' + ); + } + // verify the required parameter 'querySuggestionsIndexParam' is set + if ($querySuggestionsIndexParam === null || (is_array($querySuggestionsIndexParam) && count($querySuggestionsIndexParam) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $querySuggestionsIndexParam when calling updateConfig' + ); + } + + $resourcePath = '/1/configs/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($querySuggestionsIndexParam)) { + $httpBody = $querySuggestionsIndexParam; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/RecommendApi.php b/clients/algoliasearch-client-php/lib/Api/RecommendApi.php new file mode 100644 index 0000000000..0656d79e25 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/RecommendApi.php @@ -0,0 +1,320 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + */ + public static function create($appId = null, $apiKey = null) + { + return static::createWithConfig(RecommendConfig::create($appId, $apiKey)); + } + + /** + * Instantiate the client with configuration + * + * @param RecommendConfig $config Configuration + */ + public static function createWithConfig(RecommendConfig $config) + { + $config = clone $config; + + $cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId()); + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) { + // We'll try to restore the ClusterHost from cache, if we cannot + // we create a new instance and set the cache key + $clusterHosts = ClusterHosts::createFromAppId($config->getAppId()) + ->setCacheKey($cacheKey); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return RecommendConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Returns recommendations for a specific model and objectID. + * + * @param array $getRecommendationsParams getRecommendationsParams (required) + * - $getRecommendationsParams['requests'] => (array) The `getRecommendations` requests. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Recommend\GetRecommendationsParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Recommend\GetRecommendationsResponse + */ + public function getRecommendations($getRecommendationsParams) + { + // verify the required parameter 'getRecommendationsParams' is set + if ($getRecommendationsParams === null || (is_array($getRecommendationsParams) && count($getRecommendationsParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $getRecommendationsParams when calling getRecommendations' + ); + } + + $resourcePath = '/1/indexes/*/recommendations'; + $queryParams = []; + $httpBody = []; + + if (isset($getRecommendationsParams)) { + $httpBody = $getRecommendationsParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} diff --git a/clients/algoliasearch-client-php/lib/Api/SearchApi.php b/clients/algoliasearch-client-php/lib/Api/SearchApi.php new file mode 100644 index 0000000000..71c8ecb9c2 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Api/SearchApi.php @@ -0,0 +1,2713 @@ +config = $config; + + $this->api = $apiWrapper; + } + + /** + * Instantiate the client with basic credentials + * + * @param string $appId Application ID + * @param string $apiKey Algolia API Key + */ + public static function create($appId = null, $apiKey = null) + { + return static::createWithConfig(SearchConfig::create($appId, $apiKey)); + } + + /** + * Instantiate the client with configuration + * + * @param SearchConfig $config Configuration + */ + public static function createWithConfig(SearchConfig $config) + { + $config = clone $config; + + $cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId()); + + if ($hosts = $config->getHosts()) { + // If a list of hosts was passed, we ignore the cache + $clusterHosts = ClusterHosts::create($hosts); + } elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) { + // We'll try to restore the ClusterHost from cache, if we cannot + // we create a new instance and set the cache key + $clusterHosts = ClusterHosts::createFromAppId($config->getAppId()) + ->setCacheKey($cacheKey); + } + + $apiWrapper = new ApiWrapper( + Algolia::getHttpClient(), + $config, + $clusterHosts + ); + + return new static($apiWrapper, $config); + } + + /** + * @return SearchConfig + */ + public function getClientConfig() + { + return $this->config; + } + + /** + * Create a new API key. + * + * @param array $apiKey apiKey (required) + * - $apiKey['acl'] => (array) Set of permissions associated with the key. (required) + * - $apiKey['description'] => (string) A comment used to identify a key more easily in the dashboard. It is not interpreted by the API. + * - $apiKey['indexes'] => (array) Restrict this new API key to a list of indices or index patterns. If the list is empty, all indices are allowed. + * - $apiKey['maxHitsPerQuery'] => (int) Maximum number of hits this API key can retrieve in one query. If zero, no limit is enforced. + * - $apiKey['maxQueriesPerIPPerHour'] => (int) Maximum number of API calls per hour allowed from a given IP address or a user token. + * - $apiKey['queryParameters'] => (string) URL-encoded query string. Force some query parameters to be applied for each query made with this API key. + * - $apiKey['referers'] => (array) Restrict this new API key to specific referers. If empty or blank, defaults to all referers. + * - $apiKey['validity'] => (int) Validity limit for this key in seconds. The key will automatically be removed after this period of time. + * + * @see \Algolia\AlgoliaSearch\Model\Search\ApiKey + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\AddApiKeyResponse + */ + public function addApiKey($apiKey) + { + // verify the required parameter 'apiKey' is set + if ($apiKey === null || (is_array($apiKey) && count($apiKey) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $apiKey when calling addApiKey' + ); + } + + $resourcePath = '/1/keys'; + $queryParams = []; + $httpBody = []; + + if (isset($apiKey)) { + $httpBody = $apiKey; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Add or replace an object with a given object ID. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param array $body The Algolia object. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtWithObjectIdResponse + */ + public function addOrUpdateObject($indexName, $objectID, $body) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling addOrUpdateObject' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling addOrUpdateObject' + ); + } + // verify the required parameter 'body' is set + if ($body === null || (is_array($body) && count($body) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $body when calling addOrUpdateObject' + ); + } + + $resourcePath = '/1/indexes/{indexName}/{objectID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Add a single source. + * + * @param array $source The source to add. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\Source + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse + */ + public function appendSource($source) + { + // verify the required parameter 'source' is set + if ($source === null || (is_array($source) && count($source) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $source when calling appendSource' + ); + } + + $resourcePath = '/1/security/sources/append'; + $queryParams = []; + $httpBody = []; + + if (isset($source)) { + $httpBody = $source; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Assign or Move userID + * + * @param string $xAlgoliaUserID userID to assign. (required) + * @param array $assignUserIdParams assignUserIdParams (required) + * - $assignUserIdParams['cluster'] => (string) Name of the cluster. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\AssignUserIdParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse + */ + public function assignUserId($xAlgoliaUserID, $assignUserIdParams) + { + // verify the required parameter 'xAlgoliaUserID' is set + if ($xAlgoliaUserID === null || (is_array($xAlgoliaUserID) && count($xAlgoliaUserID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $xAlgoliaUserID when calling assignUserId' + ); + } + if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) { + throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchApi.assignUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); + } + + // verify the required parameter 'assignUserIdParams' is set + if ($assignUserIdParams === null || (is_array($assignUserIdParams) && count($assignUserIdParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $assignUserIdParams when calling assignUserId' + ); + } + + $resourcePath = '/1/clusters/mapping'; + $queryParams = []; + $httpBody = []; + + if ($xAlgoliaUserID !== null) { + if ('form' === 'form' && is_array($xAlgoliaUserID)) { + foreach ($xAlgoliaUserID as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['X-Algolia-User-ID'] = $xAlgoliaUserID; + } + } + + if (isset($assignUserIdParams)) { + $httpBody = $assignUserIdParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Performs multiple write operations in a single API call. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $batchWriteParams batchWriteParams (required) + * - $batchWriteParams['requests'] => (array) + * + * @see \Algolia\AlgoliaSearch\Model\Search\BatchWriteParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\BatchResponse + */ + public function batch($indexName, $batchWriteParams) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling batch' + ); + } + // verify the required parameter 'batchWriteParams' is set + if ($batchWriteParams === null || (is_array($batchWriteParams) && count($batchWriteParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $batchWriteParams when calling batch' + ); + } + + $resourcePath = '/1/indexes/{indexName}/batch'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($batchWriteParams)) { + $httpBody = $batchWriteParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Batch assign userIDs + * + * @param string $xAlgoliaUserID userID to assign. (required) + * @param array $batchAssignUserIdsParams batchAssignUserIdsParams (required) + * - $batchAssignUserIdsParams['cluster'] => (string) Name of the cluster. (required) + * - $batchAssignUserIdsParams['users'] => (array) userIDs to assign. Note you cannot move users with this method. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\BatchAssignUserIdsParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse + */ + public function batchAssignUserIds($xAlgoliaUserID, $batchAssignUserIdsParams) + { + // verify the required parameter 'xAlgoliaUserID' is set + if ($xAlgoliaUserID === null || (is_array($xAlgoliaUserID) && count($xAlgoliaUserID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $xAlgoliaUserID when calling batchAssignUserIds' + ); + } + if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) { + throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchApi.batchAssignUserIds, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); + } + + // verify the required parameter 'batchAssignUserIdsParams' is set + if ($batchAssignUserIdsParams === null || (is_array($batchAssignUserIdsParams) && count($batchAssignUserIdsParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $batchAssignUserIdsParams when calling batchAssignUserIds' + ); + } + + $resourcePath = '/1/clusters/mapping/batch'; + $queryParams = []; + $httpBody = []; + + if ($xAlgoliaUserID !== null) { + if ('form' === 'form' && is_array($xAlgoliaUserID)) { + foreach ($xAlgoliaUserID as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['X-Algolia-User-ID'] = $xAlgoliaUserID; + } + } + + if (isset($batchAssignUserIdsParams)) { + $httpBody = $batchAssignUserIdsParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send a batch of dictionary entries. + * + * @param array $dictionaryName The dictionary to search in. (required) + * @param array $batchDictionaryEntriesParams batchDictionaryEntriesParams (required) + * - $batchDictionaryEntriesParams['clearExistingDictionaryEntries'] => (bool) When `true`, start the batch by removing all the custom entries from the dictionary. + * - $batchDictionaryEntriesParams['requests'] => (array) List of operations to batch. Each operation is described by an `action` and a `body`. (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\BatchDictionaryEntriesParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function batchDictionaryEntries($dictionaryName, $batchDictionaryEntriesParams) + { + // verify the required parameter 'dictionaryName' is set + if ($dictionaryName === null || (is_array($dictionaryName) && count($dictionaryName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $dictionaryName when calling batchDictionaryEntries' + ); + } + // verify the required parameter 'batchDictionaryEntriesParams' is set + if ($batchDictionaryEntriesParams === null || (is_array($batchDictionaryEntriesParams) && count($batchDictionaryEntriesParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $batchDictionaryEntriesParams when calling batchDictionaryEntries' + ); + } + + $resourcePath = '/1/dictionaries/{dictionaryName}/batch'; + $queryParams = []; + $httpBody = []; + + // path params + if ($dictionaryName !== null) { + $resourcePath = str_replace( + '{dictionaryName}', + ObjectSerializer::toPathValue($dictionaryName), + $resourcePath + ); + } + + if (isset($batchDictionaryEntriesParams)) { + $httpBody = $batchDictionaryEntriesParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Batch Rules. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $rule rule (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * @param bool $clearExistingRules When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function batchRules($indexName, $rule, $forwardToReplicas = null, $clearExistingRules = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling batchRules' + ); + } + // verify the required parameter 'rule' is set + if ($rule === null || (is_array($rule) && count($rule) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $rule when calling batchRules' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/batch'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + if ($clearExistingRules !== null) { + if ('form' === 'form' && is_array($clearExistingRules)) { + foreach ($clearExistingRules as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['clearExistingRules'] = $clearExistingRules; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($rule)) { + $httpBody = $rule; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Retrieve all index content. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $browseRequest browseRequest (optional) + * - $browseRequest['params'] => (string) Search parameters as URL-encoded query string. + * - $browseRequest['cursor'] => (string) Cursor indicating the location to resume browsing from. Must match the value returned by the previous call. + * + * @see \Algolia\AlgoliaSearch\Model\Search\BrowseRequest + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\BrowseResponse + */ + public function browse($indexName, $browseRequest = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling browse' + ); + } + + $resourcePath = '/1/indexes/{indexName}/browse'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($browseRequest)) { + $httpBody = $browseRequest; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Clear all synonyms. + * + * @param string $indexName The index in which to perform the request. (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function clearAllSynonyms($indexName, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling clearAllSynonyms' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/clear'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * clear all objects from an index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function clearObjects($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling clearObjects' + ); + } + + $resourcePath = '/1/indexes/{indexName}/clear'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Clear Rules. + * + * @param string $indexName The index in which to perform the request. (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function clearRules($indexName, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling clearRules' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/clear'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function del($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling del' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete an API key. + * + * @param string $key API Key string. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeleteApiKeyResponse + */ + public function deleteApiKey($key) + { + // verify the required parameter 'key' is set + if ($key === null || (is_array($key) && count($key) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $key when calling deleteApiKey' + ); + } + + $resourcePath = '/1/keys/{key}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($key !== null) { + $resourcePath = str_replace( + '{key}', + ObjectSerializer::toPathValue($key), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete all records matching the query. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $searchParams searchParams (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse + */ + public function deleteBy($indexName, $searchParams) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteBy' + ); + } + // verify the required parameter 'searchParams' is set + if ($searchParams === null || (is_array($searchParams) && count($searchParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $searchParams when calling deleteBy' + ); + } + + $resourcePath = '/1/indexes/{indexName}/deleteByQuery'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($searchParams)) { + $httpBody = $searchParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete index. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse + */ + public function deleteIndex($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteIndex' + ); + } + + $resourcePath = '/1/indexes/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete object. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse + */ + public function deleteObject($indexName, $objectID) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteObject' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling deleteObject' + ); + } + + $resourcePath = '/1/indexes/{indexName}/{objectID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete a rule. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function deleteRule($indexName, $objectID, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteRule' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling deleteRule' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Remove a single source. + * + * @param string $source The IP range of the source. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeleteSourceResponse + */ + public function deleteSource($source) + { + // verify the required parameter 'source' is set + if ($source === null || (is_array($source) && count($source) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $source when calling deleteSource' + ); + } + + $resourcePath = '/1/security/sources/{source}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($source !== null) { + $resourcePath = str_replace( + '{source}', + ObjectSerializer::toPathValue($source), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Delete synonym. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse + */ + public function deleteSynonym($indexName, $objectID, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling deleteSynonym' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling deleteSynonym' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * + * @return array|object + */ + public function get($path, $parameters = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling get' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get an API key. + * + * @param string $key API Key string. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\Key + */ + public function getApiKey($key) + { + // verify the required parameter 'key' is set + if ($key === null || (is_array($key) && count($key) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $key when calling getApiKey' + ); + } + + $resourcePath = '/1/keys/{key}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($key !== null) { + $resourcePath = str_replace( + '{key}', + ObjectSerializer::toPathValue($key), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * List dictionaries supported per language. + * + * + * @return array|array + */ + public function getDictionaryLanguages() + { + $resourcePath = '/1/dictionaries/*/languages'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values. + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\GetDictionarySettingsResponse + */ + public function getDictionarySettings() + { + $resourcePath = '/1/dictionaries/*/settings'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Return the lastest log entries. + * + * @param int $offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, therefore 0 designates the most recent log entry. (optional, default to 0) + * @param int $length Maximum number of entries to retrieve. The maximum allowed value is 1000. (optional, default to 10) + * @param string $indexName Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. (optional) + * @param array $type Type of log entries to retrieve. When omitted, all log entries are retrieved. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\GetLogsResponse + */ + public function getLogs($offset = 0, $length = 10, $indexName = null, $type = null) + { + if ($length !== null && $length > 1000) { + throw new \InvalidArgumentException('invalid value for "$length" when calling SearchApi.getLogs, must be smaller than or equal to 1000.'); + } + + $resourcePath = '/1/logs'; + $queryParams = []; + $httpBody = []; + + if ($offset !== null) { + if ('form' === 'form' && is_array($offset)) { + foreach ($offset as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['offset'] = $offset; + } + } + + if ($length !== null) { + if ('form' === 'form' && is_array($length)) { + foreach ($length as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['length'] = $length; + } + } + + if ($indexName !== null) { + if ('form' === 'form' && is_array($indexName)) { + foreach ($indexName as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['indexName'] = $indexName; + } + } + + if ($type !== null) { + if ('form' === 'form' && is_array($type)) { + foreach ($type as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['type'] = $type; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Retrieve one object from the index. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param array $attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable attributes are returned. (optional) + * + * @return array|array + */ + public function getObject($indexName, $objectID, $attributesToRetrieve = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getObject' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling getObject' + ); + } + + $resourcePath = '/1/indexes/{indexName}/{objectID}'; + $queryParams = []; + $httpBody = []; + + if ($attributesToRetrieve !== null) { + if ('form' === 'form' && is_array($attributesToRetrieve)) { + foreach ($attributesToRetrieve as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['attributesToRetrieve'] = $attributesToRetrieve; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Retrieve one or more objects. + * + * @param array $getObjectsParams getObjectsParams (required) + * - $getObjectsParams['requests'] => (array) + * + * @see \Algolia\AlgoliaSearch\Model\Search\GetObjectsParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\GetObjectsResponse + */ + public function getObjects($getObjectsParams) + { + // verify the required parameter 'getObjectsParams' is set + if ($getObjectsParams === null || (is_array($getObjectsParams) && count($getObjectsParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $getObjectsParams when calling getObjects' + ); + } + + $resourcePath = '/1/indexes/*/objects'; + $queryParams = []; + $httpBody = []; + + if (isset($getObjectsParams)) { + $httpBody = $getObjectsParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get a rule. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\Rule + */ + public function getRule($indexName, $objectID) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getRule' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling getRule' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Retrieve settings of a given indexName. + * + * @param string $indexName The index in which to perform the request. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\IndexSettings + */ + public function getSettings($indexName) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getSettings' + ); + } + + $resourcePath = '/1/indexes/{indexName}/settings'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * List all allowed sources. + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\Source[] + */ + public function getSources() + { + $resourcePath = '/1/security/sources'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get synonym. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SynonymHit + */ + public function getSynonym($indexName, $objectID) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getSynonym' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling getSynonym' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Check the current status of a given task. + * + * @param string $indexName The index in which to perform the request. (required) + * @param int $taskID Unique identifier of an task. Numeric value (up to 64bits). (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\GetTaskResponse + */ + public function getTask($indexName, $taskID) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling getTask' + ); + } + // verify the required parameter 'taskID' is set + if ($taskID === null || (is_array($taskID) && count($taskID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $taskID when calling getTask' + ); + } + + $resourcePath = '/1/indexes/{indexName}/task/{taskID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($taskID !== null) { + $resourcePath = str_replace( + '{taskID}', + ObjectSerializer::toPathValue($taskID), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get top userID + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\GetTopUserIdsResponse + */ + public function getTopUserIds() + { + $resourcePath = '/1/clusters/mapping/top'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get userID + * + * @param string $userID userID to assign. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UserId + */ + public function getUserId($userID) + { + // verify the required parameter 'userID' is set + if ($userID === null || (is_array($userID) && count($userID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $userID when calling getUserId' + ); + } + if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $userID)) { + throw new \InvalidArgumentException('invalid value for "userID" when calling SearchApi.getUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); + } + + $resourcePath = '/1/clusters/mapping/{userID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($userID !== null) { + $resourcePath = str_replace( + '{userID}', + ObjectSerializer::toPathValue($userID), + $resourcePath + ); + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Has pending mappings + * + * @param bool $getClusters Whether to get clusters or not. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse + */ + public function hasPendingMappings($getClusters = null) + { + $resourcePath = '/1/clusters/mapping/pending'; + $queryParams = []; + $httpBody = []; + + if ($getClusters !== null) { + if ('form' === 'form' && is_array($getClusters)) { + foreach ($getClusters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['getClusters'] = $getClusters; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get the full list of API Keys. + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\ListApiKeysResponse + */ + public function listApiKeys() + { + $resourcePath = '/1/keys'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * List clusters + * + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\ListClustersResponse + */ + public function listClusters() + { + $resourcePath = '/1/clusters'; + $queryParams = []; + $httpBody = []; + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * List existing indexes. + * + * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\ListIndicesResponse + */ + public function listIndices($page = null) + { + $resourcePath = '/1/indexes'; + $queryParams = []; + $httpBody = []; + + if ($page !== null) { + if ('form' === 'form' && is_array($page)) { + foreach ($page as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['page'] = $page; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * List userIDs + * + * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional) + * @param int $hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\ListUserIdsResponse + */ + public function listUserIds($page = null, $hitsPerPage = 100) + { + $resourcePath = '/1/clusters/mapping'; + $queryParams = []; + $httpBody = []; + + if ($page !== null) { + if ('form' === 'form' && is_array($page)) { + foreach ($page as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['page'] = $page; + } + } + + if ($hitsPerPage !== null) { + if ('form' === 'form' && is_array($hitsPerPage)) { + foreach ($hitsPerPage as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['hitsPerPage'] = $hitsPerPage; + } + } + + return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody); + } + + /** + * Perform multiple write operations. + * + * @param array $batchParams batchParams (required) + * - $batchParams['requests'] => (array) + * + * @see \Algolia\AlgoliaSearch\Model\Search\BatchParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\MultipleBatchResponse + */ + public function multipleBatch($batchParams) + { + // verify the required parameter 'batchParams' is set + if ($batchParams === null || (is_array($batchParams) && count($batchParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $batchParams when calling multipleBatch' + ); + } + + $resourcePath = '/1/indexes/*/batch'; + $queryParams = []; + $httpBody = []; + + if (isset($batchParams)) { + $httpBody = $batchParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get search results for the given requests. + * + * @param array $multipleQueriesParams multipleQueriesParams (required) + * - $multipleQueriesParams['requests'] => (array) (required) + * - $multipleQueriesParams['strategy'] => (array) + * + * @see \Algolia\AlgoliaSearch\Model\Search\MultipleQueriesParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\MultipleQueriesResponse + */ + public function multipleQueries($multipleQueriesParams) + { + // verify the required parameter 'multipleQueriesParams' is set + if ($multipleQueriesParams === null || (is_array($multipleQueriesParams) && count($multipleQueriesParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $multipleQueriesParams when calling multipleQueries' + ); + } + + $resourcePath = '/1/indexes/*/queries'; + $queryParams = []; + $httpBody = []; + + if (isset($multipleQueriesParams)) { + $httpBody = $multipleQueriesParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Copy/move index. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $operationIndexParams operationIndexParams (required) + * - $operationIndexParams['operation'] => (array) (required) + * - $operationIndexParams['destination'] => (string) The Algolia index name. (required) + * - $operationIndexParams['scope'] => (array) Scope of the data to copy. When absent, a full copy is performed. When present, only the selected scopes are copied. + * + * @see \Algolia\AlgoliaSearch\Model\Search\OperationIndexParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function operationIndex($indexName, $operationIndexParams) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling operationIndex' + ); + } + // verify the required parameter 'operationIndexParams' is set + if ($operationIndexParams === null || (is_array($operationIndexParams) && count($operationIndexParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $operationIndexParams when calling operationIndex' + ); + } + + $resourcePath = '/1/indexes/{indexName}/operation'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($operationIndexParams)) { + $httpBody = $operationIndexParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Partially update an object. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param array $attributeOrBuiltInOperation List of attributes to update. (required) + * @param bool $createIfNotExists Creates the record if it does not exist yet. (optional, default to true) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtWithObjectIdResponse + */ + public function partialUpdateObject($indexName, $objectID, $attributeOrBuiltInOperation, $createIfNotExists = true) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling partialUpdateObject' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling partialUpdateObject' + ); + } + // verify the required parameter 'attributeOrBuiltInOperation' is set + if ($attributeOrBuiltInOperation === null || (is_array($attributeOrBuiltInOperation) && count($attributeOrBuiltInOperation) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $attributeOrBuiltInOperation when calling partialUpdateObject' + ); + } + + $resourcePath = '/1/indexes/{indexName}/{objectID}/partial'; + $queryParams = []; + $httpBody = []; + + if ($createIfNotExists !== null) { + if ('form' === 'form' && is_array($createIfNotExists)) { + foreach ($createIfNotExists as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['createIfNotExists'] = $createIfNotExists; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + if (isset($attributeOrBuiltInOperation)) { + $httpBody = $attributeOrBuiltInOperation; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function post($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling post' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Send requests to the Algolia REST API. + * + * @param string $path The path of the API endpoint to target, anything after the /1 needs to be specified. (required) + * @param array $parameters Query parameters to be applied to the current query. (optional) + * @param array $body The parameters to send with the custom request. (optional) + * + * @return array|object + */ + public function put($path, $parameters = null, $body = null) + { + // verify the required parameter 'path' is set + if ($path === null || (is_array($path) && count($path) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $path when calling put' + ); + } + + $resourcePath = '/1{path}'; + $queryParams = []; + $httpBody = []; + + if ($parameters !== null) { + if ('form' === 'form' && is_array($parameters)) { + foreach ($parameters as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams = $parameters; + } + } + + // path params + if ($path !== null) { + $resourcePath = str_replace( + '{path}', + $path, + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Remove userID + * + * @param string $userID userID to assign. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\RemoveUserIdResponse + */ + public function removeUserId($userID) + { + // verify the required parameter 'userID' is set + if ($userID === null || (is_array($userID) && count($userID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $userID when calling removeUserId' + ); + } + if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $userID)) { + throw new \InvalidArgumentException('invalid value for "userID" when calling SearchApi.removeUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.'); + } + + $resourcePath = '/1/clusters/mapping/{userID}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($userID !== null) { + $resourcePath = str_replace( + '{userID}', + ObjectSerializer::toPathValue($userID), + $resourcePath + ); + } + + return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody); + } + + /** + * Replace all allowed sources. + * + * @param array $source The sources to allow. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\ReplaceSourceResponse + */ + public function replaceSources($source) + { + // verify the required parameter 'source' is set + if ($source === null || (is_array($source) && count($source) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $source when calling replaceSources' + ); + } + + $resourcePath = '/1/security/sources'; + $queryParams = []; + $httpBody = []; + + if (isset($source)) { + $httpBody = $source; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Restore an API key. + * + * @param string $key API Key string. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\AddApiKeyResponse + */ + public function restoreApiKey($key) + { + // verify the required parameter 'key' is set + if ($key === null || (is_array($key) && count($key) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $key when calling restoreApiKey' + ); + } + + $resourcePath = '/1/keys/{key}/restore'; + $queryParams = []; + $httpBody = []; + + // path params + if ($key !== null) { + $resourcePath = str_replace( + '{key}', + ObjectSerializer::toPathValue($key), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Add an object to the index. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $body The Algolia record. (required) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SaveObjectResponse + */ + public function saveObject($indexName, $body) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling saveObject' + ); + } + // verify the required parameter 'body' is set + if ($body === null || (is_array($body) && count($body) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $body when calling saveObject' + ); + } + + $resourcePath = '/1/indexes/{indexName}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($body)) { + $httpBody = $body; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Save/Update a rule. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param array $rule rule (required) + * - $rule['objectID'] => (string) Unique identifier of the object. (required) + * - $rule['conditions'] => (array) A list of conditions that should apply to activate a Rule. You can use up to 25 conditions per Rule. + * - $rule['consequence'] => (array) (required) + * - $rule['description'] => (string) This field is intended for Rule management purposes, in particular to ease searching for Rules and presenting them to human readers. It's not interpreted by the API. + * - $rule['enabled'] => (bool) Whether the Rule is enabled. Disabled Rules remain in the index, but aren't applied at query time. + * - $rule['validity'] => (array) By default, Rules are permanently valid. When validity periods are specified, the Rule applies only during those periods; it's ignored the rest of the time. The list must not be empty. + * + * @see \Algolia\AlgoliaSearch\Model\Search\Rule + * + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedRuleResponse + */ + public function saveRule($indexName, $objectID, $rule, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling saveRule' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling saveRule' + ); + } + // verify the required parameter 'rule' is set + if ($rule === null || (is_array($rule) && count($rule) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $rule when calling saveRule' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/{objectID}'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + if (isset($rule)) { + $httpBody = $rule; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Save synonym. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $objectID Unique identifier of an object. (required) + * @param array $synonymHit synonymHit (required) + * - $synonymHit['objectID'] => (string) Unique identifier of the synonym object to be created or updated. (required) + * - $synonymHit['type'] => (array) + * - $synonymHit['synonyms'] => (array) Words or phrases to be considered equivalent. + * - $synonymHit['input'] => (string) Word or phrase to appear in query strings (for onewaysynonym). + * - $synonymHit['word'] => (string) Word or phrase to appear in query strings (for altcorrection1 and altcorrection2). + * - $synonymHit['corrections'] => (array) Words to be matched in records. + * - $synonymHit['placeholder'] => (string) Token to be put inside records. + * - $synonymHit['replacements'] => (array) List of query words that will match the token. + * - $synonymHit['_highlightResult'] => (array) + * + * @see \Algolia\AlgoliaSearch\Model\Search\SynonymHit + * + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SaveSynonymResponse + */ + public function saveSynonym($indexName, $objectID, $synonymHit, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling saveSynonym' + ); + } + // verify the required parameter 'objectID' is set + if ($objectID === null || (is_array($objectID) && count($objectID) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $objectID when calling saveSynonym' + ); + } + // verify the required parameter 'synonymHit' is set + if ($synonymHit === null || (is_array($synonymHit) && count($synonymHit) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $synonymHit when calling saveSynonym' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/{objectID}'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($objectID !== null) { + $resourcePath = str_replace( + '{objectID}', + ObjectSerializer::toPathValue($objectID), + $resourcePath + ); + } + + if (isset($synonymHit)) { + $httpBody = $synonymHit; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Save a batch of synonyms. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $synonymHit synonymHit (required) + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * @param bool $replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this request. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function saveSynonyms($indexName, $synonymHit, $forwardToReplicas = null, $replaceExistingSynonyms = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling saveSynonyms' + ); + } + // verify the required parameter 'synonymHit' is set + if ($synonymHit === null || (is_array($synonymHit) && count($synonymHit) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $synonymHit when calling saveSynonyms' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/batch'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + if ($replaceExistingSynonyms !== null) { + if ('form' === 'form' && is_array($replaceExistingSynonyms)) { + foreach ($replaceExistingSynonyms as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['replaceExistingSynonyms'] = $replaceExistingSynonyms; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($synonymHit)) { + $httpBody = $synonymHit; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get search results. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $searchParams searchParams (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchResponse + */ + public function search($indexName, $searchParams) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling search' + ); + } + // verify the required parameter 'searchParams' is set + if ($searchParams === null || (is_array($searchParams) && count($searchParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $searchParams when calling search' + ); + } + + $resourcePath = '/1/indexes/{indexName}/query'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($searchParams)) { + $httpBody = $searchParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Search the dictionary entries. + * + * @param array $dictionaryName The dictionary to search in. (required) + * @param array $searchDictionaryEntriesParams searchDictionaryEntriesParams (required) + * - $searchDictionaryEntriesParams['query'] => (string) The text to search in the index. (required) + * - $searchDictionaryEntriesParams['page'] => (int) Specify the page to retrieve. + * - $searchDictionaryEntriesParams['hitsPerPage'] => (int) Set the number of hits per page. + * - $searchDictionaryEntriesParams['language'] => (string) Language ISO code supported by the dictionary (e.g., \"en\" for English). + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchDictionaryEntriesParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function searchDictionaryEntries($dictionaryName, $searchDictionaryEntriesParams) + { + // verify the required parameter 'dictionaryName' is set + if ($dictionaryName === null || (is_array($dictionaryName) && count($dictionaryName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $dictionaryName when calling searchDictionaryEntries' + ); + } + // verify the required parameter 'searchDictionaryEntriesParams' is set + if ($searchDictionaryEntriesParams === null || (is_array($searchDictionaryEntriesParams) && count($searchDictionaryEntriesParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $searchDictionaryEntriesParams when calling searchDictionaryEntries' + ); + } + + $resourcePath = '/1/dictionaries/{dictionaryName}/search'; + $queryParams = []; + $httpBody = []; + + // path params + if ($dictionaryName !== null) { + $resourcePath = str_replace( + '{dictionaryName}', + ObjectSerializer::toPathValue($dictionaryName), + $resourcePath + ); + } + + if (isset($searchDictionaryEntriesParams)) { + $httpBody = $searchDictionaryEntriesParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Search for values of a given facet + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $facetName The facet name. (required) + * @param array $searchForFacetValuesRequest searchForFacetValuesRequest (optional) + * - $searchForFacetValuesRequest['params'] => (string) Search parameters as URL-encoded query string. + * - $searchForFacetValuesRequest['facetQuery'] => (string) Text to search inside the facet's values. + * - $searchForFacetValuesRequest['maxFacetHits'] => (int) Maximum number of facet hits to return during a search for facet values. For performance reasons, the maximum allowed number of returned values is 100. + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchForFacetValuesRequest + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchForFacetValuesResponse + */ + public function searchForFacetValues($indexName, $facetName, $searchForFacetValuesRequest = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling searchForFacetValues' + ); + } + // verify the required parameter 'facetName' is set + if ($facetName === null || (is_array($facetName) && count($facetName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $facetName when calling searchForFacetValues' + ); + } + + $resourcePath = '/1/indexes/{indexName}/facets/{facetName}/query'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + // path params + if ($facetName !== null) { + $resourcePath = str_replace( + '{facetName}', + ObjectSerializer::toPathValue($facetName), + $resourcePath + ); + } + + if (isset($searchForFacetValuesRequest)) { + $httpBody = $searchForFacetValuesRequest; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Search for rules. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $searchRulesParams searchRulesParams (required) + * - $searchRulesParams['query'] => (string) Full text query. + * - $searchRulesParams['anchoring'] => (array) + * - $searchRulesParams['context'] => (string) Restricts matches to contextual rules with a specific context (exact match). + * - $searchRulesParams['page'] => (int) Requested page (zero-based). + * - $searchRulesParams['hitsPerPage'] => (int) Maximum number of hits in a page. Minimum is 1, maximum is 1000. + * - $searchRulesParams['enabled'] => (bool) When specified, restricts matches to rules with a specific enabled status. When absent (default), all rules are retrieved, regardless of their enabled status. + * - $searchRulesParams['requestOptions'] => (array) A mapping of requestOptions to send along with the request. + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchRulesParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchRulesResponse + */ + public function searchRules($indexName, $searchRulesParams) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling searchRules' + ); + } + // verify the required parameter 'searchRulesParams' is set + if ($searchRulesParams === null || (is_array($searchRulesParams) && count($searchRulesParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $searchRulesParams when calling searchRules' + ); + } + + $resourcePath = '/1/indexes/{indexName}/rules/search'; + $queryParams = []; + $httpBody = []; + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($searchRulesParams)) { + $httpBody = $searchRulesParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Get all synonyms that match a query. + * + * @param string $indexName The index in which to perform the request. (required) + * @param string $query Search for specific synonyms matching this string. (optional, default to '') + * @param array $type Only search for specific types of synonyms. (optional) + * @param int $page Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). (optional, default to 0) + * @param int $hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchSynonymsResponse + */ + public function searchSynonyms($indexName, $query = '', $type = null, $page = 0, $hitsPerPage = 100) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling searchSynonyms' + ); + } + + $resourcePath = '/1/indexes/{indexName}/synonyms/search'; + $queryParams = []; + $httpBody = []; + + if ($query !== null) { + if ('form' === 'form' && is_array($query)) { + foreach ($query as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['query'] = $query; + } + } + + if ($type !== null) { + if ('form' === 'form' && is_array($type)) { + foreach ($type as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['type'] = $type; + } + } + + if ($page !== null) { + if ('form' === 'form' && is_array($page)) { + foreach ($page as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['page'] = $page; + } + } + + if ($hitsPerPage !== null) { + if ('form' === 'form' && is_array($hitsPerPage)) { + foreach ($hitsPerPage as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['hitsPerPage'] = $hitsPerPage; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Search userID + * + * @param array $searchUserIdsParams searchUserIdsParams (required) + * - $searchUserIdsParams['query'] => (string) Query to search. The search is a prefix search with typoTolerance. Use empty query to retrieve all users. (required) + * - $searchUserIdsParams['clusterName'] => (string) Name of the cluster. + * - $searchUserIdsParams['page'] => (int) Specify the page to retrieve. + * - $searchUserIdsParams['hitsPerPage'] => (int) Set the number of hits per page. + * + * @see \Algolia\AlgoliaSearch\Model\Search\SearchUserIdsParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\SearchUserIdsResponse + */ + public function searchUserIds($searchUserIdsParams) + { + // verify the required parameter 'searchUserIdsParams' is set + if ($searchUserIdsParams === null || (is_array($searchUserIdsParams) && count($searchUserIdsParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $searchUserIdsParams when calling searchUserIds' + ); + } + + $resourcePath = '/1/clusters/mapping/search'; + $queryParams = []; + $httpBody = []; + + if (isset($searchUserIdsParams)) { + $httpBody = $searchUserIdsParams; + } + + return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody); + } + + /** + * Set dictionary settings. + * + * @param array $dictionarySettingsParams dictionarySettingsParams (required) + * - $dictionarySettingsParams['disableStandardEntries'] => (array) (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\DictionarySettingsParams + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function setDictionarySettings($dictionarySettingsParams) + { + // verify the required parameter 'dictionarySettingsParams' is set + if ($dictionarySettingsParams === null || (is_array($dictionarySettingsParams) && count($dictionarySettingsParams) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $dictionarySettingsParams when calling setDictionarySettings' + ); + } + + $resourcePath = '/1/dictionaries/*/settings'; + $queryParams = []; + $httpBody = []; + + if (isset($dictionarySettingsParams)) { + $httpBody = $dictionarySettingsParams; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Update settings of a given indexName. + * + * @param string $indexName The index in which to perform the request. (required) + * @param array $indexSettings indexSettings (required) + * + * @see \Algolia\AlgoliaSearch\Model\Search\IndexSettings + * + * @param bool $forwardToReplicas When true, changes are also propagated to replicas of the given indexName. (optional) + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse + */ + public function setSettings($indexName, $indexSettings, $forwardToReplicas = null) + { + // verify the required parameter 'indexName' is set + if ($indexName === null || (is_array($indexName) && count($indexName) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexName when calling setSettings' + ); + } + // verify the required parameter 'indexSettings' is set + if ($indexSettings === null || (is_array($indexSettings) && count($indexSettings) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $indexSettings when calling setSettings' + ); + } + + $resourcePath = '/1/indexes/{indexName}/settings'; + $queryParams = []; + $httpBody = []; + + if ($forwardToReplicas !== null) { + if ('form' === 'form' && is_array($forwardToReplicas)) { + foreach ($forwardToReplicas as $key => $value) { + $queryParams[$key] = $value; + } + } else { + $queryParams['forwardToReplicas'] = $forwardToReplicas; + } + } + + // path params + if ($indexName !== null) { + $resourcePath = str_replace( + '{indexName}', + ObjectSerializer::toPathValue($indexName), + $resourcePath + ); + } + + if (isset($indexSettings)) { + $httpBody = $indexSettings; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + /** + * Update an API key. + * + * @param string $key API Key string. (required) + * @param array $apiKey apiKey (required) + * - $apiKey['acl'] => (array) Set of permissions associated with the key. (required) + * - $apiKey['description'] => (string) A comment used to identify a key more easily in the dashboard. It is not interpreted by the API. + * - $apiKey['indexes'] => (array) Restrict this new API key to a list of indices or index patterns. If the list is empty, all indices are allowed. + * - $apiKey['maxHitsPerQuery'] => (int) Maximum number of hits this API key can retrieve in one query. If zero, no limit is enforced. + * - $apiKey['maxQueriesPerIPPerHour'] => (int) Maximum number of API calls per hour allowed from a given IP address or a user token. + * - $apiKey['queryParameters'] => (string) URL-encoded query string. Force some query parameters to be applied for each query made with this API key. + * - $apiKey['referers'] => (array) Restrict this new API key to specific referers. If empty or blank, defaults to all referers. + * - $apiKey['validity'] => (int) Validity limit for this key in seconds. The key will automatically be removed after this period of time. + * + * @see \Algolia\AlgoliaSearch\Model\Search\ApiKey + * + * @return array|\Algolia\AlgoliaSearch\Model\Search\UpdateApiKeyResponse + */ + public function updateApiKey($key, $apiKey) + { + // verify the required parameter 'key' is set + if ($key === null || (is_array($key) && count($key) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $key when calling updateApiKey' + ); + } + // verify the required parameter 'apiKey' is set + if ($apiKey === null || (is_array($apiKey) && count($apiKey) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $apiKey when calling updateApiKey' + ); + } + + $resourcePath = '/1/keys/{key}'; + $queryParams = []; + $httpBody = []; + + // path params + if ($key !== null) { + $resourcePath = str_replace( + '{key}', + ObjectSerializer::toPathValue($key), + $resourcePath + ); + } + + if (isset($apiKey)) { + $httpBody = $apiKey; + } + + return $this->sendRequest('PUT', $resourcePath, $queryParams, $httpBody); + } + + private function sendRequest($method, $resourcePath, $queryParams, $httpBody) + { + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + + if ($method === 'GET') { + $request = $this->api->read( + $method, + $resourcePath . ($query ? "?{$query}" : '') + ); + } else { + $request = $this->api->write( + $method, + $resourcePath . ($query ? "?{$query}" : ''), + $httpBody + ); + } + + return $request; + } +} From 160a4cee804dfa153d74ac8448cbbd41b2337598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 20 Apr 2022 16:22:47 +0200 Subject: [PATCH 5/6] make CLI delete api folder --- config/clients.config.json | 3 +++ scripts/config.ts | 4 ++++ scripts/generate.ts | 4 ++-- scripts/pre-gen/index.ts | 2 +- ...stingModel.ts => removeExistingCodegen.ts} | 22 ++++++++++++++++--- 5 files changed, 29 insertions(+), 6 deletions(-) rename scripts/pre-gen/{removeExistingModel.ts => removeExistingCodegen.ts} (54%) diff --git a/config/clients.config.json b/config/clients.config.json index 64a2eb4003..5c999a9878 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -3,6 +3,7 @@ "folder": "clients/algoliasearch-client-java-2", "mainPackage": "java-search", "modelFolder": "algoliasearch-core/com/algolia/model", + "apiFolder": "algoliasearch-core/com/algolia/api", "customGenerator": "algolia-java", "tests": { "extension": ".test.java", @@ -13,6 +14,7 @@ "folder": "clients/algoliasearch-client-javascript", "mainPackage": "javascript-search", "modelFolder": "model", + "apiFolder": "src", "customGenerator": "algolia-javascript", "tests": { "extension": ".test.ts", @@ -23,6 +25,7 @@ "folder": "clients/algoliasearch-client-php", "mainPackage": "php-search", "modelFolder": "lib/Model", + "apiFolder": "lib/Api", "customGenerator": "algolia-php" } } diff --git a/scripts/config.ts b/scripts/config.ts index 30638510d8..9cd43beabd 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -4,6 +4,10 @@ export function getLanguageFolder(language: string): string { return clientsConfig[language].folder; } +export function getLanguageApiFolder(language: string): string { + return clientsConfig[language].apiFolder; +} + export function getLanguageModelFolder(language: string): string { return clientsConfig[language].modelFolder; } diff --git a/scripts/generate.ts b/scripts/generate.ts index 6c6ae34897..b168b2933f 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -3,11 +3,11 @@ import { buildCustomGenerators, CI, run } from './common'; import { getCustomGenerator, getLanguageFolder } from './config'; import { formatter } from './formatter'; import { createSpinner } from './oraLog'; -import { removeExistingModel, setDefaultGeneratorOptions } from './pre-gen'; +import { removeExistingCodegen, setDefaultGeneratorOptions } from './pre-gen'; import type { Generator } from './types'; async function preGen(gen: Generator, verbose?: boolean): Promise { - await removeExistingModel(gen, verbose); + await removeExistingCodegen(gen, verbose); await setDefaultGeneratorOptions(gen); } diff --git a/scripts/pre-gen/index.ts b/scripts/pre-gen/index.ts index cb2119fc23..30f042dae8 100644 --- a/scripts/pre-gen/index.ts +++ b/scripts/pre-gen/index.ts @@ -1,2 +1,2 @@ -export * from './removeExistingModel'; +export * from './removeExistingCodegen'; export * from './setDefaultGeneratorOptions'; diff --git a/scripts/pre-gen/removeExistingModel.ts b/scripts/pre-gen/removeExistingCodegen.ts similarity index 54% rename from scripts/pre-gen/removeExistingModel.ts rename to scripts/pre-gen/removeExistingCodegen.ts index 65aa96e1d2..fb609b2f61 100644 --- a/scripts/pre-gen/removeExistingModel.ts +++ b/scripts/pre-gen/removeExistingCodegen.ts @@ -1,31 +1,37 @@ import path from 'path'; import { run, toAbsolutePath } from '../common'; -import { getLanguageModelFolder } from '../config'; +import { getLanguageApiFolder, getLanguageModelFolder } from '../config'; import { createClientName } from '../cts/utils'; import type { Generator } from '../types'; /** * Remove `model` folder for the current language and client. */ -export async function removeExistingModel( +export async function removeExistingCodegen( { language, client, output }: Generator, verbose?: boolean ): Promise { const baseModelFolder = getLanguageModelFolder(language); + const baseApiFolder = getLanguageApiFolder(language); + const clientName = createClientName(client, language); let clientModel = ''; + let clientApi = ''; switch (language) { case 'java': clientModel = client; + clientApi = `${clientName}*.java`; break; case 'php': - clientModel = createClientName(client, 'php'); + clientModel = clientName; + clientApi = `${clientName}*.php`; break; default: break; } + // Delete client model folder/file await run( `rm -rf ${toAbsolutePath( path.resolve('..', output, baseModelFolder, clientModel) @@ -34,4 +40,14 @@ export async function removeExistingModel( verbose, } ); + + // Delete client api folder/file + await run( + `rm -rf ${toAbsolutePath( + path.resolve('..', output, baseApiFolder, clientApi) + )}`, + { + verbose, + } + ); } From 0b745a9a0fabb7a77abfe06efd65f8f630602240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 20 Apr 2022 16:27:35 +0200 Subject: [PATCH 6/6] clean cache its good --- .github/.cache_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.cache_version b/.github/.cache_version index e9e6e4d233..e5acc09430 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -8.0.4.2 +8.0.4.3