Skip to content

Commit a6796e1

Browse files
algolia-botcdhawkemillotp
committed
feat(specs): add estimate path and responses [skip-bc] (generated)
algolia/api-clients-automation#4057 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Christopher Hawke <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 864c71c commit a6796e1

File tree

6 files changed

+749
-10
lines changed

6 files changed

+749
-10
lines changed

lib/algolia/api/abtesting_client.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,50 @@ def delete_ab_test(id, request_options = {})
319319
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Abtesting::ABTestResponse")
320320
end
321321

322+
# Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic.
323+
#
324+
# Required API Key ACLs:
325+
# - analytics
326+
# @param estimate_ab_test_request [EstimateABTestRequest] (required)
327+
# @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)
328+
# @return [Http::Response] the response
329+
def estimate_ab_test_with_http_info(estimate_ab_test_request, request_options = {})
330+
# verify the required parameter 'estimate_ab_test_request' is set
331+
if @api_client.config.client_side_validation && estimate_ab_test_request.nil?
332+
raise ArgumentError, "Parameter `estimate_ab_test_request` is required when calling `estimate_ab_test`."
333+
end
334+
335+
path = "/2/abtests/estimate"
336+
query_params = {}
337+
query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
338+
header_params = {}
339+
header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
340+
341+
post_body = request_options[:debug_body] || @api_client.object_to_http_body(estimate_ab_test_request)
342+
343+
new_options = request_options.merge(
344+
:operation => :"AbtestingClient.estimate_ab_test",
345+
:header_params => header_params,
346+
:query_params => query_params,
347+
:body => post_body,
348+
:use_read_transporter => false
349+
)
350+
351+
@api_client.call_api(:POST, path, new_options)
352+
end
353+
354+
# Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic.
355+
#
356+
# Required API Key ACLs:
357+
# - analytics
358+
# @param estimate_ab_test_request [EstimateABTestRequest] (required)
359+
# @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)
360+
# @return [EstimateABTestResponse]
361+
def estimate_ab_test(estimate_ab_test_request, request_options = {})
362+
response = estimate_ab_test_with_http_info(estimate_ab_test_request, request_options)
363+
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Abtesting::EstimateABTestResponse")
364+
end
365+
322366
# Retrieves the details for an A/B test by its ID.
323367
#
324368
# Required API Key ACLs:

lib/algolia/models/abtesting/effect.rb renamed to lib/algolia/models/abtesting/effect_metric.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module Algolia
77
module Abtesting
8-
class Effect
8+
class EffectMetric
99
ADD_TO_CART_RATE = "addToCartRate".freeze
1010
CLICK_THROUGH_RATE = "clickThroughRate".freeze
1111
CONVERSION_RATE = "conversionRate".freeze
@@ -26,8 +26,8 @@ def self.build_from_hash(value)
2626
# @param [String] The enum value in the form of the string
2727
# @return [String] The enum value
2828
def build_from_hash(value)
29-
return value if Effect.all_vars.include?(value)
30-
raise "Invalid ENUM value #{value} for class #Effect"
29+
return value if EffectMetric.all_vars.include?(value)
30+
raise "Invalid ENUM value #{value} for class #EffectMetric"
3131
end
3232
end
3333
end
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 Abtesting
8+
class EstimateABTestRequest
9+
attr_accessor :configuration
10+
11+
# A/B test variants.
12+
attr_accessor :variants
13+
14+
# Attribute mapping from ruby-style variable name to JSON key.
15+
def self.attribute_map
16+
{
17+
:configuration => :configuration,
18+
:variants => :variants
19+
}
20+
end
21+
22+
# Returns all the JSON keys this model knows about
23+
def self.acceptable_attributes
24+
attribute_map.values
25+
end
26+
27+
# Attribute type mapping.
28+
def self.types_mapping
29+
{
30+
:configuration => :"EstimateConfiguration",
31+
:variants => :"Array<AddABTestsVariant>"
32+
}
33+
end
34+
35+
# List of attributes with nullable: true
36+
def self.openapi_nullable
37+
Set.new(
38+
[]
39+
)
40+
end
41+
42+
# Initializes the object
43+
# @param [Hash] attributes Model attributes in the form of hash
44+
def initialize(attributes = {})
45+
if (!attributes.is_a?(Hash))
46+
raise(
47+
ArgumentError,
48+
"The input argument (attributes) must be a hash in `Algolia::EstimateABTestRequest` initialize method"
49+
)
50+
end
51+
52+
# check to see if the attribute exists and convert string to symbol for hash key
53+
attributes = attributes.each_with_object({}) { |(k, v), h|
54+
if (!self.class.attribute_map.key?(k.to_sym))
55+
raise(
56+
ArgumentError,
57+
"`#{k}` is not a valid attribute in `Algolia::EstimateABTestRequest`. Please check the name to make sure it's valid. List of attributes: " +
58+
self.class.attribute_map.keys.inspect
59+
)
60+
end
61+
62+
h[k.to_sym] = v
63+
}
64+
65+
if attributes.key?(:configuration)
66+
self.configuration = attributes[:configuration]
67+
else
68+
self.configuration = nil
69+
end
70+
71+
if attributes.key?(:variants)
72+
if (value = attributes[:variants]).is_a?(Array)
73+
self.variants = value
74+
end
75+
else
76+
self.variants = 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+
configuration == other.configuration &&
86+
variants == other.variants
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+
[configuration, variants].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::Abtesting.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)