algolia 3.42.3 → 3.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/do-not-edit-this-repository.yml +1 -1
  3. data/.github/workflows/issue.yml +7 -5
  4. data/.github/workflows/release.yml +4 -4
  5. data/CHANGELOG.md +29 -0
  6. data/Gemfile.lock +2 -2
  7. data/lib/algolia/api/abtesting_client.rb +20 -13
  8. data/lib/algolia/api/abtesting_v3_client.rb +2 -1
  9. data/lib/algolia/api/agent_studio_client.rb +2 -1
  10. data/lib/algolia/api/analytics_client.rb +223 -1
  11. data/lib/algolia/api/composition_client.rb +2 -1
  12. data/lib/algolia/api/ingestion_client.rb +2 -1
  13. data/lib/algolia/api/insights_client.rb +2 -1
  14. data/lib/algolia/api/monitoring_client.rb +2 -1
  15. data/lib/algolia/api/personalization_client.rb +2 -1
  16. data/lib/algolia/api/query_suggestions_client.rb +2 -1
  17. data/lib/algolia/api/recommend_client.rb +2 -1
  18. data/lib/algolia/api/search_client.rb +124 -20
  19. data/lib/algolia/api_client.rb +10 -2
  20. data/lib/algolia/chunked_helper_options.rb +1 -0
  21. data/lib/algolia/configuration.rb +10 -2
  22. data/lib/algolia/error.rb +20 -3
  23. data/lib/algolia/models/abtesting-v3/ab_test.rb +7 -19
  24. data/lib/algolia/models/abtesting-v3/decision.rb +219 -0
  25. data/lib/algolia/models/analytics/bin_edge.rb +109 -0
  26. data/lib/algolia/models/analytics/catalog.rb +208 -0
  27. data/lib/algolia/models/analytics/catalog_entry.rb +249 -0
  28. data/lib/algolia/models/analytics/distribution_definition.rb +243 -0
  29. data/lib/algolia/models/analytics/distribution_payload.rb +247 -0
  30. data/lib/algolia/models/analytics/domain_catalog.rb +253 -0
  31. data/lib/algolia/models/analytics/field_reference.rb +219 -0
  32. data/lib/algolia/models/analytics/filter_definition.rb +238 -0
  33. data/lib/algolia/models/analytics/order_definition.rb +230 -0
  34. data/lib/algolia/models/analytics/order_direction.rb +34 -0
  35. data/lib/algolia/models/analytics/parameter_definition.rb +230 -0
  36. data/lib/algolia/models/analytics/parameter_reference.rb +219 -0
  37. data/lib/algolia/models/analytics/parameter_value.rb +111 -0
  38. data/lib/algolia/models/analytics/scalar_payload.rb +247 -0
  39. data/lib/algolia/models/analytics/series.rb +234 -0
  40. data/lib/algolia/models/analytics/series_date.rb +223 -0
  41. data/lib/algolia/models/analytics/table_payload.rb +292 -0
  42. data/lib/algolia/models/analytics/table_response.rb +211 -0
  43. data/lib/algolia/models/analytics/timeseries_payload.rb +279 -0
  44. data/lib/algolia/models/analytics/timeseries_response.rb +213 -0
  45. data/lib/algolia/models/insights/added_to_cart_object_ids_after_search.rb +1 -1
  46. data/lib/algolia/models/insights/clicked_object_ids_after_search.rb +1 -1
  47. data/lib/algolia/models/insights/converted_object_ids_after_search.rb +1 -1
  48. data/lib/algolia/models/insights/events_items.rb +1 -0
  49. data/lib/algolia/models/insights/instantsearch.rb +269 -0
  50. data/lib/algolia/models/insights/instantsearch_event.rb +33 -0
  51. data/lib/algolia/models/search/log.rb +11 -0
  52. data/lib/algolia/transport/http/http_requester.rb +2 -2
  53. data/lib/algolia/transport/request_id.rb +49 -0
  54. data/lib/algolia/transport/transport.rb +79 -8
  55. data/lib/algolia/version.rb +1 -1
  56. data/lib/algolia.rb +1 -0
  57. metadata +26 -2
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 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.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Analytics
10
+ class ScalarPayload
11
+ # Default domain propagated to entries that omit their own.
12
+ attr_accessor :domain
13
+
14
+ # Fields to aggregate.
15
+ attr_accessor :metrics
16
+
17
+ # Filter conditions.
18
+ attr_accessor :filters
19
+
20
+ # Literal values referenced by the query.
21
+ attr_accessor :parameters
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :domain => :domain,
27
+ :metrics => :metrics,
28
+ :filters => :filters,
29
+ :parameters => :parameters
30
+ }
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.types_mapping
35
+ {
36
+ :domain => :"String",
37
+ :metrics => :"Array<FieldReference>",
38
+ :filters => :"Array<FilterDefinition>",
39
+ :parameters => :"Array<ParameterDefinition>"
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new(
46
+ []
47
+ )
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ raise(
55
+ ArgumentError,
56
+ "The input argument (attributes) must be a hash in `Algolia::ScalarPayload` initialize method"
57
+ )
58
+ end
59
+
60
+ # check to see if the attribute exists and convert string to symbol for hash key
61
+ attributes = attributes.each_with_object({}) { |(k, v), h|
62
+ if (!self.class.attribute_map.key?(k.to_sym))
63
+ raise(
64
+ ArgumentError,
65
+ "`#{k}` is not a valid attribute in `Algolia::ScalarPayload`. Please check the name to make sure it's valid. List of attributes: " +
66
+ self.class.attribute_map.keys.inspect
67
+ )
68
+ end
69
+
70
+ h[k.to_sym] = v
71
+ }
72
+
73
+ if attributes.key?(:domain)
74
+ self.domain = attributes[:domain]
75
+ end
76
+
77
+ if attributes.key?(:metrics)
78
+ if (value = attributes[:metrics]).is_a?(Array)
79
+ self.metrics = value
80
+ end
81
+ else
82
+ self.metrics = nil
83
+ end
84
+
85
+ if attributes.key?(:filters)
86
+ if (value = attributes[:filters]).is_a?(Array)
87
+ self.filters = value
88
+ end
89
+ end
90
+
91
+ if attributes.key?(:parameters)
92
+ if (value = attributes[:parameters]).is_a?(Array)
93
+ self.parameters = value
94
+ end
95
+ else
96
+ self.parameters = nil
97
+ end
98
+ end
99
+
100
+ # Checks equality by comparing each attribute.
101
+ # @param [Object] Object to be compared
102
+ def ==(other)
103
+ return true if self.equal?(other)
104
+ self.class == other.class &&
105
+ domain == other.domain &&
106
+ metrics == other.metrics &&
107
+ filters == other.filters &&
108
+ parameters == other.parameters
109
+ end
110
+
111
+ # @see the `==` method
112
+ # @param [Object] Object to be compared
113
+ def eql?(other)
114
+ self == other
115
+ end
116
+
117
+ # Calculates hash code according to all attributes.
118
+ # @return [Integer] Hash code
119
+ def hash
120
+ [domain, metrics, filters, parameters].hash
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def self.build_from_hash(attributes)
127
+ return nil unless attributes.is_a?(Hash)
128
+ attributes = attributes.transform_keys(&:to_sym)
129
+ transformed_hash = {}
130
+ types_mapping.each_pair do |key, type|
131
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
132
+ transformed_hash[key.to_sym] = nil
133
+ elsif type =~ /\AArray<(.*)>/i
134
+ # check to ensure the input is an array given that the attribute
135
+ # is documented as an array but the input is not
136
+ if attributes[attribute_map[key]].is_a?(Array)
137
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
138
+ _deserialize(::Regexp.last_match(1), v)
139
+ }
140
+ end
141
+ elsif !attributes[attribute_map[key]].nil?
142
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
143
+ end
144
+ end
145
+
146
+ new(transformed_hash)
147
+ end
148
+
149
+ # Deserializes the data based on type
150
+ # @param string type Data type
151
+ # @param string value Value to be deserialized
152
+ # @return [Object] Deserialized data
153
+ def self._deserialize(type, value)
154
+ case type.to_sym
155
+ when :Time
156
+ Time.parse(value)
157
+ when :Date
158
+ Date.parse(value)
159
+ when :String
160
+ value.to_s
161
+ when :Integer
162
+ value.to_i
163
+ when :Float
164
+ value.to_f
165
+ when :Boolean
166
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
167
+ true
168
+ else
169
+ false
170
+ end
171
+
172
+ when :Object
173
+ # generic object (usually a Hash), return directly
174
+ value
175
+ when /\AArray<(?<inner_type>.+)>\z/
176
+ inner_type = Regexp.last_match[:inner_type]
177
+ value.map { |v| _deserialize(inner_type, v) }
178
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
179
+ k_type = Regexp.last_match[:k_type]
180
+ v_type = Regexp.last_match[:v_type]
181
+ {}.tap do |hash|
182
+ value.each do |k, v|
183
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
184
+ end
185
+ end
186
+ # model
187
+ else
188
+ # models (e.g. Pet) or oneOf
189
+ klass = Algolia::Analytics.const_get(type)
190
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
191
+ .build_from_hash(value)
192
+ end
193
+ end
194
+
195
+ # Returns the string representation of the object
196
+ # @return [String] String presentation of the object
197
+ def to_s
198
+ to_hash.to_s
199
+ end
200
+
201
+ # to_body is an alias to to_hash (backward compatibility)
202
+ # @return [Hash] Returns the object in the form of hash
203
+ def to_body
204
+ to_hash
205
+ end
206
+
207
+ def to_json(*_args)
208
+ to_hash.to_json
209
+ end
210
+
211
+ # Returns the object in the form of hash
212
+ # @return [Hash] Returns the object in the form of hash
213
+ def to_hash
214
+ hash = {}
215
+ self.class.attribute_map.each_pair do |attr, param|
216
+ value = send(attr)
217
+ if value.nil?
218
+ is_nullable = self.class.openapi_nullable.include?(attr)
219
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
220
+ end
221
+
222
+ hash[param] = _to_hash(value)
223
+ end
224
+
225
+ hash
226
+ end
227
+
228
+ # Outputs non-array value in the form of hash
229
+ # For object, use to_hash. Otherwise, just return the value
230
+ # @param [Object] value Any valid value
231
+ # @return [Hash] Returns the value in the form of hash
232
+ def _to_hash(value)
233
+ if value.is_a?(Array)
234
+ value.map { |v| _to_hash(v) }
235
+ elsif value.is_a?(Hash)
236
+ {}.tap do |hash|
237
+ value.each { |k, v| hash[k] = _to_hash(v) }
238
+ end
239
+ elsif value.respond_to?(:to_hash)
240
+ value.to_hash
241
+ else
242
+ value
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,234 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 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.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Analytics
10
+ class Series
11
+ # The `groupBy` values identifying this series. Absent when the query has no `groupBy`.
12
+ attr_accessor :key
13
+
14
+ # Metric totals over the whole period.
15
+ attr_accessor :totals
16
+
17
+ # Per-day metric breakdown.
18
+ attr_accessor :dates
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :key => :key,
24
+ :totals => :totals,
25
+ :dates => :dates
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.types_mapping
31
+ {
32
+ :key => :"Hash<String, Object>",
33
+ :totals => :"Hash<String, Object>",
34
+ :dates => :"Array<SeriesDate>"
35
+ }
36
+ end
37
+
38
+ # List of attributes with nullable: true
39
+ def self.openapi_nullable
40
+ Set.new(
41
+ []
42
+ )
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ if (!attributes.is_a?(Hash))
49
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Series` initialize method"
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::Series`. 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?(:key)
66
+ if (value = attributes[:key]).is_a?(Hash)
67
+ self.key = value
68
+ end
69
+ end
70
+
71
+ if attributes.key?(:totals)
72
+ if (value = attributes[:totals]).is_a?(Hash)
73
+ self.totals = value
74
+ end
75
+ else
76
+ self.totals = nil
77
+ end
78
+
79
+ if attributes.key?(:dates)
80
+ if (value = attributes[:dates]).is_a?(Array)
81
+ self.dates = value
82
+ end
83
+ else
84
+ self.dates = nil
85
+ end
86
+ end
87
+
88
+ # Checks equality by comparing each attribute.
89
+ # @param [Object] Object to be compared
90
+ def ==(other)
91
+ return true if self.equal?(other)
92
+ self.class == other.class &&
93
+ key == other.key &&
94
+ totals == other.totals &&
95
+ dates == other.dates
96
+ end
97
+
98
+ # @see the `==` method
99
+ # @param [Object] Object to be compared
100
+ def eql?(other)
101
+ self == other
102
+ end
103
+
104
+ # Calculates hash code according to all attributes.
105
+ # @return [Integer] Hash code
106
+ def hash
107
+ [key, totals, dates].hash
108
+ end
109
+
110
+ # Builds the object from hash
111
+ # @param [Hash] attributes Model attributes in the form of hash
112
+ # @return [Object] Returns the model itself
113
+ def self.build_from_hash(attributes)
114
+ return nil unless attributes.is_a?(Hash)
115
+ attributes = attributes.transform_keys(&:to_sym)
116
+ transformed_hash = {}
117
+ types_mapping.each_pair do |key, type|
118
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
119
+ transformed_hash[key.to_sym] = nil
120
+ elsif type =~ /\AArray<(.*)>/i
121
+ # check to ensure the input is an array given that the attribute
122
+ # is documented as an array but the input is not
123
+ if attributes[attribute_map[key]].is_a?(Array)
124
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
125
+ _deserialize(::Regexp.last_match(1), v)
126
+ }
127
+ end
128
+ elsif !attributes[attribute_map[key]].nil?
129
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
130
+ end
131
+ end
132
+
133
+ new(transformed_hash)
134
+ end
135
+
136
+ # Deserializes the data based on type
137
+ # @param string type Data type
138
+ # @param string value Value to be deserialized
139
+ # @return [Object] Deserialized data
140
+ def self._deserialize(type, value)
141
+ case type.to_sym
142
+ when :Time
143
+ Time.parse(value)
144
+ when :Date
145
+ Date.parse(value)
146
+ when :String
147
+ value.to_s
148
+ when :Integer
149
+ value.to_i
150
+ when :Float
151
+ value.to_f
152
+ when :Boolean
153
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
154
+ true
155
+ else
156
+ false
157
+ end
158
+
159
+ when :Object
160
+ # generic object (usually a Hash), return directly
161
+ value
162
+ when /\AArray<(?<inner_type>.+)>\z/
163
+ inner_type = Regexp.last_match[:inner_type]
164
+ value.map { |v| _deserialize(inner_type, v) }
165
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
166
+ k_type = Regexp.last_match[:k_type]
167
+ v_type = Regexp.last_match[:v_type]
168
+ {}.tap do |hash|
169
+ value.each do |k, v|
170
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
171
+ end
172
+ end
173
+ # model
174
+ else
175
+ # models (e.g. Pet) or oneOf
176
+ klass = Algolia::Analytics.const_get(type)
177
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
178
+ .build_from_hash(value)
179
+ end
180
+ end
181
+
182
+ # Returns the string representation of the object
183
+ # @return [String] String presentation of the object
184
+ def to_s
185
+ to_hash.to_s
186
+ end
187
+
188
+ # to_body is an alias to to_hash (backward compatibility)
189
+ # @return [Hash] Returns the object in the form of hash
190
+ def to_body
191
+ to_hash
192
+ end
193
+
194
+ def to_json(*_args)
195
+ to_hash.to_json
196
+ end
197
+
198
+ # Returns the object in the form of hash
199
+ # @return [Hash] Returns the object in the form of hash
200
+ def to_hash
201
+ hash = {}
202
+ self.class.attribute_map.each_pair do |attr, param|
203
+ value = send(attr)
204
+ if value.nil?
205
+ is_nullable = self.class.openapi_nullable.include?(attr)
206
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
207
+ end
208
+
209
+ hash[param] = _to_hash(value)
210
+ end
211
+
212
+ hash
213
+ end
214
+
215
+ # Outputs non-array value in the form of hash
216
+ # For object, use to_hash. Otherwise, just return the value
217
+ # @param [Object] value Any valid value
218
+ # @return [Hash] Returns the value in the form of hash
219
+ def _to_hash(value)
220
+ if value.is_a?(Array)
221
+ value.map { |v| _to_hash(v) }
222
+ elsif value.is_a?(Hash)
223
+ {}.tap do |hash|
224
+ value.each { |k, v| hash[k] = _to_hash(v) }
225
+ end
226
+ elsif value.respond_to?(:to_hash)
227
+ value.to_hash
228
+ else
229
+ value
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 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.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Analytics
10
+ class SeriesDate
11
+ # Day, formatted as YYYY-MM-DD.
12
+ attr_accessor :date
13
+
14
+ # Metric values for the day.
15
+ attr_accessor :metrics
16
+
17
+ # Attribute mapping from ruby-style variable name to JSON key.
18
+ def self.attribute_map
19
+ {
20
+ :date => :date,
21
+ :metrics => :metrics
22
+ }
23
+ end
24
+
25
+ # Attribute type mapping.
26
+ def self.types_mapping
27
+ {
28
+ :date => :"String",
29
+ :metrics => :"Hash<String, Object>"
30
+ }
31
+ end
32
+
33
+ # List of attributes with nullable: true
34
+ def self.openapi_nullable
35
+ Set.new(
36
+ []
37
+ )
38
+ end
39
+
40
+ # Initializes the object
41
+ # @param [Hash] attributes Model attributes in the form of hash
42
+ def initialize(attributes = {})
43
+ if (!attributes.is_a?(Hash))
44
+ raise(
45
+ ArgumentError,
46
+ "The input argument (attributes) must be a hash in `Algolia::SeriesDate` initialize method"
47
+ )
48
+ end
49
+
50
+ # check to see if the attribute exists and convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h|
52
+ if (!self.class.attribute_map.key?(k.to_sym))
53
+ raise(
54
+ ArgumentError,
55
+ "`#{k}` is not a valid attribute in `Algolia::SeriesDate`. Please check the name to make sure it's valid. List of attributes: " +
56
+ self.class.attribute_map.keys.inspect
57
+ )
58
+ end
59
+
60
+ h[k.to_sym] = v
61
+ }
62
+
63
+ if attributes.key?(:date)
64
+ self.date = attributes[:date]
65
+ else
66
+ self.date = nil
67
+ end
68
+
69
+ if attributes.key?(:metrics)
70
+ if (value = attributes[:metrics]).is_a?(Hash)
71
+ self.metrics = value
72
+ end
73
+ else
74
+ self.metrics = nil
75
+ end
76
+ end
77
+
78
+ # Checks equality by comparing each attribute.
79
+ # @param [Object] Object to be compared
80
+ def ==(other)
81
+ return true if self.equal?(other)
82
+ self.class == other.class &&
83
+ date == other.date &&
84
+ metrics == other.metrics
85
+ end
86
+
87
+ # @see the `==` method
88
+ # @param [Object] Object to be compared
89
+ def eql?(other)
90
+ self == other
91
+ end
92
+
93
+ # Calculates hash code according to all attributes.
94
+ # @return [Integer] Hash code
95
+ def hash
96
+ [date, metrics].hash
97
+ end
98
+
99
+ # Builds the object from hash
100
+ # @param [Hash] attributes Model attributes in the form of hash
101
+ # @return [Object] Returns the model itself
102
+ def self.build_from_hash(attributes)
103
+ return nil unless attributes.is_a?(Hash)
104
+ attributes = attributes.transform_keys(&:to_sym)
105
+ transformed_hash = {}
106
+ types_mapping.each_pair do |key, type|
107
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
108
+ transformed_hash[key.to_sym] = nil
109
+ elsif type =~ /\AArray<(.*)>/i
110
+ # check to ensure the input is an array given that the attribute
111
+ # is documented as an array but the input is not
112
+ if attributes[attribute_map[key]].is_a?(Array)
113
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
114
+ _deserialize(::Regexp.last_match(1), v)
115
+ }
116
+ end
117
+ elsif !attributes[attribute_map[key]].nil?
118
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
119
+ end
120
+ end
121
+
122
+ new(transformed_hash)
123
+ end
124
+
125
+ # Deserializes the data based on type
126
+ # @param string type Data type
127
+ # @param string value Value to be deserialized
128
+ # @return [Object] Deserialized data
129
+ def self._deserialize(type, value)
130
+ case type.to_sym
131
+ when :Time
132
+ Time.parse(value)
133
+ when :Date
134
+ Date.parse(value)
135
+ when :String
136
+ value.to_s
137
+ when :Integer
138
+ value.to_i
139
+ when :Float
140
+ value.to_f
141
+ when :Boolean
142
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
143
+ true
144
+ else
145
+ false
146
+ end
147
+
148
+ when :Object
149
+ # generic object (usually a Hash), return directly
150
+ value
151
+ when /\AArray<(?<inner_type>.+)>\z/
152
+ inner_type = Regexp.last_match[:inner_type]
153
+ value.map { |v| _deserialize(inner_type, v) }
154
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
155
+ k_type = Regexp.last_match[:k_type]
156
+ v_type = Regexp.last_match[:v_type]
157
+ {}.tap do |hash|
158
+ value.each do |k, v|
159
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
160
+ end
161
+ end
162
+ # model
163
+ else
164
+ # models (e.g. Pet) or oneOf
165
+ klass = Algolia::Analytics.const_get(type)
166
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
167
+ .build_from_hash(value)
168
+ end
169
+ end
170
+
171
+ # Returns the string representation of the object
172
+ # @return [String] String presentation of the object
173
+ def to_s
174
+ to_hash.to_s
175
+ end
176
+
177
+ # to_body is an alias to to_hash (backward compatibility)
178
+ # @return [Hash] Returns the object in the form of hash
179
+ def to_body
180
+ to_hash
181
+ end
182
+
183
+ def to_json(*_args)
184
+ to_hash.to_json
185
+ end
186
+
187
+ # Returns the object in the form of hash
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_hash
190
+ hash = {}
191
+ self.class.attribute_map.each_pair do |attr, param|
192
+ value = send(attr)
193
+ if value.nil?
194
+ is_nullable = self.class.openapi_nullable.include?(attr)
195
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
196
+ end
197
+
198
+ hash[param] = _to_hash(value)
199
+ end
200
+
201
+ hash
202
+ end
203
+
204
+ # Outputs non-array value in the form of hash
205
+ # For object, use to_hash. Otherwise, just return the value
206
+ # @param [Object] value Any valid value
207
+ # @return [Hash] Returns the value in the form of hash
208
+ def _to_hash(value)
209
+ if value.is_a?(Array)
210
+ value.map { |v| _to_hash(v) }
211
+ elsif value.is_a?(Hash)
212
+ {}.tap do |hash|
213
+ value.each { |k, v| hash[k] = _to_hash(v) }
214
+ end
215
+ elsif value.respond_to?(:to_hash)
216
+ value.to_hash
217
+ else
218
+ value
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end