Skip to content

Commit

Permalink
feat(specs): add recommend batch rules endpoint (generated)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
4 people committed Sep 27, 2024
1 parent 45e77b3 commit e430751
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 1 deletion.
57 changes: 57 additions & 0 deletions algoliasearch/Clients/RecommendClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@ namespace Algolia.Search.Clients;
/// </summary>
public interface IRecommendClient
{
/// <summary>
/// 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).
/// </summary>
///
/// Required API Key ACLs:
/// - editSettings
/// <param name="indexName">Name of the index on which to perform the operation.</param>
/// <param name="model">[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). </param>
/// <param name="recommendRule"> (optional)</param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>Task of RecommendUpdatedAtResponse</returns>
Task<RecommendUpdatedAtResponse> BatchRecommendRulesAsync(string indexName, RecommendModels model, List<RecommendRule> recommendRule = default, RequestOptions options = null, CancellationToken cancellationToken = default);

/// <summary>
/// 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). (Synchronous version)
/// </summary>
///
/// Required API Key ACLs:
/// - editSettings
/// <param name="indexName">Name of the index on which to perform the operation.</param>
/// <param name="model">[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). </param>
/// <param name="recommendRule"> (optional)</param>
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <exception cref="ArgumentException">Thrown when arguments are not correct</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
/// <returns>RecommendUpdatedAtResponse</returns>
RecommendUpdatedAtResponse BatchRecommendRules(string indexName, RecommendModels model, List<RecommendRule> recommendRule = default, RequestOptions options = null, CancellationToken cancellationToken = default);

/// <summary>
/// This method allow you to send requests to the Algolia REST API.
/// </summary>
Expand Down Expand Up @@ -374,6 +408,29 @@ public void SetClientApiKey(string apiKey)



/// <inheritdoc />
public async Task<RecommendUpdatedAtResponse> BatchRecommendRulesAsync(string indexName, RecommendModels model, List<RecommendRule> recommendRule = default, RequestOptions options = null, CancellationToken cancellationToken = default)
{

if (indexName == null)
throw new ArgumentException("Parameter `indexName` is required when calling `BatchRecommendRules`.");


var requestOptions = new InternalRequestOptions(options);

requestOptions.PathParameters.Add("indexName", QueryStringHelper.ParameterToString(indexName));
requestOptions.PathParameters.Add("model", QueryStringHelper.ParameterToString(model));

requestOptions.Data = recommendRule;
return await _transport.ExecuteRequestAsync<RecommendUpdatedAtResponse>(new HttpMethod("POST"), "/1/indexes/{indexName}/{model}/recommend/rules/batch", requestOptions, cancellationToken).ConfigureAwait(false);
}


/// <inheritdoc />
public RecommendUpdatedAtResponse BatchRecommendRules(string indexName, RecommendModels model, List<RecommendRule> recommendRule = default, RequestOptions options = null, CancellationToken cancellationToken = default) =>
AsyncHelper.RunSync(() => BatchRecommendRulesAsync(indexName, model, recommendRule, options, cancellationToken));


/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
{
Expand Down
15 changes: 14 additions & 1 deletion algoliasearch/Models/Recommend/RecommendRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public RecommendRule()
[JsonPropertyName("enabled")]
public bool? Enabled { get; set; }

/// <summary>
/// Time periods when the rule is active.
/// </summary>
/// <value>Time periods when the rule is active.</value>
[JsonPropertyName("validity")]
public List<TimeRange> Validity { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -76,6 +83,7 @@ public override string ToString()
sb.Append(" Consequence: ").Append(Consequence).Append("\n");
sb.Append(" Description: ").Append(Description).Append("\n");
sb.Append(" Enabled: ").Append(Enabled).Append("\n");
sb.Append(" Validity: ").Append(Validity).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -107,7 +115,8 @@ public override bool Equals(object obj)
(Condition == input.Condition || (Condition != null && Condition.Equals(input.Condition))) &&
(Consequence == input.Consequence || (Consequence != null && Consequence.Equals(input.Consequence))) &&
(Description == input.Description || (Description != null && Description.Equals(input.Description))) &&
(Enabled == input.Enabled || Enabled.Equals(input.Enabled));
(Enabled == input.Enabled || Enabled.Equals(input.Enabled)) &&
(Validity == input.Validity || Validity != null && input.Validity != null && Validity.SequenceEqual(input.Validity));
}

/// <summary>
Expand Down Expand Up @@ -140,6 +149,10 @@ public override int GetHashCode()
hashCode = (hashCode * 59) + Description.GetHashCode();
}
hashCode = (hashCode * 59) + Enabled.GetHashCode();
if (Validity != null)
{
hashCode = (hashCode * 59) + Validity.GetHashCode();
}
return hashCode;
}
}
Expand Down
108 changes: 108 additions & 0 deletions algoliasearch/Models/Recommend/RecommendUpdatedAtResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// 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.
//
using System;
using System.Text;
using System.Linq;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using Algolia.Search.Serializer;
using System.Text.Json;

