|
| 1 | +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on |
| 2 | +// https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 3 | + |
| 4 | +import Foundation |
| 5 | +#if canImport(Core) |
| 6 | + import Core |
| 7 | +#endif |
| 8 | + |
| 9 | +open class CompositionClient { |
| 10 | + private var configuration: CompositionClientConfiguration |
| 11 | + private var transporter: Transporter |
| 12 | + |
| 13 | + var appID: String { |
| 14 | + self.configuration.appID |
| 15 | + } |
| 16 | + |
| 17 | + public init(configuration: CompositionClientConfiguration, transporter: Transporter) { |
| 18 | + self.configuration = configuration |
| 19 | + self.transporter = transporter |
| 20 | + } |
| 21 | + |
| 22 | + public convenience init(configuration: CompositionClientConfiguration) { |
| 23 | + self.init(configuration: configuration, transporter: Transporter(configuration: configuration)) |
| 24 | + } |
| 25 | + |
| 26 | + public convenience init(appID: String, apiKey: String) throws { |
| 27 | + try self.init(configuration: CompositionClientConfiguration(appID: appID, apiKey: apiKey)) |
| 28 | + } |
| 29 | + |
| 30 | + open func setClientApiKey(apiKey: String) { |
| 31 | + self.configuration.apiKey = apiKey |
| 32 | + self.transporter.setClientApiKey(apiKey: apiKey) |
| 33 | + } |
| 34 | + |
| 35 | + /// - parameter compositionID: (path) Unique Composition ObjectID. |
| 36 | + /// - parameter requestBody: (body) |
| 37 | + /// - returns: CompositionSearchResponse |
| 38 | + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) |
| 39 | + open func search<T: Codable>( |
| 40 | + compositionID: String, |
| 41 | + requestBody: CompositionRequestBody, |
| 42 | + requestOptions: RequestOptions? = nil |
| 43 | + ) async throws -> CompositionSearchResponse<T> { |
| 44 | + let response: Response<CompositionSearchResponse<T>> = try await searchWithHTTPInfo( |
| 45 | + compositionID: compositionID, |
| 46 | + requestBody: requestBody, |
| 47 | + requestOptions: requestOptions |
| 48 | + ) |
| 49 | + |
| 50 | + guard let body = response.body else { |
| 51 | + throw AlgoliaError.missingData |
| 52 | + } |
| 53 | + |
| 54 | + return body |
| 55 | + } |
| 56 | + |
| 57 | + // Runs a query on a single composition and returns matching results. |
| 58 | + // Required API Key ACLs: |
| 59 | + // - search |
| 60 | + // |
| 61 | + // - parameter compositionID: (path) Unique Composition ObjectID. |
| 62 | + // |
| 63 | + // - parameter requestBody: (body) |
| 64 | + // - returns: RequestBuilder<CompositionSearchResponse> |
| 65 | + |
| 66 | + open func searchWithHTTPInfo<T: Codable>( |
| 67 | + compositionID: String, |
| 68 | + requestBody: CompositionRequestBody, |
| 69 | + requestOptions userRequestOptions: RequestOptions? = nil |
| 70 | + ) async throws -> Response<CompositionSearchResponse<T>> { |
| 71 | + guard !compositionID.isEmpty else { |
| 72 | + throw AlgoliaError.invalidArgument("compositionID", "search") |
| 73 | + } |
| 74 | + |
| 75 | + var resourcePath = "/1/compositions/{compositionID}/run" |
| 76 | + let compositionIDPreEscape = "\(APIHelper.mapValueToPathItem(compositionID))" |
| 77 | + let compositionIDPostEscape = compositionIDPreEscape |
| 78 | + .addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? "" |
| 79 | + resourcePath = resourcePath.replacingOccurrences( |
| 80 | + of: "{compositionID}", |
| 81 | + with: compositionIDPostEscape, |
| 82 | + options: .literal, |
| 83 | + range: nil |
| 84 | + ) |
| 85 | + let body = requestBody |
| 86 | + let queryParameters: [String: Any?]? = nil |
| 87 | + |
| 88 | + let nillableHeaders: [String: Any?]? = nil |
| 89 | + |
| 90 | + let headers = APIHelper.rejectNilHeaders(nillableHeaders) |
| 91 | + |
| 92 | + return try await self.transporter.send( |
| 93 | + method: "POST", |
| 94 | + path: resourcePath, |
| 95 | + data: body, |
| 96 | + requestOptions: RequestOptions( |
| 97 | + headers: headers, |
| 98 | + queryParameters: queryParameters |
| 99 | + ) + userRequestOptions, |
| 100 | + useReadTransporter: true |
| 101 | + ) |
| 102 | + } |
| 103 | + |
| 104 | + /// - parameter compositionID: (path) Unique Composition ObjectID. |
| 105 | + /// - parameter facetName: (path) Facet attribute in which to search for values. This attribute must be included in |
| 106 | + /// the `attributesForFaceting` index setting with the `searchable()` modifier. |
| 107 | + /// - parameter searchForFacetValuesRequest: (body) (optional) |
| 108 | + /// - returns: CompositionSearchForFacetValuesResponse |
| 109 | + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) |
| 110 | + open func searchForFacetValues( |
| 111 | + compositionID: String, |
| 112 | + facetName: String, |
| 113 | + searchForFacetValuesRequest: CompositionSearchForFacetValuesRequest? = nil, |
| 114 | + requestOptions: RequestOptions? = nil |
| 115 | + ) async throws -> CompositionSearchForFacetValuesResponse { |
| 116 | + let response: Response<CompositionSearchForFacetValuesResponse> = try await searchForFacetValuesWithHTTPInfo( |
| 117 | + compositionID: compositionID, |
| 118 | + facetName: facetName, |
| 119 | + searchForFacetValuesRequest: searchForFacetValuesRequest, |
| 120 | + requestOptions: requestOptions |
| 121 | + ) |
| 122 | + |
| 123 | + guard let body = response.body else { |
| 124 | + throw AlgoliaError.missingData |
| 125 | + } |
| 126 | + |
| 127 | + return body |
| 128 | + } |
| 129 | + |
| 130 | + // Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet |
| 131 | + // values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching |
| 132 | + // for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. |
| 133 | + // Required API Key ACLs: |
| 134 | + // - search |
| 135 | + // |
| 136 | + // - parameter compositionID: (path) Unique Composition ObjectID. |
| 137 | + // |
| 138 | + // - parameter facetName: (path) Facet attribute in which to search for values. This attribute must be included in |
| 139 | + // the `attributesForFaceting` index setting with the `searchable()` modifier. |
| 140 | + // |
| 141 | + // - parameter searchForFacetValuesRequest: (body) (optional) |
| 142 | + // - returns: RequestBuilder<CompositionSearchForFacetValuesResponse> |
| 143 | + |
| 144 | + open func searchForFacetValuesWithHTTPInfo( |
| 145 | + compositionID: String, |
| 146 | + facetName: String, |
| 147 | + searchForFacetValuesRequest: CompositionSearchForFacetValuesRequest? = nil, |
| 148 | + requestOptions userRequestOptions: RequestOptions? = nil |
| 149 | + ) async throws -> Response<CompositionSearchForFacetValuesResponse> { |
| 150 | + guard !compositionID.isEmpty else { |
| 151 | + throw AlgoliaError.invalidArgument("compositionID", "searchForFacetValues") |
| 152 | + } |
| 153 | + |
| 154 | + guard !facetName.isEmpty else { |
| 155 | + throw AlgoliaError.invalidArgument("facetName", "searchForFacetValues") |
| 156 | + } |
| 157 | + |
| 158 | + var resourcePath = "/1/compositions/{compositionID}/facets/{facetName}/query" |
| 159 | + let compositionIDPreEscape = "\(APIHelper.mapValueToPathItem(compositionID))" |
| 160 | + let compositionIDPostEscape = compositionIDPreEscape |
| 161 | + .addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? "" |
| 162 | + resourcePath = resourcePath.replacingOccurrences( |
| 163 | + of: "{compositionID}", |
| 164 | + with: compositionIDPostEscape, |
| 165 | + options: .literal, |
| 166 | + range: nil |
| 167 | + ) |
| 168 | + let facetNamePreEscape = "\(APIHelper.mapValueToPathItem(facetName))" |
| 169 | + let facetNamePostEscape = facetNamePreEscape |
| 170 | + .addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? "" |
| 171 | + resourcePath = resourcePath.replacingOccurrences( |
| 172 | + of: "{facetName}", |
| 173 | + with: facetNamePostEscape, |
| 174 | + options: .literal, |
| 175 | + range: nil |
| 176 | + ) |
| 177 | + let body = searchForFacetValuesRequest |
| 178 | + let queryParameters: [String: Any?]? = nil |
| 179 | + |
| 180 | + let nillableHeaders: [String: Any?]? = nil |
| 181 | + |
| 182 | + let headers = APIHelper.rejectNilHeaders(nillableHeaders) |
| 183 | + |
| 184 | + return try await self.transporter.send( |
| 185 | + method: "POST", |
| 186 | + path: resourcePath, |
| 187 | + data: body ?? AnyCodable(), |
| 188 | + requestOptions: RequestOptions( |
| 189 | + headers: headers, |
| 190 | + queryParameters: queryParameters |
| 191 | + ) + userRequestOptions, |
| 192 | + useReadTransporter: true |
| 193 | + ) |
| 194 | + } |
| 195 | +} |
0 commit comments