algolia 3.0.0.alpha.16 → 3.0.0.alpha.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.openapi-generator/FILES +10 -167
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile.lock +1 -1
  5. data/lib/algolia/api/analytics_client.rb +76 -76
  6. data/lib/algolia/api/recommend_client.rb +22 -22
  7. data/lib/algolia/api/search_client.rb +8 -8
  8. data/lib/algolia/api/usage_client.rb +329 -0
  9. data/lib/algolia/models/analytics/get_status_response.rb +1 -1
  10. data/lib/algolia/models/ingestion/auth_algolia_insights.rb +212 -0
  11. data/lib/algolia/models/{recommend/consequence_query_object.rb → ingestion/auth_algolia_insights_partial.rb} +21 -24
  12. data/lib/algolia/models/ingestion/auth_input.rb +1 -0
  13. data/lib/algolia/models/ingestion/auth_input_partial.rb +1 -0
  14. data/lib/algolia/models/ingestion/authentication_type.rb +2 -1
  15. data/lib/algolia/models/insights/added_to_cart_object_ids.rb +1 -1
  16. data/lib/algolia/models/insights/added_to_cart_object_ids_after_search.rb +1 -1
  17. data/lib/algolia/models/insights/clicked_filters.rb +1 -1
  18. data/lib/algolia/models/insights/clicked_object_ids.rb +1 -1
  19. data/lib/algolia/models/insights/clicked_object_ids_after_search.rb +1 -1
  20. data/lib/algolia/models/insights/converted_filters.rb +1 -1
  21. data/lib/algolia/models/insights/converted_object_ids.rb +1 -1
  22. data/lib/algolia/models/insights/converted_object_ids_after_search.rb +1 -1
  23. data/lib/algolia/models/insights/purchased_object_ids.rb +1 -1
  24. data/lib/algolia/models/insights/purchased_object_ids_after_search.rb +1 -1
  25. data/lib/algolia/models/insights/viewed_filters.rb +1 -1
  26. data/lib/algolia/models/insights/viewed_object_ids.rb +1 -1
  27. data/lib/algolia/models/monitoring/incidents_inner.rb +1 -1
  28. data/lib/algolia/models/monitoring/probes_metric.rb +1 -1
  29. data/lib/algolia/models/monitoring/time_inner.rb +1 -1
  30. data/lib/algolia/models/query-suggestions/get_config_status200_response.rb +2 -2
  31. data/lib/algolia/models/query-suggestions/get_log_file200_response.rb +1 -1
  32. data/lib/algolia/models/recommend/auto_facet_filter.rb +208 -0
  33. data/lib/algolia/models/recommend/base_recommend_request.rb +36 -7
  34. data/lib/algolia/models/recommend/base_search_params.rb +1 -1
  35. data/lib/algolia/models/recommend/base_search_params_without_query.rb +1 -1
  36. data/lib/algolia/models/recommend/bought_together_query.rb +319 -0
  37. data/lib/algolia/models/recommend/condition.rb +12 -62
  38. data/lib/algolia/models/recommend/consequence.rb +32 -54
  39. data/lib/algolia/models/recommend/deleted_at_response.rb +1 -1
  40. data/lib/algolia/models/recommend/{recommended_for_you_query_parameters.rb → fallback_params.rb} +9 -12
  41. data/lib/algolia/models/recommend/{edit_type.rb → fbt_model.rb} +5 -6
  42. data/lib/algolia/models/recommend/{base_trending_facets_query.rb → frequently_bought_together.rb} +20 -18
  43. data/lib/algolia/models/recommend/get_recommendations_params.rb +2 -2
  44. data/lib/algolia/models/recommend/{consequence_hide.rb → hide_consequence_object.rb} +4 -6
  45. data/lib/algolia/models/recommend/index_settings_as_search_params.rb +5 -5
  46. data/lib/algolia/models/recommend/{base_recommendations_query.rb → looking_similar.rb} +6 -15
  47. data/lib/algolia/models/recommend/{anchoring.rb → looking_similar_model.rb} +5 -8
  48. data/lib/algolia/models/recommend/looking_similar_query.rb +328 -0
  49. data/lib/algolia/models/recommend/{params.rb → params_consequence.rb} +26 -28
  50. data/lib/algolia/models/recommend/{promote_object_id.rb → promote_consequence_object.rb} +19 -9
  51. data/lib/algolia/models/recommend/{rule_response.rb → recommend_rule.rb} +13 -18
  52. data/lib/algolia/models/recommend/{rule_response_metadata.rb → recommend_rule_metadata.rb} +5 -4
  53. data/lib/algolia/models/recommend/recommendations_hits.rb +4 -24
  54. data/lib/algolia/models/recommend/recommendations_request.rb +3 -1
  55. data/lib/algolia/models/recommend/recommendations_results.rb +4 -24
  56. data/lib/algolia/models/recommend/{base_recommended_for_you_query.rb → recommended_for_you.rb} +5 -14
  57. data/lib/algolia/models/recommend/recommended_for_you_query.rb +35 -15
  58. data/lib/algolia/models/recommend/{recommendation_models.rb → related_model.rb} +4 -5
  59. data/lib/algolia/models/recommend/{edit.rb → related_products.rb} +27 -24
  60. data/lib/algolia/models/recommend/{recommendations_query.rb → related_query.rb} +39 -19
  61. data/lib/algolia/models/recommend/{consequence_params.rb → search_params.rb} +25 -44
  62. data/lib/algolia/models/recommend/search_params_object.rb +6 -6
  63. data/lib/algolia/models/recommend/search_recommend_rules_params.rb +58 -10
  64. data/lib/algolia/models/recommend/search_recommend_rules_response.rb +2 -2
  65. data/lib/algolia/models/recommend/trending_facet_hit.rb +2 -2
  66. data/lib/algolia/models/recommend/trending_facets.rb +243 -0
  67. data/lib/algolia/models/recommend/trending_facets_query.rb +50 -10
  68. data/lib/algolia/models/recommend/{base_trending_items_query.rb → trending_items.rb} +12 -15
  69. data/lib/algolia/models/recommend/trending_items_query.rb +42 -16
  70. data/lib/algolia/models/search/add_api_key_response.rb +1 -1
  71. data/lib/algolia/models/search/base_get_api_key_response.rb +1 -1
  72. data/lib/algolia/models/search/base_index_settings.rb +4 -4
  73. data/lib/algolia/models/search/base_search_params.rb +1 -1
  74. data/lib/algolia/models/search/base_search_params_without_query.rb +1 -1
  75. data/lib/algolia/models/search/browse_params_object.rb +6 -6
  76. data/lib/algolia/models/search/consequence_params.rb +6 -6
  77. data/lib/algolia/models/search/created_at_response.rb +1 -1
  78. data/lib/algolia/models/search/delete_api_key_response.rb +1 -1
  79. data/lib/algolia/models/search/delete_by_params.rb +1 -1
  80. data/lib/algolia/models/search/delete_source_response.rb +1 -1
  81. data/lib/algolia/models/search/deleted_at_response.rb +1 -1
  82. data/lib/algolia/models/search/fetched_index.rb +1 -1
  83. data/lib/algolia/models/search/get_api_key_response.rb +1 -1
  84. data/lib/algolia/models/search/index_settings.rb +9 -9
  85. data/lib/algolia/models/search/index_settings_as_search_params.rb +5 -5
  86. data/lib/algolia/models/search/log.rb +1 -1
  87. data/lib/algolia/models/search/remove_user_id_response.rb +1 -1
  88. data/lib/algolia/models/search/replace_source_response.rb +1 -1
  89. data/lib/algolia/models/search/save_object_response.rb +1 -1
  90. data/lib/algolia/models/search/save_synonym_response.rb +1 -1
  91. data/lib/algolia/models/search/search_for_facets.rb +6 -6
  92. data/lib/algolia/models/search/search_for_hits.rb +6 -6
  93. data/lib/algolia/models/search/search_params_object.rb +6 -6
  94. data/lib/algolia/models/search/search_user_ids_response.rb +1 -1
  95. data/lib/algolia/models/search/secured_api_key_restrictions.rb +1 -1
  96. data/lib/algolia/models/search/update_api_key_response.rb +1 -1
  97. data/lib/algolia/models/search/updated_at_response.rb +1 -1
  98. data/lib/algolia/models/search/updated_at_with_object_id_response.rb +1 -1
  99. data/lib/algolia/models/search/updated_rule_response.rb +1 -1
  100. data/lib/algolia/models/search/user_hit.rb +1 -1
  101. data/lib/algolia/models/search/user_id.rb +1 -1
  102. data/lib/algolia/models/usage/error_base.rb +205 -0
  103. data/lib/algolia/models/usage/get_usage200_response.rb +198 -0
  104. data/lib/algolia/models/usage/get_usage200_response_statistics_inner.rb +206 -0
  105. data/lib/algolia/models/{recommend/base_recommended_for_you_query_parameters.rb → usage/get_usage400_response.rb} +13 -14
  106. data/lib/algolia/models/usage/get_usage400_response_error.rb +216 -0
  107. data/lib/algolia/models/usage/get_usage400_response_error_errors_inner.rb +225 -0
  108. data/lib/algolia/models/usage/granularity.rb +33 -0
  109. data/lib/algolia/models/usage/statistic.rb +116 -0
  110. data/lib/algolia/models/{recommend/promote.rb → usage/statistic_value.rb} +5 -5
  111. data/lib/algolia/version.rb +1 -1
  112. metadata +34 -25
  113. data/lib/algolia/models/recommend/automatic_facet_filter.rb +0 -220
  114. data/lib/algolia/models/recommend/automatic_facet_filters.rb +0 -97
  115. data/lib/algolia/models/recommend/consequence_query.rb +0 -97
  116. data/lib/algolia/models/recommend/promote_object_ids.rb +0 -228
