Skip to content

Commit 3532b6c

Browse files
feat(specs): add v2 endpoints for ingestion
algolia/api-clients-automation#3416 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 9cf23ef commit 3532b6c

10 files changed

+194
-20
lines changed

Sources/Ingestion/IngestionClient.swift

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,76 @@ open class IngestionClient {
23762376
)
23772377
}
23782378

2379+
/// - parameter taskID: (path) Unique identifier of a task.
2380+
/// - parameter batchWriteParams: (body) Request body of a Search API `batch` request that will be pushed in the
2381+
/// Connectors pipeline.
2382+
/// - returns: RunResponse
2383+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
2384+
open func pushTask(
2385+
taskID: String,
2386+
batchWriteParams: IngestionBatchWriteParams,
2387+
requestOptions: RequestOptions? = nil
2388+
) async throws -> RunResponse {
2389+
let response: Response<RunResponse> = try await pushTaskWithHTTPInfo(
2390+
taskID: taskID,
2391+
batchWriteParams: batchWriteParams,
2392+
requestOptions: requestOptions
2393+
)
2394+
2395+
guard let body = response.body else {
2396+
throw AlgoliaError.missingData
2397+
}
2398+
2399+
return body
2400+
}
2401+
2402+
// Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the
2403+
// observability endpoints.
2404+
// Required API Key ACLs:
2405+
// - addObject
2406+
// - deleteIndex
2407+
// - editSettings
2408+
//
2409+
// - parameter taskID: (path) Unique identifier of a task.
2410+
//
2411+
// - parameter batchWriteParams: (body) Request body of a Search API `batch` request that will be pushed in the
2412+
// Connectors pipeline.
2413+
// - returns: RequestBuilder<RunResponse>
2414+
2415+
open func pushTaskWithHTTPInfo(
2416+
taskID: String,
2417+
batchWriteParams: IngestionBatchWriteParams,
2418+
requestOptions userRequestOptions: RequestOptions? = nil
2419+
) async throws -> Response<RunResponse> {
2420+
guard !taskID.isEmpty else {
2421+
throw AlgoliaError.invalidArgument("taskID", "pushTask")
2422+
}
2423+
2424+
var resourcePath = "/2/tasks/{taskID}/push"
2425+
let taskIDPreEscape = "\(APIHelper.mapValueToPathItem(taskID))"
2426+
let taskIDPostEscape = taskIDPreEscape
2427+
.addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? ""
2428+
resourcePath = resourcePath.replacingOccurrences(
2429+
of: "{taskID}",
2430+
with: taskIDPostEscape,
2431+
options: .literal,
2432+
range: nil
2433+
)
2434+
let body = batchWriteParams
2435+
let queryParameters: [String: Any?]? = nil
2436+
2437+
let nillableHeaders: [String: Any?]? = nil
2438+
2439+
let headers = APIHelper.rejectNilHeaders(nillableHeaders)
2440+
2441+
return try await self.transporter.send(
2442+
method: "POST",
2443+
path: resourcePath,
2444+
data: body,
2445+
requestOptions: RequestOptions(headers: headers, queryParameters: queryParameters) + userRequestOptions
2446+
)
2447+
}
2448+
23792449
/// - parameter taskID: (path) Unique identifier of a task.
23802450
/// - returns: RunResponse
23812451
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/// Type of indexing operation.
10+
public enum IngestionAction: String, Codable, CaseIterable {
11+
case addObject
12+
case updateObject
13+
case partialUpdateObject
14+
case partialUpdateObjectNoCreate
15+
case deleteObject
16+
case delete
17+
case clear
18+
}
19+
20+
extension IngestionAction: Hashable {}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
public struct IngestionBatchRequest: Codable, JSONEncodable {
10+
public var action: IngestionAction
11+
/// Operation arguments (varies with specified `action`).
12+
public var body: AnyCodable
13+
14+
public init(action: IngestionAction, body: AnyCodable) {
15+
self.action = action
16+
self.body = body
17+
}
18+
19+
public enum CodingKeys: String, CodingKey, CaseIterable {
20+
case action
21+
case body
22+
}
23+
24+
// Encodable protocol methods
25+
26+
public func encode(to encoder: Encoder) throws {
27+
var container = encoder.container(keyedBy: CodingKeys.self)
28+
try container.encode(self.action, forKey: .action)
29+
try container.encode(self.body, forKey: .body)
30+
}
31+
}
32+
33+
extension IngestionBatchRequest: Equatable {
34+
public static func ==(lhs: IngestionBatchRequest, rhs: IngestionBatchRequest) -> Bool {
35+
lhs.action == rhs.action &&
36+
lhs.body == rhs.body
37+
}
38+
}
39+
40+
extension IngestionBatchRequest: Hashable {
41+
public func hash(into hasher: inout Hasher) {
42+
hasher.combine(self.action.hashValue)
43+
hasher.combine(self.body.hashValue)
44+
}
45+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
/// Batch parameters.
10+
public struct IngestionBatchWriteParams: Codable, JSONEncodable {
11+
public var requests: [IngestionBatchRequest]
12+
13+
public init(requests: [IngestionBatchRequest]) {
14+
self.requests = requests
15+
}
16+
17+
public enum CodingKeys: String, CodingKey, CaseIterable {
18+
case requests
19+
}
20+
21+
// Encodable protocol methods
22+
23+
public func encode(to encoder: Encoder) throws {
24+
var container = encoder.container(keyedBy: CodingKeys.self)
25+
try container.encode(self.requests, forKey: .requests)
26+
}
27+
}
28+
29+
extension IngestionBatchWriteParams: Equatable {
30+
public static func ==(lhs: IngestionBatchWriteParams, rhs: IngestionBatchWriteParams) -> Bool {
31+
lhs.requests == rhs.requests
32+
}
33+
}
34+
35+
extension IngestionBatchWriteParams: Hashable {
36+
public func hash(into hasher: inout Hasher) {
37+
hasher.combine(self.requests.hashValue)
38+
}
39+
}

Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public extension SearchClient {
426426
func chunkedBatch(
427427
indexName: String,
428428
objects: [some Encodable],
429-
action: Action = .addObject,
429+
action: SearchAction = .addObject,
430430
waitForTasks: Bool = false,
431431
batchSize: Int = 1000,
432432
requestOptions: RequestOptions? = nil
@@ -439,7 +439,7 @@ public extension SearchClient {
439439
for batch in batches {
440440
let batchResponse = try await self.batch(
441441
indexName: indexName,
442-
batchWriteParams: BatchWriteParams(
442+
batchWriteParams: SearchBatchWriteParams(
443443
requests: batch.map {
444444
.init(action: action, body: AnyCodable($0))
445445
}

Sources/Search/Models/MultipleBatchRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import Foundation
77
#endif
88

99
public struct MultipleBatchRequest: Codable, JSONEncodable {
10-
public var action: Action
10+
public var action: SearchAction
1111
/// Operation arguments (varies with specified `action`).
1212
public var body: AnyCodable
1313
/// Index name (case-sensitive).
1414
public var indexName: String
1515

16-
public init(action: Action, body: AnyCodable, indexName: String) {
16+
public init(action: SearchAction, body: AnyCodable, indexName: String) {
1717
self.action = action
1818
self.body = body
1919
self.indexName = indexName

Sources/Search/Models/Action.swift renamed to Sources/Search/Models/SearchAction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
#endif
88

99
/// Type of indexing operation.
10-
public enum Action: String, Codable, CaseIterable {
10+
public enum SearchAction: String, Codable, CaseIterable {
1111
case addObject
1212
case updateObject
1313
case partialUpdateObject
@@ -17,4 +17,4 @@ public enum Action: String, Codable, CaseIterable {
1717
case clear
1818
}
1919

20-
extension Action: Hashable {}
20+
extension SearchAction: Hashable {}

Sources/Search/Models/BatchRequest.swift renamed to Sources/Search/Models/SearchBatchRequest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import Foundation
66
import Core
77
#endif
88

9-
public struct BatchRequest: Codable, JSONEncodable {
10-
public var action: Action
9+
public struct SearchBatchRequest: Codable, JSONEncodable {
10+
public var action: SearchAction
1111
/// Operation arguments (varies with specified `action`).
1212
public var body: AnyCodable
1313

14-
public init(action: Action, body: AnyCodable) {
14+
public init(action: SearchAction, body: AnyCodable) {
1515
self.action = action
1616
self.body = body
1717
}
@@ -30,14 +30,14 @@ public struct BatchRequest: Codable, JSONEncodable {
3030
}
3131
}
3232

33-
extension BatchRequest: Equatable {
34-
public static func ==(lhs: BatchRequest, rhs: BatchRequest) -> Bool {
33+
extension SearchBatchRequest: Equatable {
34+
public static func ==(lhs: SearchBatchRequest, rhs: SearchBatchRequest) -> Bool {
3535
lhs.action == rhs.action &&
3636
lhs.body == rhs.body
3737
}
3838
}
3939

40-
extension BatchRequest: Hashable {
40+
extension SearchBatchRequest: Hashable {
4141
public func hash(into hasher: inout Hasher) {
4242
hasher.combine(self.action.hashValue)
4343
hasher.combine(self.body.hashValue)

Sources/Search/Models/BatchWriteParams.swift renamed to Sources/Search/Models/SearchBatchWriteParams.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import Foundation
77
#endif
88

99
/// Batch parameters.
10-
public struct BatchWriteParams: Codable, JSONEncodable {
11-
public var requests: [BatchRequest]
10+
public struct SearchBatchWriteParams: Codable, JSONEncodable {
11+
public var requests: [SearchBatchRequest]
1212

13-
public init(requests: [BatchRequest]) {
13+
public init(requests: [SearchBatchRequest]) {
1414
self.requests = requests
1515
}
1616

@@ -26,13 +26,13 @@ public struct BatchWriteParams: Codable, JSONEncodable {
2626
}
2727
}
2828

29-
extension BatchWriteParams: Equatable {
30-
public static func ==(lhs: BatchWriteParams, rhs: BatchWriteParams) -> Bool {
29+
extension SearchBatchWriteParams: Equatable {
30+
public static func ==(lhs: SearchBatchWriteParams, rhs: SearchBatchWriteParams) -> Bool {
3131
lhs.requests == rhs.requests
3232
}
3333
}
3434

35-
extension BatchWriteParams: Hashable {
35+
extension SearchBatchWriteParams: Hashable {
3636
public func hash(into hasher: inout Hasher) {
3737
hasher.combine(self.requests.hashValue)
3838
}

Sources/Search/SearchClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ open class SearchClient {
267267
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
268268
open func batch(
269269
indexName: String,
270-
batchWriteParams: BatchWriteParams,
270+
batchWriteParams: SearchBatchWriteParams,
271271
requestOptions: RequestOptions? = nil
272272
) async throws -> BatchResponse {
273273
let response: Response<BatchResponse> = try await batchWithHTTPInfo(
@@ -295,7 +295,7 @@ open class SearchClient {
295295

296296
open func batchWithHTTPInfo(
297297
indexName: String,
298-
batchWriteParams: BatchWriteParams,
298+
batchWriteParams: SearchBatchWriteParams,
299299
requestOptions userRequestOptions: RequestOptions? = nil
300300
) async throws -> Response<BatchResponse> {
301301
guard !indexName.isEmpty else {

0 commit comments

Comments
 (0)