namespace Algolia.Search.Models.Recommend;

/// <summary>
/// Response, taskID, and update timestamp.
/// </summary>
public partial class RecommendUpdatedAtResponse
{
/// <summary>
/// Initializes a new instance of the RecommendUpdatedAtResponse class.
/// </summary>
[JsonConstructor]
public RecommendUpdatedAtResponse() { }
/// <summary>
/// Initializes a new instance of the RecommendUpdatedAtResponse class.
/// </summary>
/// <param name="taskID">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&#39;s progress with the [&#x60;task&#x60; operation](#tag/Indices/operation/getTask) and this &#x60;taskID&#x60;. (required).</param>
/// <param name="updatedAt">Date and time when the object was updated, in RFC 3339 format. (required).</param>
public RecommendUpdatedAtResponse(long taskID, string updatedAt)
{
TaskID = taskID;
UpdatedAt = updatedAt ?? throw new ArgumentNullException(nameof(updatedAt));
}

/// <summary>
/// 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`.
/// </summary>
/// <value>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`. </value>
[JsonPropertyName("taskID")]
public long TaskID { get; set; }

/// <summary>
/// Date and time when the object was updated, in RFC 3339 format.
/// </summary>
/// <value>Date and time when the object was updated, in RFC 3339 format.</value>
[JsonPropertyName("updatedAt")]
public string UpdatedAt { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class RecommendUpdatedAtResponse {\n");
sb.Append(" TaskID: ").Append(TaskID).Append("\n");
sb.Append(" UpdatedAt: ").Append(UpdatedAt).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
{
return JsonSerializer.Serialize(this, JsonConfig.Options);
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
if (obj is not RecommendUpdatedAtResponse input)
{
return false;
}

return
(TaskID == input.TaskID || TaskID.Equals(input.TaskID)) &&
(UpdatedAt == input.UpdatedAt || (UpdatedAt != null && UpdatedAt.Equals(input.UpdatedAt)));
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
hashCode = (hashCode * 59) + TaskID.GetHashCode();
if (UpdatedAt != null)
{
hashCode = (hashCode * 59) + UpdatedAt.GetHashCode();
}
return hashCode;
}
}

}

105 changes: 105 additions & 0 deletions algoliasearch/Models/Recommend/TimeRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// 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.
//
using System;
using System.Text;
using System.Linq;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using Algolia.Search.Serializer;
using System.Text.Json;

namespace Algolia.Search.Models.Recommend;

/// <summary>
/// TimeRange
/// </summary>
public partial class TimeRange
{
/// <summary>
/// Initializes a new instance of the TimeRange class.
/// </summary>
[JsonConstructor]
public TimeRange() { }
/// <summary>
/// Initializes a new instance of the TimeRange class.
/// </summary>
/// <param name="from">When the rule should start to be active, in Unix epoch time. (required).</param>
/// <param name="until">When the rule should stop to be active, in Unix epoch time. (required).</param>
public TimeRange(int from, int until)
{
From = from;
Until = until;
}

/// <summary>
/// When the rule should start to be active, in Unix epoch time.
/// </summary>
/// <value>When the rule should start to be active, in Unix epoch time.</value>
[JsonPropertyName("from")]
public int From { get; set; }

/// <summary>
/// When the rule should stop to be active, in Unix epoch time.
/// </summary>
/// <value>When the rule should stop to be active, in Unix epoch time.</value>
[JsonPropertyName("until")]
public int Until { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class TimeRange {\n");
sb.Append(" From: ").Append(From).Append("\n");
sb.Append(" Until: ").Append(Until).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
{
return JsonSerializer.Serialize(this, JsonConfig.Options);
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
if (obj is not TimeRange input)
{
return false;
}

return
(From == input.From || From.Equals(input.From)) &&
(Until == input.Until || Until.Equals(input.Until));
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
hashCode = (hashCode * 59) + From.GetHashCode();
hashCode = (hashCode * 59) + Until.GetHashCode();
return hashCode;
}
}

}

0 comments on commit e430751

Please sign in to comment.