@@ -0,0 +1,206 @@
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 Usage
8
+ class GetUsage200ResponseStatisticsInner
9
+ # Timestamp, measured in milliseconds since the Unix epoch.
10
+ attr_accessor :t
11
+
12
+ attr_accessor :v
13
+
14
+ # Attribute mapping from ruby-style variable name to JSON key.
15
+ def self.attribute_map
16
+ {
17
+ :t => :t,
18
+ :v => :v
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
+ :t => :Integer,
31
+ :v => :StatisticValue
32
+ }
33
+ end
34
+
35
+ # List of attributes with nullable: true
36
+ def self.openapi_nullable
37
+ Set.new([])
38
+ end
39
+
40
+ # Initializes the object
41
+ # @param [Hash] attributes Model attributes in the form of hash
42
+ def initialize(attributes = {})
43
+ unless attributes.is_a?(Hash)
44
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::GetUsage200ResponseStatisticsInner` initialize method"
45
+ end
46
+
47
+ # check to see if the attribute exists and convert string to symbol for hash key
48
+ attributes = attributes.each_with_object({}) do |(k, v), h|
49
+ unless self.class.attribute_map.key?(k.to_sym)
50
+ raise ArgumentError,
51
+ "`#{k}` is not a valid attribute in `Algolia::GetUsage200ResponseStatisticsInner`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
52
+ end
53
+
54
+ h[k.to_sym] = v
55
+ end
56
+
57
+ if attributes.key?(:t)
58
+ self.t = attributes[:t]
59
+ end
60
+
61
+ if attributes.key?(:v)
62
+ self.v = attributes[:v]
63
+ end
64
+ end
65
+
66
+ # Checks equality by comparing each attribute.
67
+ # @param [Object] Object to be compared
68
+ def ==(other)
69
+ return true if equal?(other)
70
+
71
+ self.class == other.class &&
72
+ t == other.t &&
73
+ v == other.v
74
+ end
75
+
76
+ # @see the `==` method
77
+ # @param [Object] Object to be compared
78
+ def eql?(other)
79
+ self == other
80
+ end
81
+
82
+ # Calculates hash code according to all attributes.
83
+ # @return [Integer] Hash code
84
+ def hash
85
+ [t, v].hash
86
+ end
87
+
88
+ # Builds the object from hash
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ # @return [Object] Returns the model itself
91
+ def self.build_from_hash(attributes)
92
+ return nil unless attributes.is_a?(Hash)
93
+
94
+ attributes = attributes.transform_keys(&:to_sym)
95
+ transformed_hash = {}
96
+ types_mapping.each_pair do |key, type|
97
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
98
+ transformed_hash[key.to_sym] = nil
99
+ elsif type =~ /\AArray<(.*)>/i
100
+ # check to ensure the input is an array given that the attribute
101
+ # is documented as an array but the input is not
102
+ if attributes[attribute_map[key]].is_a?(Array)
103
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
104
+ end
105
+ elsif !attributes[attribute_map[key]].nil?
106
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
107
+ end
108
+ end
109
+ new(transformed_hash)
110
+ end
111
+
112
+ # Deserializes the data based on type
113
+ # @param string type Data type
114
+ # @param string value Value to be deserialized
115
+ # @return [Object] Deserialized data
116
+ def self._deserialize(type, value)
117
+ case type.to_sym
118
+ when :Time
119
+ Time.parse(value)
120
+ when :Date
121
+ Date.parse(value)
122
+ when :String
123
+ value.to_s
124
+ when :Integer
125
+ value.to_i
126
+ when :Float
127
+ value.to_f
128
+ when :Boolean
129
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
130
+ true
131
+ else
132
+ false
133
+ end
134
+ when :Object
135
+ # generic object (usually a Hash), return directly
136
+ value
137
+ when /\AArray<(?<inner_type>.+)>\z/
138
+ inner_type = Regexp.last_match[:inner_type]
139
+ value.map { |v| _deserialize(inner_type, v) }
140
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
141
+ k_type = Regexp.last_match[:k_type]
142
+ v_type = Regexp.last_match[:v_type]
143
+ {}.tap do |hash|
144
+ value.each do |k, v|
145
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
146
+ end
147
+ end
148
+ else # model
149
+ # models (e.g. Pet) or oneOf
150
+ klass = Algolia::Usage.const_get(type)
151
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
152
+ end
153
+ end
154
+
155
+ # Returns the string representation of the object
156
+ # @return [String] String presentation of the object
157
+ def to_s
158
+ to_hash.to_s
159
+ end
160
+
161
+ # to_body is an alias to to_hash (backward compatibility)
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_body
164
+ to_hash
165
+ end
166
+
167
+ def to_json(*_args)
168
+ to_hash.to_json
169
+ end
170
+
171
+ # Returns the object in the form of hash
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_hash
174
+ hash = {}
175
+ self.class.attribute_map.each_pair do |attr, param|
176
+ value = send(attr)
177
+ if value.nil?
178
+ is_nullable = self.class.openapi_nullable.include?(attr)
179
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
180
+ end
181
+
182
+ hash[param] = _to_hash(value)
183
+ end
184
+ hash
185
+ end
186
+
187
+ # Outputs non-array value in the form of hash
188
+ # For object, use to_hash. Otherwise, just return the value
189
+ # @param [Object] value Any valid value
190
+ # @return [Hash] Returns the value in the form of hash
191
+ def _to_hash(value)
192
+ if value.is_a?(Array)
193
+ value.compact.map { |v| _to_hash(v) }
194
+ elsif value.is_a?(Hash)
195
+ {}.tap do |hash|
196
+ value.each { |k, v| hash[k] = _to_hash(v) }
197
+ end
198
+ elsif value.respond_to? :to_hash
199
+ value.to_hash
200
+ else
201
+ value
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -4,15 +4,14 @@ require 'date'
4
4
  require 'time'
