Skip to content

Commit a50ea2c

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 a030487 commit a50ea2c

9 files changed

+201
-2
lines changed

packages/client_recommend/lib/algolia_client_recommend.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export 'src/model/recommend_index_settings.dart';
4949
export 'src/model/recommend_models.dart';
5050
export 'src/model/recommend_rule.dart';
5151
export 'src/model/recommend_search_params.dart';
52+
export 'src/model/recommend_updated_at_response.dart';
5253
export 'src/model/recommendations_hits.dart';
5354
export 'src/model/recommendations_results.dart';
5455
export 'src/model/recommended_for_you.dart';
@@ -72,6 +73,7 @@ export 'src/model/snippet_result_option.dart';
7273
export 'src/model/sort_remaining_by.dart';
7374
export 'src/model/supported_language.dart';
7475
export 'src/model/task_status.dart';
76+
export 'src/model/time_range.dart';
7577
export 'src/model/trending_facet_hit.dart';
7678
export 'src/model/trending_facets.dart';
7779
export 'src/model/trending_facets_model.dart';

packages/client_recommend/lib/src/api/recommend_client.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:algolia_client_recommend/src/model/get_recommendations_params.da
1010
import 'package:algolia_client_recommend/src/model/get_recommendations_response.dart';
1111
import 'package:algolia_client_recommend/src/model/recommend_models.dart';
1212
import 'package:algolia_client_recommend/src/model/recommend_rule.dart';
13+
import 'package:algolia_client_recommend/src/model/recommend_updated_at_response.dart';
1314
import 'package:algolia_client_recommend/src/model/search_recommend_rules_params.dart';
1415
import 'package:algolia_client_recommend/src/model/search_recommend_rules_response.dart';
1516

@@ -49,6 +50,45 @@ final class RecommendClient implements ApiClient {
4950
_retryStrategy.requester.setClientApiKey(apiKey);
5051
}
5152

53+
/// Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the 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).
54+
///
55+
/// Required API Key ACLs:
56+
/// - editSettings
57+
///
58+
/// Parameters:
59+
/// * [indexName] Name of the index on which to perform the operation.
60+
/// * [model] [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
61+
/// * [recommendRule]
62+
/// * [requestOptions] additional request configuration.
63+
Future<RecommendUpdatedAtResponse> batchRecommendRules({
64+
required String indexName,
65+
required RecommendModels model,
66+
List<RecommendRule>? recommendRule,
67+
RequestOptions? requestOptions,
68+
}) async {
69+
assert(
70+
indexName.isNotEmpty,
71+
'Parameter `indexName` is required when calling `batchRecommendRules`.',
72+
);
73+
final request = ApiRequest(
74+
method: RequestMethod.post,
75+
path: r'/1/indexes/{indexName}/{model}/recommend/rules/batch'
76+
.replaceAll(
77+
'{' r'indexName' '}', Uri.encodeComponent(indexName.toString()))
78+
.replaceAll('{' r'model' '}', Uri.encodeComponent(model.toString())),
79+
body: recommendRule,
80+
);
81+
final response = await _retryStrategy.execute(
82+
request: request,
83+
options: requestOptions,
84+
);
85+
return deserialize<RecommendUpdatedAtResponse, RecommendUpdatedAtResponse>(
86+
response,
87+
'RecommendUpdatedAtResponse',
88+
growable: true,
89+
);
90+
}
91+
5292
/// This method allow you to send requests to the Algolia REST API.
5393
///
5494
/// Parameters:

packages/client_recommend/lib/src/deserialize.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import 'package:algolia_client_recommend/src/model/recommend_index_settings.dart
4242
import 'package:algolia_client_recommend/src/model/recommend_models.dart';
4343
import 'package:algolia_client_recommend/src/model/recommend_rule.dart';
4444
import 'package:algolia_client_recommend/src/model/recommend_search_params.dart';
45+
import 'package:algolia_client_recommend/src/model/recommend_updated_at_response.dart';
4546
import 'package:algolia_client_recommend/src/model/recommendations_hits.dart';
4647
import 'package:algolia_client_recommend/src/model/recommendations_results.dart';
4748
import 'package:algolia_client_recommend/src/model/recommended_for_you.dart';
@@ -65,6 +66,7 @@ import 'package:algolia_client_recommend/src/model/snippet_result_option.dart';
6566
import 'package:algolia_client_recommend/src/model/sort_remaining_by.dart';
6667
import 'package:algolia_client_recommend/src/model/supported_language.dart';
6768
import 'package:algolia_client_recommend/src/model/task_status.dart';
69+
import 'package:algolia_client_recommend/src/model/time_range.dart';
6870
import 'package:algolia_client_recommend/src/model/trending_facet_hit.dart';
6971
import 'package:algolia_client_recommend/src/model/trending_facets.dart';
7072
import 'package:algolia_client_recommend/src/model/trending_facets_model.dart';
@@ -208,6 +210,9 @@ ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType,
208210
case 'RecommendSearchParams':
209211
return RecommendSearchParams.fromJson(value as Map<String, dynamic>)
210212
as ReturnType;
213+
case 'RecommendUpdatedAtResponse':
214+
return RecommendUpdatedAtResponse.fromJson(value as Map<String, dynamic>)
215+
as ReturnType;
211216
case 'RecommendationsHits':
212217
return RecommendationsHits.fromJson(value as Map<String, dynamic>)
213218
as ReturnType;
@@ -267,6 +272,8 @@ ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType,
267272
return SupportedLanguage.fromJson(value) as ReturnType;
268273
case 'TaskStatus':
269274
return TaskStatus.fromJson(value) as ReturnType;
275+
case 'TimeRange':
276+
return TimeRange.fromJson(value as Map<String, dynamic>) as ReturnType;
270277
case 'TrendingFacetHit':
271278
return TrendingFacetHit.fromJson(value as Map<String, dynamic>)
272279
as ReturnType;

