Skip to content

Commit a0e31e8

Browse files
algolia-botraed667millotpshortcuts
committed
feat(specs): add recommend batch rules endpoint (generated)
algolia/api-clients-automation#3782 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Raed <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent e430548 commit a0e31e8

File tree

6 files changed

+197
-8
lines changed

6 files changed

+197
-8
lines changed

Sources/Recommend/Models/RecommendRule.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ public struct RecommendRule: Codable, JSONEncodable {
1717
public var description: String?
1818
/// Indicates whether to enable the rule. If it isn't enabled, it isn't applied at query time.
1919
public var enabled: Bool?
20+
/// Time periods when the rule is active.
21+
public var validity: [RecommendTimeRange]?
2022

2123
public init(
2224
metadata: RuleMetadata? = nil,
2325
objectID: String? = nil,
2426
condition: RecommendCondition? = nil,
2527
consequence: RecommendConsequence? = nil,
2628
description: String? = nil,
27-
enabled: Bool? = nil
29+
enabled: Bool? = nil,
30+
validity: [RecommendTimeRange]? = nil
2831
) {
2932
self.metadata = metadata
3033
self.objectID = objectID
3134
self.condition = condition
3235
self.consequence = consequence
3336
self.description = description
3437
self.enabled = enabled
38+
self.validity = validity
3539
}
3640

3741
public enum CodingKeys: String, CodingKey, CaseIterable {
@@ -41,6 +45,7 @@ public struct RecommendRule: Codable, JSONEncodable {
4145
case consequence
4246
case description
4347
case enabled
48+
case validity
4449
}
4550

4651
// Encodable protocol methods
@@ -53,6 +58,7 @@ public struct RecommendRule: Codable, JSONEncodable {
5358
try container.encodeIfPresent(self.consequence, forKey: .consequence)
5459
try container.encodeIfPresent(self.description, forKey: .description)
5560
try container.encodeIfPresent(self.enabled, forKey: .enabled)
61+
try container.encodeIfPresent(self.validity, forKey: .validity)
5662
}
5763
}
5864

@@ -63,7 +69,8 @@ extension RecommendRule: Equatable {
6369
lhs.condition == rhs.condition &&
6470
lhs.consequence == rhs.consequence &&
6571
lhs.description == rhs.description &&
66-
lhs.enabled == rhs.enabled
72+
lhs.enabled == rhs.enabled &&
73+
lhs.validity == rhs.validity
6774
}
6875
}
6976