5
5
 
6
6
  module Algolia
7
- module Recommend
8
- class BaseRecommendedForYouQueryParameters
9
- # Unique pseudonymous or anonymous user identifier. This helps with analytics and click and conversion events. For more information, see [user token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken/).
10
- attr_accessor :user_token
7
+ module Usage
8
+ class GetUsage400Response
9
+ attr_accessor :error
11
10
 
12
11
  # Attribute mapping from ruby-style variable name to JSON key.
13
12
  def self.attribute_map
14
13
  {
15
- :user_token => :userToken
14
+ :error => :error
16
15
  }
17
16
  end
18
17
 
@@ -24,7 +23,7 @@ module Algolia
24
23
  # Attribute type mapping.
25
24
  def self.types_mapping
26
25
  {
27
- :user_token => :String
26
+ :error => :GetUsage400ResponseError
28
27
  }
29
28
  end
30
29
 
@@ -37,23 +36,23 @@ module Algolia
37
36
  # @param [Hash] attributes Model attributes in the form of hash
38
37
  def initialize(attributes = {})
39
38
  unless attributes.is_a?(Hash)
40
- raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::BaseRecommendedForYouQueryParameters` initialize method"
39
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::GetUsage400Response` initialize method"
41
40
  end
42
41
 
43
42
  # check to see if the attribute exists and convert string to symbol for hash key
