algolia 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,231 +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 Usage
8
- class InvalidRequestError
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<ErrorItem>"
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(
50
- ArgumentError,
51
- "The input argument (attributes) must be a hash in `Algolia::InvalidRequestError` initialize method"
52
- )
53
- end
54
-
55
- # check to see if the attribute exists and convert string to symbol for hash key
56
- attributes = attributes.each_with_object({}) { |(k, v), h|
57
- if (!self.class.attribute_map.key?(k.to_sym))
58
- raise(
59
- ArgumentError,
60
- "`#{k}` is not a valid attribute in `Algolia::InvalidRequestError`. Please check the name to make sure it's valid. List of attributes: " +
61
- self.class.attribute_map.keys.inspect
62
- )
63
- end
64
-
65
- h[k.to_sym] = v
66
- }
67
-
68
- if attributes.key?(:code)
69
- self.code = attributes[:code]
70
- end
71
-
72
- if attributes.key?(:message)
73
- self.message = attributes[:message]
74
- end
75
-
76
- if attributes.key?(:errors)
77
- if (value = attributes[:errors]).is_a?(Array)
78
- self.errors = value
79
- end
80
- end
81
- end
82
-
83
- # Checks equality by comparing each attribute.
84
- # @param [Object] Object to be compared
85
- def ==(other)
86
- return true if self.equal?(other)
87
- self.class == other.class &&
88
- code == other.code &&
89
- message == other.message &&
90
- errors == other.errors
91
- end
92
-
93
- # @see the `==` method
94
- # @param [Object] Object to be compared
95
- def eql?(other)
96
- self == other
97
- end
98
-
99
- # Calculates hash code according to all attributes.
100
- # @return [Integer] Hash code
101
- def hash
102
- [code, message, errors].hash
103
- end
104
-
105
- # Builds the object from hash
106
- # @param [Hash] attributes Model attributes in the form of hash
107
- # @return [Object] Returns the model itself
108
- def self.build_from_hash(attributes)
109
- return nil unless attributes.is_a?(Hash)
110
- attributes = attributes.transform_keys(&:to_sym)
111
- transformed_hash = {}
112
- types_mapping.each_pair do |key, type|
113
- if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
114
- transformed_hash[key.to_sym] = nil
115
- elsif type =~ /\AArray<(.*)>/i
116
- # check to ensure the input is an array given that the attribute
117
- # is documented as an array but the input is not
118
- if attributes[attribute_map[key]].is_a?(Array)
119
- transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
120
- _deserialize(::Regexp.last_match(1), v)
121
- }
122
- end
123
- elsif !attributes[attribute_map[key]].nil?
124
- transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
125
- end
126
- end
127
-
128
- new(transformed_hash)
129
- end
130
-
131
- # Deserializes the data based on type
132
- # @param string type Data type
133
- # @param string value Value to be deserialized
134
- # @return [Object] Deserialized data
135
- def self._deserialize(type, value)
136
- case type.to_sym
137
- when :Time
138
- Time.parse(value)
139
- when :Date
140
- Date.parse(value)
141
- when :String
142
- value.to_s
143
- when :Integer
144
- value.to_i
145
- when :Float
146
- value.to_f
147
- when :Boolean
148
- if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
- true
150
- else
151
- false
152
- end
153
-
154
- when :Object
155
- # generic object (usually a Hash), return directly
156
- value
157
- when /\AArray<(?<inner_type>.+)>\z/
158
- inner_type = Regexp.last_match[:inner_type]
159
- value.map { |v| _deserialize(inner_type, v) }
160
- when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
161
- k_type = Regexp.last_match[:k_type]
162
- v_type = Regexp.last_match[:v_type]
163
- {}.tap do |hash|
164
- value.each do |k, v|
165
- hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
166
- end
167
- end
168
- # model
169
- else
170
- # models (e.g. Pet) or oneOf
171
- klass = Algolia::Usage.const_get(type)
172
- klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
173
- .build_from_hash(value)
174
- end
175
- end
176
-
177
- # Returns the string representation of the object
178
- # @return [String] String presentation of the object
179
- def to_s
180
- to_hash.to_s
181
- end
182
-
183
- # to_body is an alias to to_hash (backward compatibility)
184
- # @return [Hash] Returns the object in the form of hash
185
- def to_body
186
- to_hash
187
- end
188
-
189
- def to_json(*_args)
190
- to_hash.to_json
191
- end
192
-
193
- # Returns the object in the form of hash
194
- # @return [Hash] Returns the object in the form of hash
195
- def to_hash
196
- hash = {}
197
- self.class.attribute_map.each_pair do |attr, param|
198
- value = send(attr)
199
- if value.nil?
200
- is_nullable = self.class.openapi_nullable.include?(attr)
201
- next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
202
- end
203
-
204
- hash[param] = _to_hash(value)
205
- end
206
-
207
- hash
208
- end
209
-
210
- # Outputs non-array value in the form of hash
211
- # For object, use to_hash. Otherwise, just return the value
212
- # @param [Object] value Any valid value
213
- # @return [Hash] Returns the value in the form of hash
214
- def _to_hash(value)
215
- if value.is_a?(Array)
216
- value.compact.map { |v| _to_hash(v) }
217
- elsif value.is_a?(Hash)
218
- {}.tap do |hash|
219
- value.each { |k, v| hash[k] = _to_hash(v) }
220
- end
221
- elsif value.respond_to?(:to_hash)
222
- value.to_hash
223
- else
224
- value
225
- end
226
- end
227
-
228
- end
229
-
230
- end
231
- end
@@ -1,199 +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 Usage
8
- class Statistic
9
- ALL = "*".freeze
10
- SEARCH_OPERATIONS = "search_operations".freeze
11
- TOTAL_SEARCH_OPERATIONS = "total_search_operations".freeze
12
- TOTAL_SEARCH_REQUESTS = "total_search_requests".freeze
13
- QUERIES_OPERATIONS = "queries_operations".freeze
14
- MULTI_QUERIES_OPERATIONS = "multi_queries_operations".freeze
15
- ACL_OPERATIONS = "acl_operations".freeze
16
- TOTAL_ACL_OPERATIONS = "total_acl_operations".freeze
17
- GET_API_KEYS_OPERATIONS = "get_api_keys_operations".freeze
18
- GET_API_KEY_OPERATIONS = "get_api_key_operations".freeze
19
- ADD_API_KEY_OPERATIONS = "add_api_key_operations".freeze
20
- UPDATE_API_KEY_OPERATIONS = "update_api_key_operations".freeze
21
- DELETE_API_KEY_OPERATIONS = "delete_api_key_operations".freeze
22
- LIST_API_KEY_OPERATIONS = "list_api_key_operations".freeze
23
- INDEXING_OPERATIONS = "indexing_operations".freeze
24
- TOTAL_INDEXING_OPERATIONS = "total_indexing_operations".freeze
25
- BROWSE_OPERATIONS = "browse_operations".freeze
26
- CLEAR_INDEX_OPERATIONS = "clear_index_operations".freeze
27
- COPY_MOVE_OPERATIONS = "copy_move_operations".freeze
28
- DELETE_INDEX_OPERATIONS = "delete_index_operations".freeze
29
- GET_LOG_OPERATIONS = "get_log_operations".freeze
30
- GET_SETTINGS_OPERATIONS = "get_settings_operations".freeze
31
- SET_SETTINGS_OPERATIONS = "set_settings_operations".freeze
32
- LIST_INDICES_OPERATIONS = "list_indices_operations".freeze
33
- WAIT_TASK_OPERATIONS = "wait_task_operations".freeze
34
- RECORD_OPERATIONS = "record_operations".freeze
35
- TOTAL_RECORDS_OPERATIONS = "total_records_operations".freeze
36
- ADD_RECORD_OPERATIONS = "add_record_operations".freeze
37
- BATCH_OPERATIONS = "batch_operations".freeze
38
- DELETE_BY_QUERY_OPERATIONS = "delete_by_query_operations".freeze
39
- DELETE_RECORD_OPERATIONS = "delete_record_operations".freeze
40
- GET_RECORD_OPERATIONS = "get_record_operations".freeze
41
- PARTIAL_UPDATE_RECORD_OPERATIONS = "partial_update_record_operations".freeze
42
- UPDATE_RECORD_OPERATIONS = "update_record_operations".freeze
43
- SYNONYM_OPERATIONS = "synonym_operations".freeze
44
- TOTAL_SYNONYM_OPERATIONS = "total_synonym_operations".freeze
45
- BATCH_SYNONYM_OPERATIONS = "batch_synonym_operations".freeze
46
- CLEAR_SYNONYM_OPERATIONS = "clear_synonym_operations".freeze
47
- DELETE_SYNONYM_OPERATIONS = "delete_synonym_operations".freeze
48
- GET_SYNONYM_OPERATIONS = "get_synonym_operations".freeze
49
- QUERY_SYNONYM_OPERATIONS = "query_synonym_operations".freeze
50
- UPDATE_SYNONYM_OPERATIONS = "update_synonym_operations".freeze
51
- RULE_OPERATIONS = "rule_operations".freeze
52
- TOTAL_RULES_OPERATIONS = "total_rules_operations".freeze
53
- BATCH_RULES_OPERATIONS = "batch_rules_operations".freeze
54
- CLEAR_RULES_OPERATIONS = "clear_rules_operations".freeze
55
- DELETE_RULES_OPERATIONS = "delete_rules_operations".freeze
56
- GET_RULES_OPERATIONS = "get_rules_operations".freeze
57
- SAVE_RULES_OPERATIONS = "save_rules_operations".freeze
58
- SEARCH_RULES_OPERATIONS = "search_rules_operations".freeze
59
- TOTAL_RECOMMEND_REQUESTS = "total_recommend_requests".freeze
60
- TOTAL_WRITE_OPERATIONS = "total_write_operations".freeze
61
- TOTAL_READ_OPERATIONS = "total_read_operations".freeze
62
- TOTAL_OPERATIONS = "total_operations".freeze
63
- QUERYSUGGESTIONS_TOTAL_SEARCH_OPERATIONS = "querysuggestions_total_search_operations".freeze
64
- QUERYSUGGESTIONS_TOTAL_SEARCH_REQUESTS = "querysuggestions_total_search_requests".freeze
65
- QUERYSUGGESTIONS_TOTAL_ACL_OPERATIONS = "querysuggestions_total_acl_operations".freeze
66
- QUERYSUGGESTIONS_TOTAL_INDEXING_OPERATIONS = "querysuggestions_total_indexing_operations".freeze
67
- QUERYSUGGESTIONS_TOTAL_RECORDS_OPERATIONS = "querysuggestions_total_records_operations".freeze
68
- QUERYSUGGESTIONS_TOTAL_SYNONYM_OPERATIONS = "querysuggestions_total_synonym_operations".freeze
69
- QUERYSUGGESTIONS_TOTAL_RULES_OPERATIONS = "querysuggestions_total_rules_operations".freeze
70
- QUERYSUGGESTIONS_TOTAL_WRITE_OPERATIONS = "querysuggestions_total_write_operations".freeze
71
- QUERYSUGGESTIONS_TOTAL_READ_OPERATIONS = "querysuggestions_total_read_operations".freeze
72
- QUERYSUGGESTIONS_TOTAL_OPERATIONS = "querysuggestions_total_operations".freeze
73
- AVG_PROCESSING_TIME = "avg_processing_time".freeze
74
- N90P_PROCESSING_TIME = "90p_processing_time".freeze
75
- N99P_PROCESSING_TIME = "99p_processing_time".freeze
76
- QUERIES_ABOVE_LAST_MS_PROCESSING_TIME = "queries_above_last_ms_processing_time".freeze
77
- RECORDS = "records".freeze
78
- DATA_SIZE = "data_size".freeze
79
- FILE_SIZE = "file_size".freeze
80
- MAX_QPS = "max_qps".freeze
81
- REGION_MAX_QPS = "region_max_qps".freeze
82
- TOTAL_MAX_QPS = "total_max_qps".freeze
83
- USED_SEARCH_CAPACITY = "used_search_capacity".freeze
84
- AVG_USED_SEARCH_CAPACITY = "avg_used_search_capacity".freeze
85
- REGION_USED_SEARCH_CAPACITY = "region_used_search_capacity".freeze
86
- REGION_AVG_USED_SEARCH_CAPACITY = "region_avg_used_search_capacity".freeze
87
- TOTAL_USED_SEARCH_CAPACITY = "total_used_search_capacity".freeze
88
- TOTAL_AVG_USED_SEARCH_CAPACITY = "total_avg_used_search_capacity".freeze
89
- DEGRADED_QUERIES_SSD_USED_QUERIES_IMPACTED = "degraded_queries_ssd_used_queries_impacted".freeze
90
- DEGRADED_QUERIES_SSD_USED_SECONDS_IMPACTED = "degraded_queries_ssd_used_seconds_impacted".freeze
91
- DEGRADED_QUERIES_MAX_CAPACITY_QUERIES_IMPACTED = "degraded_queries_max_capacity_queries_impacted".freeze
92
- DEGRADED_QUERIES_MAX_CAPACITY_SECONDS_IMPACTED = "degraded_queries_max_capacity_seconds_impacted".freeze
93
-
94
- def self.all_vars
95
- @all_vars ||= [
96
- ALL,
97
- SEARCH_OPERATIONS,
98
- TOTAL_SEARCH_OPERATIONS,
99
- TOTAL_SEARCH_REQUESTS,
100
- QUERIES_OPERATIONS,
101
- MULTI_QUERIES_OPERATIONS,
102
- ACL_OPERATIONS,
103
- TOTAL_ACL_OPERATIONS,
104
- GET_API_KEYS_OPERATIONS,
105
- GET_API_KEY_OPERATIONS,
106
- ADD_API_KEY_OPERATIONS,
107
- UPDATE_API_KEY_OPERATIONS,
108
- DELETE_API_KEY_OPERATIONS,
109
- LIST_API_KEY_OPERATIONS,
110
- INDEXING_OPERATIONS,
111
- TOTAL_INDEXING_OPERATIONS,
112
- BROWSE_OPERATIONS,
113
- CLEAR_INDEX_OPERATIONS,
114
- COPY_MOVE_OPERATIONS,
115
- DELETE_INDEX_OPERATIONS,
116
- GET_LOG_OPERATIONS,
117
- GET_SETTINGS_OPERATIONS,
118
- SET_SETTINGS_OPERATIONS,
119
- LIST_INDICES_OPERATIONS,
120
- WAIT_TASK_OPERATIONS,
121
- RECORD_OPERATIONS,
122
- TOTAL_RECORDS_OPERATIONS,
123
- ADD_RECORD_OPERATIONS,
124
- BATCH_OPERATIONS,
125
- DELETE_BY_QUERY_OPERATIONS,
126
- DELETE_RECORD_OPERATIONS,
127
- GET_RECORD_OPERATIONS,
128
- PARTIAL_UPDATE_RECORD_OPERATIONS,
129
- UPDATE_RECORD_OPERATIONS,
130
- SYNONYM_OPERATIONS,
131
- TOTAL_SYNONYM_OPERATIONS,
132
- BATCH_SYNONYM_OPERATIONS,
133
- CLEAR_SYNONYM_OPERATIONS,
134
- DELETE_SYNONYM_OPERATIONS,
135
- GET_SYNONYM_OPERATIONS,
136
- QUERY_SYNONYM_OPERATIONS,
137
- UPDATE_SYNONYM_OPERATIONS,
138
- RULE_OPERATIONS,
139
- TOTAL_RULES_OPERATIONS,
140
- BATCH_RULES_OPERATIONS,
141
- CLEAR_RULES_OPERATIONS,
142
- DELETE_RULES_OPERATIONS,
143
- GET_RULES_OPERATIONS,
144
- SAVE_RULES_OPERATIONS,
145
- SEARCH_RULES_OPERATIONS,
146
- TOTAL_RECOMMEND_REQUESTS,
147
- TOTAL_WRITE_OPERATIONS,
148
- TOTAL_READ_OPERATIONS,
149
- TOTAL_OPERATIONS,
150
- QUERYSUGGESTIONS_TOTAL_SEARCH_OPERATIONS,
151
- QUERYSUGGESTIONS_TOTAL_SEARCH_REQUESTS,
152
- QUERYSUGGESTIONS_TOTAL_ACL_OPERATIONS,
153
- QUERYSUGGESTIONS_TOTAL_INDEXING_OPERATIONS,
154
- QUERYSUGGESTIONS_TOTAL_RECORDS_OPERATIONS,
155
- QUERYSUGGESTIONS_TOTAL_SYNONYM_OPERATIONS,
156
- QUERYSUGGESTIONS_TOTAL_RULES_OPERATIONS,
157
- QUERYSUGGESTIONS_TOTAL_WRITE_OPERATIONS,
158
- QUERYSUGGESTIONS_TOTAL_READ_OPERATIONS,
159
- QUERYSUGGESTIONS_TOTAL_OPERATIONS,
160
- AVG_PROCESSING_TIME,
161
- N90P_PROCESSING_TIME,
162
- N99P_PROCESSING_TIME,
163
- QUERIES_ABOVE_LAST_MS_PROCESSING_TIME,
164
- RECORDS,
165
- DATA_SIZE,
166
- FILE_SIZE,
167
- MAX_QPS,
168
- REGION_MAX_QPS,
169
- TOTAL_MAX_QPS,
170
- USED_SEARCH_CAPACITY,
171
- AVG_USED_SEARCH_CAPACITY,
172
- REGION_USED_SEARCH_CAPACITY,
173
- REGION_AVG_USED_SEARCH_CAPACITY,
174
- TOTAL_USED_SEARCH_CAPACITY,
175
- TOTAL_AVG_USED_SEARCH_CAPACITY,
176
- DEGRADED_QUERIES_SSD_USED_QUERIES_IMPACTED,
177
- DEGRADED_QUERIES_SSD_USED_SECONDS_IMPACTED,
178
- DEGRADED_QUERIES_MAX_CAPACITY_QUERIES_IMPACTED,
179
- DEGRADED_QUERIES_MAX_CAPACITY_SECONDS_IMPACTED
180
- ].freeze
181
- end
182
-
183
- # Builds the enum from string
184
- # @param [String] The enum value in the form of the string
185
- # @return [String] The enum value
186
- def self.build_from_hash(value)
187
- new.build_from_hash(value)
188
- end
189
-
190
- # Builds the enum from string
191
- # @param [String] The enum value in the form of the string
192
- # @return [String] The enum value
193
- def build_from_hash(value)
194
- return value if Statistic.all_vars.include?(value)
195
- raise "Invalid ENUM value #{value} for class #Statistic"
196
- end
197
- end
198
- end
199
- end
@@ -1,221 +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 Usage
8
- class StatisticEntry
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
- []
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::StatisticEntry` 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::StatisticEntry`. 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?(:t)
66
- self.t = attributes[:t]
67
- end
68
-
69
- if attributes.key?(:v)
70
- self.v = attributes[:v]
71
- end
72
- end
73
-
74
- # Checks equality by comparing each attribute.
75
- # @param [Object] Object to be compared
76
- def ==(other)
77
- return true if self.equal?(other)
78
- self.class == other.class &&
79
- t == other.t &&
80
- v == other.v
81
- end
82
-
83
- # @see the `==` method
84
- # @param [Object] Object to be compared
85
- def eql?(other)
86
- self == other
87
- end
88
-
89
- # Calculates hash code according to all attributes.
90
- # @return [Integer] Hash code
91
- def hash
92
- [t, v].hash
93
- end
94
-
95
- # Builds the object from hash
96
- # @param [Hash] attributes Model attributes in the form of hash
97
- # @return [Object] Returns the model itself
98
- def self.build_from_hash(attributes)
99
- return nil unless attributes.is_a?(Hash)
100
- attributes = attributes.transform_keys(&:to_sym)
101
- transformed_hash = {}
102
- types_mapping.each_pair do |key, type|
103
- if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
104
- transformed_hash[key.to_sym] = nil
105
- elsif type =~ /\AArray<(.*)>/i
106
- # check to ensure the input is an array given that the attribute
107
- # is documented as an array but the input is not
108
- if attributes[attribute_map[key]].is_a?(Array)
109
- transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
110
- _deserialize(::Regexp.last_match(1), v)
111
- }
112
- end
113
- elsif !attributes[attribute_map[key]].nil?
114
- transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
115
- end
116
- end
117
-
118
- new(transformed_hash)
119
- end
120
-
121
- # Deserializes the data based on type
122
- # @param string type Data type
123
- # @param string value Value to be deserialized
124
- # @return [Object] Deserialized data
125
- def self._deserialize(type, value)
126
- case type.to_sym
127
- when :Time
128
- Time.parse(value)
129
- when :Date
130
- Date.parse(value)
131
- when :String
132
- value.to_s
133
- when :Integer
134
- value.to_i
135
- when :Float
136
- value.to_f
137
- when :Boolean
138
- if value.to_s =~ /\A(true|t|yes|y|1)\z/i
139
- true
140
- else
141
- false
142
- end
143
-
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
- # model
159
- else
160
- # models (e.g. Pet) or oneOf
161
- klass = Algolia::Usage.const_get(type)
162
- klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
163
- .build_from_hash(value)
164
- end
165
- end
166
-
167
- # Returns the string representation of the object
168
- # @return [String] String presentation of the object
169
- def to_s
170
- to_hash.to_s
171
- end
172
-
173
- # to_body is an alias to to_hash (backward compatibility)
174
- # @return [Hash] Returns the object in the form of hash
175
- def to_body
176
- to_hash
177
- end
178
-
179
- def to_json(*_args)
180
- to_hash.to_json
181
- end
182
-
183
- # Returns the object in the form of hash
184
- # @return [Hash] Returns the object in the form of hash
185
- def to_hash
186
- hash = {}
187
- self.class.attribute_map.each_pair do |attr, param|
188
- value = send(attr)
189
- if value.nil?
190
- is_nullable = self.class.openapi_nullable.include?(attr)
191
- next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
192
- end
193
-
194
- hash[param] = _to_hash(value)
195
- end
196
-
197
- hash
198
- end
199
-
200
- # Outputs non-array value in the form of hash
201
- # For object, use to_hash. Otherwise, just return the value
202
- # @param [Object] value Any valid value
203
- # @return [Hash] Returns the value in the form of hash
204
- def _to_hash(value)
205
- if value.is_a?(Array)
206
- value.compact.map { |v| _to_hash(v) }
207
- elsif value.is_a?(Hash)
208
- {}.tap do |hash|
209
- value.each { |k, v| hash[k] = _to_hash(v) }
210
- end
211
- elsif value.respond_to?(:to_hash)
212
- value.to_hash
213
- else
214
- value
215
- end
216
- end
217
-
218
- end
219
-
220
- end
221
- end