Skip to content

Commit 793d6c7

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 a060cef commit 793d6c7

File tree

4 files changed

+526
-4
lines changed

4 files changed

+526
-4
lines changed

lib/algolia/api/recommend_client.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,63 @@ def set_client_api_key(api_key)
4040
@api_client.set_client_api_key(api_key)
4141
end
4242

43+
# Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same &#x60;objectID&#x60; already exists. You may also specify &#x60;true&#x60; for &#x60;clearExistingRules&#x60;, 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 &#x60;pattern&#x60; and &#x60;anchoring&#x60; are unavailable. - Condition &#x60;filters&#x60; triggers if the source item matches the specified filters. - Condition &#x60;filters&#x60; accepts numeric filters. - Consequence &#x60;params&#x60; only covers filtering parameters. - Consequence &#x60;automaticFacetFilters&#x60; doesn&#39;t require a facet value placeholder (it tries to match the data source item&#39;s attributes instead).
44+
#
45+
# Required API Key ACLs:
46+
# - editSettings
47+
# @param index_name [String] Name of the index on which to perform the operation. (required)
48+
# @param model [RecommendModels] [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
49+
# @param recommend_rule [Array<RecommendRule>]
50+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
51+
# @return [Http::Response] the response
52+
def batch_recommend_rules_with_http_info(index_name, model, recommend_rule = nil, request_options = {})
53+
# verify the required parameter 'index_name' is set
54+
if @api_client.config.client_side_validation && index_name.nil?
55+
raise ArgumentError, "Parameter `index_name` is required when calling `batch_recommend_rules`."
56+
end
57+
# verify the required parameter 'model' is set
58+
if @api_client.config.client_side_validation && model.nil?
59+
raise ArgumentError, "Parameter `model` is required when calling `batch_recommend_rules`."
60+
end
61+
62+
path = "/1/indexes/{indexName}/{model}/recommend/rules/batch"
63+
.sub("{" + "indexName" + "}", Transport.encode_uri(index_name.to_s))
64+
.sub("{" + "model" + "}", Transport.encode_uri(model.to_s))
65+
query_params = {}
66+
query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
67+
header_params = {}
68+
header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
69+
70+
post_body = request_options[:debug_body] || @api_client.object_to_http_body(recommend_rule)
71+
72+
new_options = request_options.merge(
73+
:operation => :"RecommendClient.batch_recommend_rules",
74+
:header_params => header_params,
75+
:query_params => query_params,
76+
:body => post_body,
77+
:use_read_transporter => false
78+
)
79+
80+
@api_client.call_api(:POST, path, new_options)
81+
end
82+
83+
# 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).
84+
#
85+
# Required API Key ACLs:
86+
# - editSettings
87+
# @param index_name [String] Name of the index on which to perform the operation. (required)
88+
# @param model [RecommendModels] [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
89+
# @param recommend_rule [Array<RecommendRule>]
90+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
91+
# @return [RecommendUpdatedAtResponse]
92+
def batch_recommend_rules(index_name, model, recommend_rule = nil, request_options = {})
93+
response = batch_recommend_rules_with_http_info(index_name, model, recommend_rule, request_options)
94+
@api_client.deserialize(
95+
response.body,
96+
request_options[:debug_return_type] || "Recommend::RecommendUpdatedAtResponse"
97+
)
98+
end
99+
43100
# This method allow you to send requests to the Algolia REST API.
44101

45102
# @param path [String] Path of the endpoint, anything after \&quot;/1\&quot; must be specified. (required)

lib/algolia/models/recommend/recommend_rule.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class RecommendRule
2222
# Indicates whether to enable the rule. If it isn't enabled, it isn't applied at query time.
2323
attr_accessor :enabled
2424

25+
# Time periods when the rule is active.
26+
attr_accessor :validity
27+
2528
# Attribute mapping from ruby-style variable name to JSON key.
2629
def self.attribute_map
2730
{
@@ -30,7 +33,8 @@ def self.attribute_map
3033
:condition => :condition,
3134
:consequence => :consequence,
3235
:description => :description,
33-
:enabled => :enabled
36+
:enabled => :enabled,
37+
:validity => :validity
3438
}
3539
end
3640