44
43
  attributes = attributes.each_with_object({}) do |(k, v), h|
45
44
  unless self.class.attribute_map.key?(k.to_sym)
46
45
  raise ArgumentError,
47
- "`#{k}` is not a valid attribute in `Algolia::BaseRecommendedForYouQueryParameters`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
46
+ "`#{k}` is not a valid attribute in `Algolia::GetUsage400Response`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
48
47
  end
49
48
 
50
49
  h[k.to_sym] = v
51
50
  end
52
51
 
53
- if attributes.key?(:user_token)
54
- self.user_token = attributes[:user_token]
52
+ if attributes.key?(:error)
53
+ self.error = attributes[:error]
55
54
  else
56
- self.user_token = nil
55
+ self.error = nil
57
56
  end
58
57
  end
59
58
 
@@ -63,7 +62,7 @@ module Algolia
63
62
  return true if equal?(other)
64
63
 
65
64
  self.class == other.class &&
66
- user_token == other.user_token
65
+ error == other.error
67
66
  end
68
67
 
69
68
  # @see the `==` method
@@ -75,7 +74,7 @@ module Algolia
75
74
  # Calculates hash code according to all attributes.
76
75
  # @return [Integer] Hash code
77
76
  def hash
78
- [user_token].hash
77
+ [error].hash
79
78
  end