packages/client_recommend/lib/src/model/recommend_rule.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// 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.
22
// ignore_for_file: unused_element
33
import 'package:algolia_client_recommend/src/model/condition.dart';
4+
import 'package:algolia_client_recommend/src/model/time_range.dart';
45
import 'package:algolia_client_recommend/src/model/rule_metadata.dart';
56
import 'package:algolia_client_recommend/src/model/consequence.dart';
67

@@ -18,6 +19,7 @@ final class RecommendRule {
1819
this.consequence,
1920
this.description,
2021
this.enabled,
22+
this.validity,
2123
});
2224

2325
@JsonKey(name: r'_metadata')
@@ -41,6 +43,10 @@ final class RecommendRule {
4143
@JsonKey(name: r'enabled')
4244
final bool? enabled;
4345

46+
/// Time periods when the rule is active.
47+
@JsonKey(name: r'validity')
48+
final List<TimeRange>? validity;
49+
4450
@override
4551
bool operator ==(Object other) =>
4652
identical(this, other) ||
@@ -50,7 +56,8 @@ final class RecommendRule {
5056
other.condition == condition &&
5157
other.consequence == consequence &&
5258
other.description == description &&
53-
other.enabled == enabled;
59+
other.enabled == enabled &&
60+
other.validity == validity;
5461

5562
@override
5663
int get hashCode =>
@@ -59,7 +66,8 @@ final class RecommendRule {
5966
condition.hashCode +
6067
consequence.hashCode +
6168
description.hashCode +
62-
enabled.hashCode;
69+
enabled.hashCode +
70+
validity.hashCode;
6371

6472
factory RecommendRule.fromJson(Map<String, dynamic> json) =>
6573
_$RecommendRuleFromJson(json);

packages/client_recommend/lib/src/model/recommend_rule.g.dart

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
// ignore_for_file: unused_element
3+
4+
import 'package:json_annotation/json_annotation.dart';
5+
6+
part 'recommend_updated_at_response.g.dart';
7+
8+
@JsonSerializable()
9+
final class RecommendUpdatedAtResponse {
10+
/// Returns a new [RecommendUpdatedAtResponse] instance.
11+
const RecommendUpdatedAtResponse({
12+
required this.taskID,
13+
required this.updatedAt,
14+
});
15+
16+
/// Unique identifier of a task. A successful API response means that a task was added to a queue. It might not run immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and this `taskID`.
17+
@JsonKey(name: r'taskID')
18+
final int taskID;
19+
20+
/// Date and time when the object was updated, in RFC 3339 format.
21+
@JsonKey(name: r'updatedAt')
22+
final String updatedAt;
23+
24+
@override
25+
bool operator ==(Object other) =>
26+
identical(this, other) ||
27+
other is RecommendUpdatedAtResponse &&
28+
other.taskID == taskID &&
29+
other.updatedAt == updatedAt;
30+
31+
@override
32+
int get hashCode => taskID.hashCode + updatedAt.hashCode;
33+
34+
factory RecommendUpdatedAtResponse.fromJson(Map<String, dynamic> json) =>
35+
_$RecommendUpdatedAtResponseFromJson(json);
36+
37+
Map<String, dynamic> toJson() => _$RecommendUpdatedAtResponseToJson(this);
38+
39+
@override
40+
String toString() {
41+
return toJson().toString();
42+
}
43+
}

packages/client_recommend/lib/src/model/recommend_updated_at_response.g.dart

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
// ignore_for_file: unused_element
3+
4+
import 'package:json_annotation/json_annotation.dart';
5+
6+
part 'time_range.g.dart';
7+
8+
@JsonSerializable()
9+
final class TimeRange {
10+
/// Returns a new [TimeRange] instance.
11+
const TimeRange({
12+
required this.from,
13+
required this.until,
14+
});
15+
16+
/// When the rule should start to be active, in Unix epoch time.
17+
@JsonKey(name: r'from')
18+
final int from;
19+
20+
/// When the rule should stop to be active, in Unix epoch time.
21+
@JsonKey(name: r'until')
22+
final int until;
23+
24+
@override
25+
bool operator ==(Object other) =>
26+
identical(this, other) ||
27+
other is TimeRange && other.from == from && other.until == until;
28+
29+
@override
30+
int get hashCode => from.hashCode + until.hashCode;
31+
32+
factory TimeRange.fromJson(Map<String, dynamic> json) =>
33+
_$TimeRangeFromJson(json);
34+
35+
Map<String, dynamic> toJson() => _$TimeRangeToJson(this);
36+
37+
@override
38+
String toString() {
39+
return toJson().toString();
40+
}
41+
}

packages/client_recommend/lib/src/model/time_range.g.dart

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)