|
| 1 | +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 2 | + |
| 3 | +import 'package:algolia_client_core/algolia_client_core.dart'; |
| 4 | +import 'package:algolia_client_composition/src/deserialize.dart'; |
| 5 | +import 'package:algolia_client_composition/src/version.dart'; |
| 6 | + |
| 7 | +import 'package:algolia_client_composition/src/model/request_body.dart'; |
| 8 | +import 'package:algolia_client_composition/src/model/search_for_facet_values_request.dart'; |
| 9 | +import 'package:algolia_client_composition/src/model/search_for_facet_values_response.dart'; |
| 10 | +import 'package:algolia_client_composition/src/model/search_response.dart'; |
| 11 | + |
| 12 | +final class CompositionClient implements ApiClient { |
| 13 | + @override |
| 14 | + final ClientOptions options; |
| 15 | + |
| 16 | + final RetryStrategy _retryStrategy; |
| 17 | + |
| 18 | + CompositionClient({ |
| 19 | + required String appId, |
| 20 | + required String apiKey, |
| 21 | + this.options = const ClientOptions(), |
| 22 | + }) : _retryStrategy = RetryStrategy.create( |
| 23 | + segment: AgentSegment(value: "Composition", version: packageVersion), |
| 24 | + appId: appId, |
| 25 | + apiKey: apiKey, |
| 26 | + options: options, |
| 27 | + defaultHosts: () => |
| 28 | + [ |
| 29 | + Host(url: '$appId-dsn.algolia.net', callType: CallType.read), |
| 30 | + Host(url: '$appId.algolia.net', callType: CallType.write), |
| 31 | + ] + |
| 32 | + ([ |
| 33 | + Host(url: '$appId-1.algolianet.com'), |
| 34 | + Host(url: '$appId-2.algolianet.com'), |
| 35 | + Host(url: '$appId-3.algolianet.com'), |
| 36 | + ]..shuffle()), |
| 37 | + ) { |
| 38 | + assert(appId.isNotEmpty, '`appId` is missing.'); |
| 39 | + assert(apiKey.isNotEmpty, '`apiKey` is missing.'); |
| 40 | + } |
| 41 | + |
| 42 | + /// Allows to switch the API key used to authenticate requests. |
| 43 | + @override |
| 44 | + void setClientApiKey({required String apiKey}) { |
| 45 | + _retryStrategy.requester.setClientApiKey(apiKey); |
| 46 | + } |
| 47 | + |
| 48 | + /// Runs a query on a single composition and returns matching results. |
| 49 | + /// |
| 50 | + /// Required API Key ACLs: |
| 51 | + /// - search |
| 52 | + /// |
| 53 | + /// Parameters: |
| 54 | + /// * [compositionID] Unique Composition ObjectID. |
| 55 | + /// * [requestBody] |
| 56 | + /// * [requestOptions] additional request configuration. |
| 57 | + Future<SearchResponse> search({ |
| 58 | + required String compositionID, |
| 59 | + required RequestBody requestBody, |
| 60 | + RequestOptions? requestOptions, |
| 61 | + }) async { |
| 62 | + assert( |
| 63 | + compositionID.isNotEmpty, |
| 64 | + 'Parameter `compositionID` is required when calling `search`.', |
| 65 | + ); |
| 66 | + final request = ApiRequest( |
| 67 | + method: RequestMethod.post, |
| 68 | + path: r'/1/compositions/{compositionID}/run'.replaceAll( |
| 69 | + '{' r'compositionID' '}', |
| 70 | + Uri.encodeComponent(compositionID.toString())), |
| 71 | + isRead: true, |
| 72 | + body: requestBody.toJson(), |
| 73 | + ); |
| 74 | + final response = await _retryStrategy.execute( |
| 75 | + request: request, |
| 76 | + options: requestOptions, |
| 77 | + ); |
| 78 | + return deserialize<SearchResponse, SearchResponse>( |
| 79 | + response, |
| 80 | + 'SearchResponse', |
| 81 | + growable: true, |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + /// Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. |
| 86 | + /// |
| 87 | + /// Required API Key ACLs: |
| 88 | + /// - search |
| 89 | + /// |
| 90 | + /// Parameters: |
| 91 | + /// * [compositionID] Unique Composition ObjectID. |
| 92 | + /// * [facetName] Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. |
| 93 | + /// * [searchForFacetValuesRequest] |
| 94 | + /// * [requestOptions] additional request configuration. |
| 95 | + Future<SearchForFacetValuesResponse> searchForFacetValues({ |
| 96 | + required String compositionID, |
| 97 | + required String facetName, |
| 98 | + SearchForFacetValuesRequest? searchForFacetValuesRequest, |
| 99 | + RequestOptions? requestOptions, |
| 100 | + }) async { |
| 101 | + assert( |
| 102 | + compositionID.isNotEmpty, |
| 103 | + 'Parameter `compositionID` is required when calling `searchForFacetValues`.', |
| 104 | + ); |
| 105 | + assert( |
| 106 | + facetName.isNotEmpty, |
| 107 | + 'Parameter `facetName` is required when calling `searchForFacetValues`.', |
| 108 | + ); |
| 109 | + final request = ApiRequest( |
| 110 | + method: RequestMethod.post, |
| 111 | + path: r'/1/compositions/{compositionID}/facets/{facetName}/query' |
| 112 | + .replaceAll('{' r'compositionID' '}', |
| 113 | + Uri.encodeComponent(compositionID.toString())) |
| 114 | + .replaceAll( |
| 115 | + '{' r'facetName' '}', Uri.encodeComponent(facetName.toString())), |
| 116 | + isRead: true, |
| 117 | + body: searchForFacetValuesRequest?.toJson(), |
| 118 | + ); |
| 119 | + final response = await _retryStrategy.execute( |
| 120 | + request: request, |
| 121 | + options: requestOptions, |
| 122 | + ); |
| 123 | + return deserialize<SearchForFacetValuesResponse, |
| 124 | + SearchForFacetValuesResponse>( |
| 125 | + response, |
| 126 | + 'SearchForFacetValuesResponse', |
| 127 | + growable: true, |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + @override |
| 132 | + void dispose() => _retryStrategy.dispose(); |
| 133 | +} |
0 commit comments