80
79
 
81
80
  # Builds the object from hash
@@ -140,7 +139,7 @@ module Algolia
140
139
  end
141
140
  else # model
142
141
  # models (e.g. Pet) or oneOf
143
- klass = Algolia::Recommend.const_get(type)
142
+ klass = Algolia::Usage.const_get(type)
144
143
  klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
145
144
  end
146
145
  end
@@ -0,0 +1,216 @@
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 Usage
8
+ class GetUsage400ResponseError
9
+ attr_accessor :code
10
+
11
+ attr_accessor :message
12
+
13
+ attr_accessor :errors
14
+
15
+ # Attribute mapping from ruby-style variable name to JSON key.
16
+ def self.attribute_map
17
+ {
18
+ :code => :code,
19
+ :message => :message,
20
+ :errors => :errors
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
+ :code => :String,
33
+ :message => :String,
34
+ :errors => :'Array<GetUsage400ResponseErrorErrorsInner>'
35
+ }
36
+ end
37
+
38
+ # List of attributes with nullable: true
39
+ def self.openapi_nullable
40
+ Set.new([])
41
+ end
42
+
43
+ # Initializes the object
44
+ # @param [Hash] attributes Model attributes in the form of hash
45
+ def initialize(attributes = {})
46
+ unless attributes.is_a?(Hash)
47
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::GetUsage400ResponseError` initialize method"
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({}) do |(k, v), h|
52
+ unless self.class.attribute_map.key?(k.to_sym)
53
+ raise ArgumentError,
54
+ "`#{k}` is not a valid attribute in `Algolia::GetUsage400ResponseError`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
55
+ end
56
+
57
+ h[k.to_sym] = v
58
+ end
59
+
60
+ if attributes.key?(:code)
61
+ self.code = attributes[:code]
62
+ end
63
+
64
+ if attributes.key?(:message)
65
+ self.message = attributes[:message]
66
+ end
67
+
68
+ if attributes.key?(:errors)
69
+ if (value = attributes[:errors]).is_a?(Array)
70
+ self.errors = value
71
+ end
72
+ end
73
+ end
74
+
75
+ # Checks equality by comparing each attribute.
76
+ # @param [Object] Object to be compared
77
+ def ==(other)
78
+ return true if equal?(other)
79
+
80
+ self.class == other.class &&
81
+ code == other.code &&
82
+ message == other.message &&
83
+ errors == other.errors
84
+ end
85
+
86
+ # @see the `==` method
87
+ # @param [Object] Object to be compared
88
+ def eql?(other)
89
+ self == other
90
+ end
91
+
92
+ # Calculates hash code according to all attributes.
93
+ # @return [Integer] Hash code
94
+ def hash
95
+ [code, message, errors].hash
96
+ end
97
+
98
+ # Builds the object from hash
99
+ # @param [Hash] attributes Model attributes in the form of hash
100
+ # @return [Object] Returns the model itself
101
+ def self.build_from_hash(attributes)
102
+ return nil unless attributes.is_a?(Hash)
103
+
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| _deserialize(::Regexp.last_match(1), v) }
114
+ end
115
+ elsif !attributes[attribute_map[key]].nil?
116
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
117
+ end
118
+ end
119
+ new(transformed_hash)
120
+ end
121
+
122
+ # Deserializes the data based on type
123
+ # @param string type Data type
124
+ # @param string value Value to be deserialized
125
+ # @return [Object] Deserialized data
126
+ def self._deserialize(type, value)
127
+ case type.to_sym
128
+ when :Time
129
+ Time.parse(value)
130
+ when :Date
131
+ Date.parse(value)
132
+ when :String
133
+ value.to_s
134
+ when :Integer
135
+ value.to_i
136
+ when :Float
137
+ value.to_f
138
+ when :Boolean
139
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
140
+ true
141
+ else
142
+ false
143
+ end
144
+ when :Object
145
+ # generic object (usually a Hash), return directly
146
+ value
147
+ when /\AArray<(?<inner_type>.+)>\z/
148
+ inner_type = Regexp.last_match[:inner_type]
149
+ value.map { |v| _deserialize(inner_type, v) }
150
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
151
+ k_type = Regexp.last_match[:k_type]
152
+ v_type = Regexp.last_match[:v_type]
153
+ {}.tap do |hash|
154
+ value.each do |k, v|
155
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
156
+ end
157
+ end
158
+ else # model
159
+ # models (e.g. Pet) or oneOf
160
+ klass = Algolia::Usage.const_get(type)
161
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
162
+ end
163
+ end
164
+
165
+ # Returns the string representation of the object
166
+ # @return [String] String presentation of the object
167
+ def to_s
168
+ to_hash.to_s
169
+ end
170
+
171
+ # to_body is an alias to to_hash (backward compatibility)
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_body
174
+ to_hash
175
+ end
176
+
177
+ def to_json(*_args)
178
+ to_hash.to_json
179
+ end
180
+
181
+ # Returns the object in the form of hash
182
+ # @return [Hash] Returns the object in the form of hash
183
+ def to_hash
184
+ hash = {}
185
+ self.class.attribute_map.each_pair do |attr, param|
186
+ value = send(attr)
187
+ if value.nil?
188
+ is_nullable = self.class.openapi_nullable.include?(attr)
189
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
190
+ end
191
+
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end