@@ -75,5 +82,6 @@ extension RecommendRule: Hashable {
7582
hasher.combine(self.consequence?.hashValue)
7683
hasher.combine(self.description?.hashValue)
7784
hasher.combine(self.enabled?.hashValue)
85+
hasher.combine(self.validity?.hashValue)
7886
}
7987
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 RecommendTimeRange: Codable, JSONEncodable {
10+
/// When the rule should start to be active, in Unix epoch time.
11+
public var from: Int
12+
/// When the rule should stop to be active, in Unix epoch time.
13+
public var until: Int
14+
15+
public init(from: Int, until: Int) {
16+
self.from = from
17+
self.until = until
18+
}
19+
20+
public enum CodingKeys: String, CodingKey, CaseIterable {
21+
case from
22+
case until
23+
}
24+
25+
// Encodable protocol methods
26+
27+
public func encode(to encoder: Encoder) throws {
28+
var container = encoder.container(keyedBy: CodingKeys.self)
29+
try container.encode(self.from, forKey: .from)
30+
try container.encode(self.until, forKey: .until)
31+
}
32+
}
33+
34+
extension RecommendTimeRange: Equatable {
35+
public static func ==(lhs: RecommendTimeRange, rhs: RecommendTimeRange) -> Bool {
36+
lhs.from == rhs.from &&
37+
lhs.until == rhs.until
38+
}
39+
}
40+
41+
extension RecommendTimeRange: Hashable {
42+
public func hash(into hasher: inout Hasher) {
43+
hasher.combine(self.from.hashValue)
44+
hasher.combine(self.until.hashValue)
45+
}
46+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
/// Response, taskID, and update timestamp.
10+
public struct RecommendUpdatedAtResponse: Codable, JSONEncodable {
11+
/// Unique identifier of a task. A successful API response means that a task was added to a queue. It might not run
12+
/// immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and
13+
/// this `taskID`.
14+
public var taskID: Int64
15+
/// Date and time when the object was updated, in RFC 3339 format.
16+
public var updatedAt: String
17+
18+
public init(taskID: Int64, updatedAt: String) {
19+
self.taskID = taskID
20+
self.updatedAt = updatedAt
21+
}
22+
23+
public enum CodingKeys: String, CodingKey, CaseIterable {
24+
case taskID
25+
case updatedAt
26+
}
27+
28+
// Encodable protocol methods
29+
30+
public func encode(to encoder: Encoder) throws {
31+
var container = encoder.container(keyedBy: CodingKeys.self)
32+
try container.encode(self.taskID, forKey: .taskID)
33+
try container.encode(self.updatedAt, forKey: .updatedAt)
34+
}
35+
}
36+
37+
extension RecommendUpdatedAtResponse: Equatable {
38+
public static func ==(lhs: RecommendUpdatedAtResponse, rhs: RecommendUpdatedAtResponse) -> Bool {
39+
lhs.taskID == rhs.taskID &&
40+
lhs.updatedAt == rhs.updatedAt
41+
}
42+
}
43+
44+
extension RecommendUpdatedAtResponse: Hashable {
45+
public func hash(into hasher: inout Hasher) {
46+
hasher.combine(self.taskID.hashValue)
47+
hasher.combine(self.updatedAt.hashValue)
48+
}
49+
}

Sources/Recommend/RecommendClient.swift

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,92 @@ open class RecommendClient {
3232
self.transporter.setClientApiKey(apiKey: apiKey)
3333
}
3434

35+
/// - parameter indexName: (path) Name of the index on which to perform the operation.
36+
/// - parameter model: (path) [Recommend
37+
/// model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
38+
/// - parameter recommendRule: (body) (optional)
39+
/// - returns: RecommendUpdatedAtResponse
40+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
41+
open func batchRecommendRules(
42+
indexName: String,
43+
model: RecommendModels,
44+
recommendRule: [RecommendRule]? = nil,
45+
requestOptions: RequestOptions? = nil
46+
) async throws -> RecommendUpdatedAtResponse {
47+
let response: Response<RecommendUpdatedAtResponse> = try await batchRecommendRulesWithHTTPInfo(
48+
indexName: indexName,
49+
model: model,
50+
recommendRule: recommendRule,
51+
requestOptions: requestOptions
52+
)
53+
54+
guard let body = response.body else {
55+
throw AlgoliaError.missingData
56+
}
57+
58+
return body
59+
}
60+
61+
// Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a
62+
// Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in
63+
// which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to
64+
// Search Rules, except that the conditions and consequences apply to a [source
65+
// item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the
66+
// following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
67+
// Required API Key ACLs:
68+
// - editSettings
69+
//
70+
// - parameter indexName: (path) Name of the index on which to perform the operation.
71+
//
72+
// - parameter model: (path) [Recommend
73+
// model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
74+
//
75+
// - parameter recommendRule: (body) (optional)
76+
// - returns: RequestBuilder<RecommendUpdatedAtResponse>
77+
78+
open func batchRecommendRulesWithHTTPInfo(
79+
indexName: String,
80+
model: RecommendModels,
81+
recommendRule: [RecommendRule]? = nil,
82+
requestOptions userRequestOptions: RequestOptions? = nil
83+
) async throws -> Response<RecommendUpdatedAtResponse> {
84+
guard !indexName.isEmpty else {
85+
throw AlgoliaError.invalidArgument("indexName", "batchRecommendRules")
86+
}
87+
88+
var resourcePath = "/1/indexes/{indexName}/{model}/recommend/rules/batch"
89+
let indexNamePreEscape = "\(APIHelper.mapValueToPathItem(indexName))"
90+
let indexNamePostEscape = indexNamePreEscape
91+
.addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? ""
92+
resourcePath = resourcePath.replacingOccurrences(
93+
of: "{indexName}",
94+
with: indexNamePostEscape,
95+
options: .literal,
96+
range: nil
97+
)
98+
let modelPreEscape = "\(APIHelper.mapValueToPathItem(model))"
99+
let modelPostEscape = modelPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? ""
100+
resourcePath = resourcePath.replacingOccurrences(
101+
of: "{model}",
102+
with: modelPostEscape,
103+
options: .literal,
104+
range: nil
105+
)
106+
let body = recommendRule
107+
let queryParameters: [String: Any?]? = nil
108+
109+
let nillableHeaders: [String: Any?]? = nil
110+
111+
let headers = APIHelper.rejectNilHeaders(nillableHeaders)
112+
113+
return try await self.transporter.send(
114+
method: "POST",
115+
path: resourcePath,
116+
data: body ?? AnyCodable(),
117+
requestOptions: RequestOptions(headers: headers, queryParameters: queryParameters) + userRequestOptions
118+
)
119+
}
120+
35121
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
36122
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
37123
/// - returns: AnyCodable

Sources/Search/Models/Rule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public struct Rule: Codable, JSONEncodable {
2020
/// Whether the rule is active.
2121
public var enabled: Bool?
2222
/// Time periods when the rule is active.
23-
public var validity: [TimeRange]?
23+
public var validity: [SearchTimeRange]?
2424

2525
public init(
2626
objectID: String,
2727
conditions: [SearchCondition]? = nil,
2828
consequence: SearchConsequence? = nil,
2929
description: String? = nil,
3030
enabled: Bool? = nil,
31-
validity: [TimeRange]? = nil
31+
validity: [SearchTimeRange]? = nil
3232
) {
3333
self.objectID = objectID
3434
self.conditions = conditions

Sources/Search/Models/TimeRange.swift renamed to Sources/Search/Models/SearchTimeRange.swift

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

9-
public struct TimeRange: Codable, JSONEncodable {
9+
public struct SearchTimeRange: Codable, JSONEncodable {
1010
/// When the rule should start to be active, in Unix epoch time.
1111
public var from: Int
1212
/// When the rule should stop to be active, in Unix epoch time.
@@ -31,14 +31,14 @@ public struct TimeRange: Codable, JSONEncodable {
3131
}
3232
}
3333

34-
extension TimeRange: Equatable {
35-
public static func ==(lhs: TimeRange, rhs: TimeRange) -> Bool {
34+
extension SearchTimeRange: Equatable {
35+
public static func ==(lhs: SearchTimeRange, rhs: SearchTimeRange) -> Bool {
3636
lhs.from == rhs.from &&
3737
lhs.until == rhs.until
3838
}
3939
}
4040

41-
extension TimeRange: Hashable {
41+
extension SearchTimeRange: Hashable {
4242
public func hash(into hasher: inout Hasher) {
4343
hasher.combine(self.from.hashValue)
4444
hasher.combine(self.until.hashValue)

0 commit comments

Comments
 (0)