@@ -47,7 +51,8 @@ def self.types_mapping
4751
:condition => :"Condition",
4852
:consequence => :"Consequence",
4953
:description => :"String",
50-
:enabled => :"Boolean"
54+
:enabled => :"Boolean",
55+
:validity => :"Array<TimeRange>"
5156
}
5257
end
5358

@@ -104,6 +109,12 @@ def initialize(attributes = {})
104109
if attributes.key?(:enabled)
105110
self.enabled = attributes[:enabled]
106111
end
112+
113+
if attributes.key?(:validity)
114+
if (value = attributes[:validity]).is_a?(Array)
115+
self.validity = value
116+
end
117+
end
107118
end
108119

109120
# Checks equality by comparing each attribute.
@@ -116,7 +127,8 @@ def ==(other)
116127
condition == other.condition &&
117128
consequence == other.consequence &&
118129
description == other.description &&
119-
enabled == other.enabled
130+
enabled == other.enabled &&
131+
validity == other.validity
120132
end
121133

122134
# @see the `==` method
@@ -128,7 +140,7 @@ def eql?(other)
128140
# Calculates hash code according to all attributes.
129141
# @return [Integer] Hash code
130142
def hash
131-
[_metadata, object_id, condition, consequence, description, enabled].hash
143+
[_metadata, object_id, condition, consequence, description, enabled, validity].hash
132144
end
133145

