algolia 3.0.0.beta.10 → 3.0.0.beta.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +2 -2
- data/lib/algolia/api/ingestion_client.rb +912 -359
- data/lib/algolia/api/query_suggestions_client.rb +4 -10
- data/lib/algolia/api/search_client.rb +4 -4
- data/lib/algolia/api/usage_client.rb +4 -4
- data/lib/algolia/error.rb +10 -0
- data/lib/algolia/logger_helper.rb +11 -2
- data/lib/algolia/models/abtesting/{filter_effects_empty_search.rb → empty_search_filter.rb} +3 -3
- data/lib/algolia/models/abtesting/filter_effects.rb +2 -2
- data/lib/algolia/models/abtesting/{filter_effects_outliers.rb → outliers_filter.rb} +3 -3
- data/lib/algolia/models/analytics/{click_positions_inner.rb → click_position.rb} +3 -3
- data/lib/algolia/models/analytics/get_click_positions_response.rb +1 -1
- data/lib/algolia/models/analytics/top_search_with_analytics.rb +1 -1
- data/lib/algolia/models/analytics/top_search_with_revenue_analytics.rb +1 -1
- data/lib/algolia/models/ingestion/action.rb +45 -0
- data/lib/algolia/models/{search/search_for_hits_options.rb → ingestion/batch_request.rb} +22 -20
- data/lib/algolia/models/ingestion/{source_shopify_base.rb → batch_write_params.rb} +14 -12
- data/lib/algolia/models/ingestion/docker_streams_input.rb +1 -0
- data/lib/algolia/models/{recommend/recommendations_hits.rb → ingestion/list_tasks_response_v1.rb} +26 -14
- data/lib/algolia/models/ingestion/task.rb +30 -9
- data/lib/algolia/models/ingestion/task_create.rb +11 -12
- data/lib/algolia/models/{search/search_for_facets_options.rb → ingestion/task_create_v1.rb} +86 -51
- data/lib/algolia/models/ingestion/task_update.rb +8 -7
- data/lib/algolia/models/{search/browse_pagination.rb → ingestion/task_update_v1.rb} +50 -55
- data/lib/algolia/models/{recommend/looking_similar.rb → ingestion/task_v1.rb} +147 -30
- data/lib/algolia/models/ingestion/{transformation_try_response_error.rb → transformation_error.rb} +3 -3
- data/lib/algolia/models/ingestion/transformation_try_response.rb +1 -1
- data/lib/algolia/models/monitoring/{incidents_inner.rb → incident_entry.rb} +3 -3
- data/lib/algolia/models/monitoring/{indexing_time_response_metrics.rb → indexing_metric.rb} +3 -3
- data/lib/algolia/models/monitoring/indexing_time_response.rb +1 -1
- data/lib/algolia/models/monitoring/infrastructure_response.rb +1 -1
- data/lib/algolia/models/monitoring/{latency_response_metrics.rb → latency_metric.rb} +3 -3
- data/lib/algolia/models/monitoring/latency_response.rb +1 -1
- data/lib/algolia/models/monitoring/{infrastructure_response_metrics.rb → metrics.rb} +3 -6
- data/lib/algolia/models/monitoring/{time_inner.rb → time_entry.rb} +3 -3
- data/lib/algolia/models/{recommend/trending_items.rb → query-suggestions/config_status.rb} +46 -58
- data/lib/algolia/models/{recommend/related_products.rb → query-suggestions/log_file.rb} +36 -32
- data/lib/algolia/models/recommend/around_precision.rb +1 -1
- data/lib/algolia/models/recommend/fallback_params.rb +1 -1
- data/lib/algolia/models/recommend/{around_precision_from_value_inner.rb → range.rb} +3 -6
- data/lib/algolia/models/recommend/recommend_rule.rb +1 -1
- data/lib/algolia/models/recommend/{redirect_rule_index_metadata_data.rb → redirect_rule_index_data.rb} +3 -3
- data/lib/algolia/models/recommend/redirect_rule_index_metadata.rb +1 -1
- data/lib/algolia/models/recommend/{recommend_rule_metadata.rb → rule_metadata.rb} +3 -3
- data/lib/algolia/models/recommend/search_params.rb +1 -1
- data/lib/algolia/models/recommend/search_params_object.rb +1 -1
- data/lib/algolia/models/search/around_precision.rb +1 -1
- data/lib/algolia/models/search/browse_params_object.rb +1 -1
- data/lib/algolia/models/search/built_in_operation.rb +1 -2
- data/lib/algolia/models/search/built_in_operation_value.rb +105 -0
- data/lib/algolia/models/search/consequence_params.rb +1 -1
- data/lib/algolia/models/search/dictionary_entry.rb +0 -2
- data/lib/algolia/models/search/index_settings.rb +2 -2
- data/lib/algolia/models/search/{around_precision_from_value_inner.rb → range.rb} +3 -6
- data/lib/algolia/models/search/{redirect_rule_index_metadata_data.rb → redirect_rule_index_data.rb} +3 -3
- data/lib/algolia/models/search/redirect_rule_index_metadata.rb +1 -1
- data/lib/algolia/models/search/search_for_facets.rb +1 -1
- data/lib/algolia/models/search/search_for_hits.rb +1 -1
- data/lib/algolia/models/search/search_params_object.rb +1 -1
- data/lib/algolia/models/search/search_params_string.rb +1 -0
- data/lib/algolia/models/search/{index_settings_as_search_params.rb → settings_response.rb} +251 -11
- data/lib/algolia/models/usage/{get_usage400_response_error_errors_inner.rb → error_item.rb} +3 -3
- data/lib/algolia/models/usage/{get_usage400_response_error.rb → forbidden_error.rb} +4 -4
- data/lib/algolia/models/usage/{get_usage200_response.rb → index_usage.rb} +4 -4
- data/lib/algolia/models/usage/invalid_request_error.rb +231 -0
- data/lib/algolia/models/usage/{get_usage200_response_statistics_inner.rb → statistic_entry.rb} +3 -3
- data/lib/algolia/transport/transport.rb +8 -2
- data/lib/algolia/version.rb +1 -1
- metadata +32 -63
- data/lib/algolia/models/abtesting/custom_search_params.rb +0 -214
- data/lib/algolia/models/abtesting/error_base.rb +0 -212
- data/lib/algolia/models/analytics/error_base.rb +0 -212
- data/lib/algolia/models/ingestion/error_base.rb +0 -212
- data/lib/algolia/models/insights/error_base.rb +0 -212
- data/lib/algolia/models/monitoring/error_base.rb +0 -212
- data/lib/algolia/models/monitoring/get_servers403_response.rb +0 -211
- data/lib/algolia/models/personalization/error_base.rb +0 -212
- data/lib/algolia/models/query-suggestions/app_id.rb +0 -209
- data/lib/algolia/models/query-suggestions/error_base.rb +0 -212
- data/lib/algolia/models/recommend/base_recommend_request.rb +0 -281
- data/lib/algolia/models/recommend/base_search_params.rb +0 -635
- data/lib/algolia/models/recommend/base_search_params_without_query.rb +0 -616
- data/lib/algolia/models/recommend/base_search_response.rb +0 -499
- data/lib/algolia/models/recommend/error_base.rb +0 -212
- data/lib/algolia/models/recommend/frequently_bought_together.rb +0 -247
- data/lib/algolia/models/recommend/index_settings_as_search_params.rb +0 -788
- data/lib/algolia/models/recommend/recommended_for_you.rb +0 -244
- data/lib/algolia/models/recommend/search_pagination.rb +0 -282
- data/lib/algolia/models/recommend/search_params_query.rb +0 -212
- data/lib/algolia/models/recommend/trending_facets.rb +0 -258
- data/lib/algolia/models/search/base_get_api_key_response.rb +0 -224
- data/lib/algolia/models/search/base_index_settings.rb +0 -426
- data/lib/algolia/models/search/base_search_params.rb +0 -635
- data/lib/algolia/models/search/base_search_params_without_query.rb +0 -616
- data/lib/algolia/models/search/base_search_response.rb +0 -499
- data/lib/algolia/models/search/cursor.rb +0 -209
- data/lib/algolia/models/search/error_base.rb +0 -212
- data/lib/algolia/models/search/params.rb +0 -236
- data/lib/algolia/models/search/search_hits.rb +0 -240
- data/lib/algolia/models/search/search_pagination.rb +0 -282
- data/lib/algolia/models/search/search_params_query.rb +0 -212
- data/lib/algolia/models/usage/error_base.rb +0 -212
- data/lib/algolia/models/usage/get_usage400_response.rb +0 -213
@@ -1,212 +0,0 @@
|
|
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 QuerySuggestions
|
8
|
-
# Error.
|
9
|
-
class ErrorBase
|
10
|
-
attr_accessor :message
|
11
|
-
|
12
|
-
attr_accessor :additional_properties
|
13
|
-
|
14
|
-
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
-
def self.attribute_map
|
16
|
-
{
|
17
|
-
:message => :message
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns all the JSON keys this model knows about
|
22
|
-
def self.acceptable_attributes
|
23
|
-
attribute_map.values
|
24
|
-
end
|
25
|
-
|
26
|
-
# Attribute type mapping.
|
27
|
-
def self.types_mapping
|
28
|
-
{
|
29
|
-
:message => :"String"
|
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::ErrorBase` initialize method"
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
if attributes.key?(:message)
|
51
|
-
self.message = attributes[:message]
|
52
|
-
end
|
53
|
-
|
54
|
-
# add extra attribute to additional_properties
|
55
|
-
self.additional_properties ||= {}
|
56
|
-
self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) })
|
57
|
-
end
|
58
|
-
|
59
|
-
# Checks equality by comparing each attribute.
|
60
|
-
# @param [Object] Object to be compared
|
61
|
-
def ==(other)
|
62
|
-
return true if self.equal?(other)
|
63
|
-
self.class == other.class &&
|
64
|
-
message == other.message
|
65
|
-
end
|
66
|
-
|
67
|
-
# @see the `==` method
|
68
|
-
# @param [Object] Object to be compared
|
69
|
-
def eql?(other)
|
70
|
-
self == other
|
71
|
-
end
|
72
|
-
|
73
|
-
# Calculates hash code according to all attributes.
|
74
|
-
# @return [Integer] Hash code
|
75
|
-
def hash
|
76
|
-
[message].hash
|
77
|
-
end
|
78
|
-
|
79
|
-
# Builds the object from hash
|
80
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
81
|
-
# @return [Object] Returns the model itself
|
82
|
-
def self.build_from_hash(attributes)
|
83
|
-
return nil unless attributes.is_a?(Hash)
|
84
|
-
attributes = attributes.transform_keys(&:to_sym)
|
85
|
-
transformed_hash = {}
|
86
|
-
types_mapping.each_pair do |key, type|
|
87
|
-
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
88
|
-
transformed_hash[key.to_sym] = nil
|
89
|
-
elsif type =~ /\AArray<(.*)>/i
|
90
|
-
# check to ensure the input is an array given that the attribute
|
91
|
-
# is documented as an array but the input is not
|
92
|
-
if attributes[attribute_map[key]].is_a?(Array)
|
93
|
-
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
94
|
-
_deserialize(::Regexp.last_match(1), v)
|
95
|
-
}
|
96
|
-
end
|
97
|
-
elsif !attributes[attribute_map[key]].nil?
|
98
|
-
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# add extra attribute to transformed_hash
|
103
|
-
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
|
104
|
-
new(transformed_hash)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Deserializes the data based on type
|
108
|
-
# @param string type Data type
|
109
|
-
# @param string value Value to be deserialized
|
110
|
-
# @return [Object] Deserialized data
|
111
|
-
def self._deserialize(type, value)
|
112
|
-
case type.to_sym
|
113
|
-
when :Time
|
114
|
-
Time.parse(value)
|
115
|
-
when :Date
|
116
|
-
Date.parse(value)
|
117
|
-
when :String
|
118
|
-
value.to_s
|
119
|
-
when :Integer
|
120
|
-
value.to_i
|
121
|
-
when :Float
|
122
|
-
value.to_f
|
123
|
-
when :Boolean
|
124
|
-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
125
|
-
true
|
126
|
-
else
|
127
|
-
false
|
128
|
-
end
|
129
|
-
|
130
|
-
when :Object
|
131
|
-
# generic object (usually a Hash), return directly
|
132
|
-
value
|
133
|
-
when /\AArray<(?<inner_type>.+)>\z/
|
134
|
-
inner_type = Regexp.last_match[:inner_type]
|
135
|
-
value.map { |v| _deserialize(inner_type, v) }
|
136
|
-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
137
|
-
k_type = Regexp.last_match[:k_type]
|
138
|
-
v_type = Regexp.last_match[:v_type]
|
139
|
-
{}.tap do |hash|
|
140
|
-
value.each do |k, v|
|
141
|
-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
# model
|
145
|
-
else
|
146
|
-
# models (e.g. Pet) or oneOf
|
147
|
-
klass = Algolia::QuerySuggestions.const_get(type)
|
148
|
-
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
149
|
-
.build_from_hash(value)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Returns the string representation of the object
|
154
|
-
# @return [String] String presentation of the object
|
155
|
-
def to_s
|
156
|
-
to_hash.to_s
|
157
|
-
end
|
158
|
-
|
159
|
-
# to_body is an alias to to_hash (backward compatibility)
|
160
|
-
# @return [Hash] Returns the object in the form of hash
|
161
|
-
def to_body
|
162
|
-
to_hash
|
163
|
-
end
|
164
|
-
|
165
|
-
def to_json(*_args)
|
166
|
-
to_hash.to_json
|
167
|
-
end
|
168
|
-
|
169
|
-
# Returns the object in the form of hash
|
170
|
-
# @return [Hash] Returns the object in the form of hash
|
171
|
-
def to_hash
|
172
|
-
hash = {}
|
173
|
-
self.class.attribute_map.each_pair do |attr, param|
|
174
|
-
value = send(attr)
|
175
|
-
if value.nil?
|
176
|
-
is_nullable = self.class.openapi_nullable.include?(attr)
|
177
|
-
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
178
|
-
end
|
179
|
-
|
180
|
-
hash[param] = _to_hash(value)
|
181
|
-
end
|
182
|
-
|
183
|
-
# also add attributes from additional_properties to hash
|
184
|
-
self.additional_properties&.each_pair do |k, v|
|
185
|
-
hash[k.to_sym] = _to_hash(v)
|
186
|
-
end
|
187
|
-
|
188
|
-
hash
|
189
|
-
end
|
190
|
-
|
191
|
-
# Outputs non-array value in the form of hash
|
192
|
-
# For object, use to_hash. Otherwise, just return the value
|
193
|
-
# @param [Object] value Any valid value
|
194
|
-
# @return [Hash] Returns the value in the form of hash
|
195
|
-
def _to_hash(value)
|
196
|
-
if value.is_a?(Array)
|
197
|
-
value.compact.map { |v| _to_hash(v) }
|
198
|
-
elsif value.is_a?(Hash)
|
199
|
-
{}.tap do |hash|
|
200
|
-
value.each { |k, v| hash[k] = _to_hash(v) }
|
201
|
-
end
|
202
|
-
elsif value.respond_to?(:to_hash)
|
203
|
-
value.to_hash
|
204
|
-
else
|
205
|
-
value
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
212
|
-
end
|
@@ -1,281 +0,0 @@
|
|
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
|
-
class BaseRecommendRequest
|
9
|
-
# Index name (case-sensitive).
|
10
|
-
attr_accessor :index_name
|
11
|
-
|
12
|
-
# Minimum score a recommendation must have to be included in the response.
|
13
|
-
attr_accessor :threshold
|
14
|
-
|
15
|
-
# Maximum number of recommendations to retrieve. By default, all recommendations are returned and no fallback request is made. Depending on the available recommendations and the other request parameters, the actual number of recommendations may be lower than this value.
|
16
|
-
attr_accessor :max_recommendations
|
17
|
-
|
18
|
-
attr_accessor :query_parameters
|
19
|
-
|
20
|
-
# Attribute mapping from ruby-style variable name to JSON key.
|
21
|
-
def self.attribute_map
|
22
|
-
{
|
23
|
-
:index_name => :indexName,
|
24
|
-
:threshold => :threshold,
|
25
|
-
:max_recommendations => :maxRecommendations,
|
26
|
-
:query_parameters => :queryParameters
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns all the JSON keys this model knows about
|
31
|
-
def self.acceptable_attributes
|
32
|
-
attribute_map.values
|
33
|
-
end
|
34
|
-
|
35
|
-
# Attribute type mapping.
|
36
|
-
def self.types_mapping
|
37
|
-
{
|
38
|
-
:index_name => :"String",
|
39
|
-
:threshold => :"Float",
|
40
|
-
:max_recommendations => :"Integer",
|
41
|
-
:query_parameters => :"SearchParams"
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
# List of attributes with nullable: true
|
46
|
-
def self.openapi_nullable
|
47
|
-
Set.new(
|
48
|
-
[]
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Initializes the object
|
53
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
54
|
-
def initialize(attributes = {})
|
55
|
-
if (!attributes.is_a?(Hash))
|
56
|
-
raise(
|
57
|
-
ArgumentError,
|
58
|
-
"The input argument (attributes) must be a hash in `Algolia::BaseRecommendRequest` initialize method"
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
# check to see if the attribute exists and convert string to symbol for hash key
|
63
|
-
attributes = attributes.each_with_object({}) { |(k, v), h|
|
64
|
-
if (!self.class.attribute_map.key?(k.to_sym))
|
65
|
-
raise(
|
66
|
-
ArgumentError,
|
67
|
-
"`#{k}` is not a valid attribute in `Algolia::BaseRecommendRequest`. Please check the name to make sure it's valid. List of attributes: " +
|
68
|
-
self.class.attribute_map.keys.inspect
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
h[k.to_sym] = v
|
73
|
-
}
|
74
|
-
|
75
|
-
if attributes.key?(:index_name)
|
76
|
-
self.index_name = attributes[:index_name]
|
77
|
-
else
|
78
|
-
self.index_name = nil
|
79
|
-
end
|
80
|
-
|
81
|
-
if attributes.key?(:threshold)
|
82
|
-
self.threshold = attributes[:threshold]
|
83
|
-
else
|
84
|
-
self.threshold = nil
|
85
|
-
end
|
86
|
-
|
87
|
-
if attributes.key?(:max_recommendations)
|
88
|
-
self.max_recommendations = attributes[:max_recommendations]
|
89
|
-
end
|
90
|
-
|
91
|
-
if attributes.key?(:query_parameters)
|
92
|
-
self.query_parameters = attributes[:query_parameters]
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Custom attribute writer method with validation
|
97
|
-
# @param [Object] threshold Value to be assigned
|
98
|
-
def threshold=(threshold)
|
99
|
-
if threshold.nil?
|
100
|
-
raise ArgumentError, "threshold cannot be nil"
|
101
|
-
end
|
102
|
-
|
103
|
-
if threshold > 100
|
104
|
-
raise ArgumentError, "invalid value for \"threshold\", must be smaller than or equal to 100."
|
105
|
-
end
|
106
|
-
|
107
|
-
if threshold < 0
|
108
|
-
raise ArgumentError, "invalid value for \"threshold\", must be greater than or equal to 0."
|
109
|
-
end
|
110
|
-
|
111
|
-
@threshold = threshold
|
112
|
-
end
|
113
|
-
|
114
|
-
# Custom attribute writer method with validation
|
115
|
-
# @param [Object] max_recommendations Value to be assigned
|
116
|
-
def max_recommendations=(max_recommendations)
|
117
|
-
if max_recommendations.nil?
|
118
|
-
raise ArgumentError, "max_recommendations cannot be nil"
|
119
|
-
end
|
120
|
-
|
121
|
-
if max_recommendations > 1000
|
122
|
-
raise ArgumentError, "invalid value for \"max_recommendations\", must be smaller than or equal to 1000."
|
123
|
-
end
|
124
|
-
|
125
|
-
if max_recommendations < 1
|
126
|
-
raise ArgumentError, "invalid value for \"max_recommendations\", must be greater than or equal to 1."
|
127
|
-
end
|
128
|
-
|
129
|
-
@max_recommendations = max_recommendations
|
130
|
-
end
|
131
|
-
|
132
|
-
# Checks equality by comparing each attribute.
|
133
|
-
# @param [Object] Object to be compared
|
134
|
-
def ==(other)
|
135
|
-
return true if self.equal?(other)
|
136
|
-
self.class == other.class &&
|
137
|
-
index_name == other.index_name &&
|
138
|
-
threshold == other.threshold &&
|
139
|
-
max_recommendations == other.max_recommendations &&
|
140
|
-
query_parameters == other.query_parameters
|
141
|
-
end
|
142
|
-
|
143
|
-
# @see the `==` method
|
144
|
-
# @param [Object] Object to be compared
|
145
|
-
def eql?(other)
|
146
|
-
self == other
|
147
|
-
end
|
148
|
-
|
149
|
-
# Calculates hash code according to all attributes.
|
150
|
-
# @return [Integer] Hash code
|
151
|
-
def hash
|
152
|
-
[index_name, threshold, max_recommendations, query_parameters].hash
|
153
|
-
end
|
154
|
-
|
155
|
-
# Builds the object from hash
|
156
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
157
|
-
# @return [Object] Returns the model itself
|
158
|
-
def self.build_from_hash(attributes)
|
159
|
-
return nil unless attributes.is_a?(Hash)
|
160
|
-
attributes = attributes.transform_keys(&:to_sym)
|
161
|
-
transformed_hash = {}
|
162
|
-
types_mapping.each_pair do |key, type|
|
163
|
-
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
164
|
-
transformed_hash[key.to_sym] = nil
|
165
|
-
elsif type =~ /\AArray<(.*)>/i
|
166
|
-
# check to ensure the input is an array given that the attribute
|
167
|
-
# is documented as an array but the input is not
|
168
|
-
if attributes[attribute_map[key]].is_a?(Array)
|
169
|
-
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
170
|
-
_deserialize(::Regexp.last_match(1), v)
|
171
|
-
}
|
172
|
-
end
|
173
|
-
elsif !attributes[attribute_map[key]].nil?
|
174
|
-
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
new(transformed_hash)
|
179
|
-
end
|
180
|
-
|
181
|
-
# Deserializes the data based on type
|
182
|
-
# @param string type Data type
|
183
|
-
# @param string value Value to be deserialized
|
184
|
-
# @return [Object] Deserialized data
|
185
|
-
def self._deserialize(type, value)
|
186
|
-
case type.to_sym
|
187
|
-
when :Time
|
188
|
-
Time.parse(value)
|
189
|
-
when :Date
|
190
|
-
Date.parse(value)
|
191
|
-
when :String
|
192
|
-
value.to_s
|
193
|
-
when :Integer
|
194
|
-
value.to_i
|
195
|
-
when :Float
|
196
|
-
value.to_f
|
197
|
-
when :Boolean
|
198
|
-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
199
|
-
true
|
200
|
-
else
|
201
|
-
false
|
202
|
-
end
|
203
|
-
|
204
|
-
when :Object
|
205
|
-
# generic object (usually a Hash), return directly
|
206
|
-
value
|
207
|
-
when /\AArray<(?<inner_type>.+)>\z/
|
208
|
-
inner_type = Regexp.last_match[:inner_type]
|
209
|
-
value.map { |v| _deserialize(inner_type, v) }
|
210
|
-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
211
|
-
k_type = Regexp.last_match[:k_type]
|
212
|
-
v_type = Regexp.last_match[:v_type]
|
213
|
-
{}.tap do |hash|
|
214
|
-
value.each do |k, v|
|
215
|
-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
# model
|
219
|
-
else
|
220
|
-
# models (e.g. Pet) or oneOf
|
221
|
-
klass = Algolia::Recommend.const_get(type)
|
222
|
-
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
223
|
-
.build_from_hash(value)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
# Returns the string representation of the object
|
228
|
-
# @return [String] String presentation of the object
|
229
|
-
def to_s
|
230
|
-
to_hash.to_s
|
231
|
-
end
|
232
|
-
|
233
|
-
# to_body is an alias to to_hash (backward compatibility)
|
234
|
-
# @return [Hash] Returns the object in the form of hash
|
235
|
-
def to_body
|
236
|
-
to_hash
|
237
|
-
end
|
238
|
-
|
239
|
-
def to_json(*_args)
|
240
|
-
to_hash.to_json
|
241
|
-
end
|
242
|
-
|
243
|
-
# Returns the object in the form of hash
|
244
|
-
# @return [Hash] Returns the object in the form of hash
|
245
|
-
def to_hash
|
246
|
-
hash = {}
|
247
|
-
self.class.attribute_map.each_pair do |attr, param|
|
248
|
-
value = send(attr)
|
249
|
-
if value.nil?
|
250
|
-
is_nullable = self.class.openapi_nullable.include?(attr)
|
251
|
-
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
252
|
-
end
|
253
|
-
|
254
|
-
hash[param] = _to_hash(value)
|
255
|
-
end
|
256
|
-
|
257
|
-
hash
|
258
|
-
end
|
259
|
-
|
260
|
-
# Outputs non-array value in the form of hash
|
261
|
-
# For object, use to_hash. Otherwise, just return the value
|
262
|
-
# @param [Object] value Any valid value
|
263
|
-
# @return [Hash] Returns the value in the form of hash
|
264
|
-
def _to_hash(value)
|
265
|
-
if value.is_a?(Array)
|
266
|
-
value.compact.map { |v| _to_hash(v) }
|
267
|
-
elsif value.is_a?(Hash)
|
268
|
-
{}.tap do |hash|
|
269
|
-
value.each { |k, v| hash[k] = _to_hash(v) }
|
270
|
-
end
|
271
|
-
elsif value.respond_to?(:to_hash)
|
272
|
-
value.to_hash
|
273
|
-
else
|
274
|
-
value
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
end
|