134146
# Builds the object from hash
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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+
3+
require "date"
4+
require "time"
5+
6+
module Algolia
7+
module Recommend
8+
# Response, taskID, and update timestamp.
9+
class RecommendUpdatedAtResponse
10+
# 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`.
11+
attr_accessor :task_id
12+
13+
# Date and time when the object was updated, in RFC 3339 format.
14+
attr_accessor :updated_at
15+
16+
# Attribute mapping from ruby-style variable name to JSON key.
17+
def self.attribute_map
18+
{
19+
:task_id => :taskID,
20+
:updated_at => :updatedAt
21+
}
22+
end
23+
24+
# Returns all the JSON keys this model knows about
25+
def self.acceptable_attributes
26+
attribute_map.values
27+
end
28+
29+
# Attribute type mapping.
30+
def self.types_mapping
31+
{
32+
:task_id => :"Integer",
33+
:updated_at => :"String"
34+
}
35+
end
36+
37+
# List of attributes with nullable: true
38+
def self.openapi_nullable
39+
Set.new(
40+
[]
41+
)
42+
end
43+
44+
# Initializes the object
45+
# @param [Hash] attributes Model attributes in the form of hash
46+
def initialize(attributes = {})
47+
if (!attributes.is_a?(Hash))
48+
raise(
49+
ArgumentError,
50+
"The input argument (attributes) must be a hash in `Algolia::RecommendUpdatedAtResponse` initialize method"
51+
)
52+
end
53+
54+
# check to see if the attribute exists and convert string to symbol for hash key
55+
attributes = attributes.each_with_object({}) { |(k, v), h|
56+
if (!self.class.attribute_map.key?(k.to_sym))
57+
raise(
58+
ArgumentError,
59+
"`#{k}` is not a valid attribute in `Algolia::RecommendUpdatedAtResponse`. Please check the name to make sure it's valid. List of attributes: " +
60+
self.class.attribute_map.keys.inspect
61+
)
62+
end
63+
64+
h[k.to_sym] = v
65+
}
66+
67+
if attributes.key?(:task_id)
68+
self.task_id = attributes[:task_id]
69+
else
70+
self.task_id = nil
71+
end
72+
73+
if attributes.key?(:updated_at)
74+
self.updated_at = attributes[:updated_at]
75+
else
76+
self.updated_at = nil
77+
end
78+
end
79+
80+
# Checks equality by comparing each attribute.
81+
# @param [Object] Object to be compared
82+
def ==(other)
83+
return true if self.equal?(other)
84+
self.class == other.class &&
85+
task_id == other.task_id &&
86+
updated_at == other.updated_at
87+
end
88+
89+
# @see the `==` method
90+
# @param [Object] Object to be compared
91+
def eql?(other)
92+
self == other
93+
end
94+
95+
# Calculates hash code according to all attributes.
96+
# @return [Integer] Hash code
97+
def hash
98+
[task_id, updated_at].hash
99+
end
100+
101+
# Builds the object from hash
102+
# @param [Hash] attributes Model attributes in the form of hash
103+
# @return [Object] Returns the model itself
104+
def self.build_from_hash(attributes)
105+
return nil unless attributes.is_a?(Hash)
106+
attributes = attributes.transform_keys(&:to_sym)
107+
transformed_hash = {}
108+
types_mapping.each_pair do |key, type|
109+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
110+
transformed_hash[key.to_sym] = nil
111+
elsif type =~ /\AArray<(.*)>/i
112+
# check to ensure the input is an array given that the attribute
113+
# is documented as an array but the input is not
114+
if attributes[attribute_map[key]].is_a?(Array)
115+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
116+
_deserialize(::Regexp.last_match(1), v)
117+
}
118+
end
119+
elsif !attributes[attribute_map[key]].nil?
120+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
121+
end
122+
end
123+
124+
new(transformed_hash)
125+
end
126+
127+
# Deserializes the data based on type
128+
# @param string type Data type
129+
# @param string value Value to be deserialized
130+
# @return [Object] Deserialized data
131+
def self._deserialize(type, value)
132+
case type.to_sym
133+
when :Time
134+
Time.parse(value)
135+
when :Date
136+
Date.parse(value)
137+
when :String
138+
value.to_s
139+
when :Integer
140+
value.to_i
141+
when :Float
142+
value.to_f
143+
when :Boolean
144+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
145+
true
146+
else
147+
false
148+
end
149+
150+
when :Object
151+
# generic object (usually a Hash), return directly
152+
value
153+
when /\AArray<(?<inner_type>.+)>\z/
154+
inner_type = Regexp.last_match[:inner_type]
155+
value.map { |v| _deserialize(inner_type, v) }
156+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
157+
k_type = Regexp.last_match[:k_type]
158+
v_type = Regexp.last_match[:v_type]
159+
{}.tap do |hash|
160+
value.each do |k, v|
161+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
162+
end
163+
end
164+
# model
165+
else
166+
# models (e.g. Pet) or oneOf
167+
klass = Algolia::Recommend.const_get(type)
168+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
169+
.build_from_hash(value)
170+
end
171+
end
172+
173+
# Returns the string representation of the object
174+
# @return [String] String presentation of the object
175+
def to_s
176+
to_hash.to_s
177+
end
178+
179+
# to_body is an alias to to_hash (backward compatibility)
180+
# @return [Hash] Returns the object in the form of hash
181+
def to_body
182+
to_hash
183+
end
184+
185+
def to_json(*_args)
186+
to_hash.to_json
187+
end
188+
189+
# Returns the object in the form of hash
190+
# @return [Hash] Returns the object in the form of hash
191+
def to_hash
192+
hash = {}
193+
self.class.attribute_map.each_pair do |attr, param|
194+
value = send(attr)
195+
if value.nil?
196+
is_nullable = self.class.openapi_nullable.include?(attr)
197+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
198+
end
199+
200+
hash[param] = _to_hash(value)
201+
end
202+
203+
hash
204+
end
205+
206+
# Outputs non-array value in the form of hash
207+
# For object, use to_hash. Otherwise, just return the value
208+
# @param [Object] value Any valid value
209+
# @return [Hash] Returns the value in the form of hash
210+
def _to_hash(value)
211+
if value.is_a?(Array)
212+
value.compact.map { |v| _to_hash(v) }
213+
elsif value.is_a?(Hash)
214+
{}.tap do |hash|
215+
value.each { |k, v| hash[k] = _to_hash(v) }
216+
end
217+
elsif value.respond_to?(:to_hash)
218+
value.to_hash
219+
else
220+
value
221+
end
222+
end
223+
224+
end
225+
226+
end
227+
end

0 commit comments

Comments
 (0)