algolia 3.0.0.beta.9 → 3.0.0.beta.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +4 -2
- data/lib/algolia/api/ingestion_client.rb +912 -359
- data/lib/algolia/api/search_client.rb +17 -17
- data/lib/algolia/error.rb +10 -0
- data/lib/algolia/logger_helper.rb +11 -2
- data/lib/algolia/models/ingestion/action.rb +45 -0
- data/lib/algolia/models/ingestion/batch_request.rb +247 -0
- data/lib/algolia/models/ingestion/batch_write_params.rb +216 -0
- data/lib/algolia/models/ingestion/list_tasks_response_v1.rb +227 -0
- data/lib/algolia/models/ingestion/source_shopify.rb +10 -77
- data/lib/algolia/models/ingestion/source_update_shopify.rb +10 -76
- data/lib/algolia/models/ingestion/task.rb +30 -9
- data/lib/algolia/models/ingestion/task_create.rb +11 -12
- data/lib/algolia/models/ingestion/task_create_v1.rb +328 -0
- data/lib/algolia/models/ingestion/task_update.rb +8 -7
- data/lib/algolia/models/ingestion/task_update_v1.rb +269 -0
- data/lib/algolia/models/ingestion/task_v1.rb +373 -0
- data/lib/algolia/models/recommend/get_recommendations_response.rb +2 -0
- data/lib/algolia/models/recommend/trending_items.rb +0 -4
- data/lib/algolia/models/recommend/trending_items_query.rb +0 -4
- data/lib/algolia/models/search/settings_response.rb +1028 -0
- data/lib/algolia/models/search/with_primary.rb +212 -0
- data/lib/algolia/transport/transport.rb +9 -3
- data/lib/algolia/version.rb +1 -1
- metadata +11 -2
@@ -0,0 +1,328 @@
|
|
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 Ingestion
|
8
|
+
# API request body for creating a task using the V1 shape, please use methods and types that don't contain the V1 suffix.
|
9
|
+
class TaskCreateV1
|
10
|
+
# Universally uniqud identifier (UUID) of a source.
|
11
|
+
attr_accessor :source_id
|
12
|
+
|
13
|
+
# Universally unique identifier (UUID) of a destination resource.
|
14
|
+
attr_accessor :destination_id
|
15
|
+
|
16
|
+
attr_accessor :trigger
|
17
|
+
|
18
|
+
attr_accessor :action
|
19
|
+
|
20
|
+
# Whether the task is enabled.
|
21
|
+
attr_accessor :enabled
|
22
|
+
|
23
|
+
# Maximum accepted percentage of failures for a task run to finish successfully.
|
24
|
+
attr_accessor :failure_threshold
|
25
|
+
|
26
|
+
attr_accessor :input
|
27
|
+
|
28
|
+
# Date of the last cursor in RFC 3339 format.
|
29
|
+
attr_accessor :cursor
|
30
|
+
|
31
|
+
class EnumAttributeValidator
|
32
|
+
attr_reader :datatype
|
33
|
+
attr_reader :allowable_values
|
34
|
+
|
35
|
+
def initialize(datatype, allowable_values)
|
36
|
+
@allowable_values = allowable_values.map do |value|
|
37
|
+
case datatype.to_s
|
38
|
+
when /Integer/i
|
39
|
+
value.to_i
|
40
|
+
when /Float/i
|
41
|
+
value.to_f
|
42
|
+
else
|
43
|
+
value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid?(value)
|
49
|
+
!value || allowable_values.include?(value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
54
|
+
def self.attribute_map
|
55
|
+
{
|
56
|
+
:source_id => :sourceID,
|
57
|
+
:destination_id => :destinationID,
|
58
|
+
:trigger => :trigger,
|
59
|
+
:action => :action,
|
60
|
+
:enabled => :enabled,
|
61
|
+
:failure_threshold => :failureThreshold,
|
62
|
+
:input => :input,
|
63
|
+
:cursor => :cursor
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns all the JSON keys this model knows about
|
68
|
+
def self.acceptable_attributes
|
69
|
+
attribute_map.values
|
70
|
+
end
|
71
|
+
|
72
|
+
# Attribute type mapping.
|
73
|
+
def self.types_mapping
|
74
|
+
{
|
75
|
+
:source_id => :"String",
|
76
|
+
:destination_id => :"String",
|
77
|
+
:trigger => :"TaskCreateTrigger",
|
78
|
+
:action => :"ActionType",
|
79
|
+
:enabled => :"Boolean",
|
80
|
+
:failure_threshold => :"Integer",
|
81
|
+
:input => :"TaskInput",
|
82
|
+
:cursor => :"String"
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
# List of attributes with nullable: true
|
87
|
+
def self.openapi_nullable
|
88
|
+
Set.new(
|
89
|
+
[]
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Initializes the object
|
94
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
95
|
+
def initialize(attributes = {})
|
96
|
+
if (!attributes.is_a?(Hash))
|
97
|
+
raise(
|
98
|
+
ArgumentError,
|
99
|
+
"The input argument (attributes) must be a hash in `Algolia::TaskCreateV1` initialize method"
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
104
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
105
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
106
|
+
raise(
|
107
|
+
ArgumentError,
|
108
|
+
"`#{k}` is not a valid attribute in `Algolia::TaskCreateV1`. Please check the name to make sure it's valid. List of attributes: " +
|
109
|
+
self.class.attribute_map.keys.inspect
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
h[k.to_sym] = v
|
114
|
+
}
|
115
|
+
|
116
|
+
if attributes.key?(:source_id)
|
117
|
+
self.source_id = attributes[:source_id]
|
118
|
+
else
|
119
|
+
self.source_id = nil
|
120
|
+
end
|
121
|
+
|
122
|
+
if attributes.key?(:destination_id)
|
123
|
+
self.destination_id = attributes[:destination_id]
|
124
|
+
else
|
125
|
+
self.destination_id = nil
|
126
|
+
end
|
127
|
+
|
128
|
+
if attributes.key?(:trigger)
|
129
|
+
self.trigger = attributes[:trigger]
|
130
|
+
else
|
131
|
+
self.trigger = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
if attributes.key?(:action)
|
135
|
+
self.action = attributes[:action]
|
136
|
+
else
|
137
|
+
self.action = nil
|
138
|
+
end
|
139
|
+
|
140
|
+
if attributes.key?(:enabled)
|
141
|
+
self.enabled = attributes[:enabled]
|
142
|
+
end
|
143
|
+
|
144
|
+
if attributes.key?(:failure_threshold)
|
145
|
+
self.failure_threshold = attributes[:failure_threshold]
|
146
|
+
end
|
147
|
+
|
148
|
+
if attributes.key?(:input)
|
149
|
+
self.input = attributes[:input]
|
150
|
+
end
|
151
|
+
|
152
|
+
if attributes.key?(:cursor)
|
153
|
+
self.cursor = attributes[:cursor]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Custom attribute writer method with validation
|
158
|
+
# @param [Object] failure_threshold Value to be assigned
|
159
|
+
def failure_threshold=(failure_threshold)
|
160
|
+
if failure_threshold.nil?
|
161
|
+
raise ArgumentError, "failure_threshold cannot be nil"
|
162
|
+
end
|
163
|
+
|
164
|
+
if failure_threshold > 100
|
165
|
+
raise ArgumentError, "invalid value for \"failure_threshold\", must be smaller than or equal to 100."
|
166
|
+
end
|
167
|
+
|
168
|
+
if failure_threshold < 0
|
169
|
+
raise ArgumentError, "invalid value for \"failure_threshold\", must be greater than or equal to 0."
|
170
|
+
end
|
171
|
+
|
172
|
+
@failure_threshold = failure_threshold
|
173
|
+
end
|
174
|
+
|
175
|
+
# Checks equality by comparing each attribute.
|
176
|
+
# @param [Object] Object to be compared
|
177
|
+
def ==(other)
|
178
|
+
return true if self.equal?(other)
|
179
|
+
self.class == other.class &&
|
180
|
+
source_id == other.source_id &&
|
181
|
+
destination_id == other.destination_id &&
|
182
|
+
trigger == other.trigger &&
|
183
|
+
action == other.action &&
|
184
|
+
enabled == other.enabled &&
|
185
|
+
failure_threshold == other.failure_threshold &&
|
186
|
+
input == other.input &&
|
187
|
+
cursor == other.cursor
|
188
|
+
end
|
189
|
+
|
190
|
+
# @see the `==` method
|
191
|
+
# @param [Object] Object to be compared
|
192
|
+
def eql?(other)
|
193
|
+
self == other
|
194
|
+
end
|
195
|
+
|
196
|
+
# Calculates hash code according to all attributes.
|
197
|
+
# @return [Integer] Hash code
|
198
|
+
def hash
|
199
|
+
[source_id, destination_id, trigger, action, enabled, failure_threshold, input, cursor].hash
|
200
|
+
end
|
201
|
+
|
202
|
+
# Builds the object from hash
|
203
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
204
|
+
# @return [Object] Returns the model itself
|
205
|
+
def self.build_from_hash(attributes)
|
206
|
+
return nil unless attributes.is_a?(Hash)
|
207
|
+
attributes = attributes.transform_keys(&:to_sym)
|
208
|
+
transformed_hash = {}
|
209
|
+
types_mapping.each_pair do |key, type|
|
210
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
211
|
+
transformed_hash[key.to_sym] = nil
|
212
|
+
elsif type =~ /\AArray<(.*)>/i
|
213
|
+
# check to ensure the input is an array given that the attribute
|
214
|
+
# is documented as an array but the input is not
|
215
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
216
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
217
|
+
_deserialize(::Regexp.last_match(1), v)
|
218
|
+
}
|
219
|
+
end
|
220
|
+
elsif !attributes[attribute_map[key]].nil?
|
221
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
new(transformed_hash)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Deserializes the data based on type
|
229
|
+
# @param string type Data type
|
230
|
+
# @param string value Value to be deserialized
|
231
|
+
# @return [Object] Deserialized data
|
232
|
+
def self._deserialize(type, value)
|
233
|
+
case type.to_sym
|
234
|
+
when :Time
|
235
|
+
Time.parse(value)
|
236
|
+
when :Date
|
237
|
+
Date.parse(value)
|
238
|
+
when :String
|
239
|
+
value.to_s
|
240
|
+
when :Integer
|
241
|
+
value.to_i
|
242
|
+
when :Float
|
243
|
+
value.to_f
|
244
|
+
when :Boolean
|
245
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
246
|
+
true
|
247
|
+
else
|
248
|
+
false
|
249
|
+
end
|
250
|
+
|
251
|
+
when :Object
|
252
|
+
# generic object (usually a Hash), return directly
|
253
|
+
value
|
254
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
255
|
+
inner_type = Regexp.last_match[:inner_type]
|
256
|
+
value.map { |v| _deserialize(inner_type, v) }
|
257
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
258
|
+
k_type = Regexp.last_match[:k_type]
|
259
|
+
v_type = Regexp.last_match[:v_type]
|
260
|
+
{}.tap do |hash|
|
261
|
+
value.each do |k, v|
|
262
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
# model
|
266
|
+
else
|
267
|
+
# models (e.g. Pet) or oneOf
|
268
|
+
klass = Algolia::Ingestion.const_get(type)
|
269
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
270
|
+
.build_from_hash(value)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# Returns the string representation of the object
|
275
|
+
# @return [String] String presentation of the object
|
276
|
+
def to_s
|
277
|
+
to_hash.to_s
|
278
|
+
end
|
279
|
+
|
280
|
+
# to_body is an alias to to_hash (backward compatibility)
|
281
|
+
# @return [Hash] Returns the object in the form of hash
|
282
|
+
def to_body
|
283
|
+
to_hash
|
284
|
+
end
|
285
|
+
|
286
|
+
def to_json(*_args)
|
287
|
+
to_hash.to_json
|
288
|
+
end
|
289
|
+
|
290
|
+
# Returns the object in the form of hash
|
291
|
+
# @return [Hash] Returns the object in the form of hash
|
292
|
+
def to_hash
|
293
|
+
hash = {}
|
294
|
+
self.class.attribute_map.each_pair do |attr, param|
|
295
|
+
value = send(attr)
|
296
|
+
if value.nil?
|
297
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
298
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
299
|
+
end
|
300
|
+
|
301
|
+
hash[param] = _to_hash(value)
|
302
|
+
end
|
303
|
+
|
304
|
+
hash
|
305
|
+
end
|
306
|
+
|
307
|
+
# Outputs non-array value in the form of hash
|
308
|
+
# For object, use to_hash. Otherwise, just return the value
|
309
|
+
# @param [Object] value Any valid value
|
310
|
+
# @return [Hash] Returns the value in the form of hash
|
311
|
+
def _to_hash(value)
|
312
|
+
if value.is_a?(Array)
|
313
|
+
value.compact.map { |v| _to_hash(v) }
|
314
|
+
elsif value.is_a?(Hash)
|
315
|
+
{}.tap do |hash|
|
316
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
317
|
+
end
|
318
|
+
elsif value.respond_to?(:to_hash)
|
319
|
+
value.to_hash
|
320
|
+
else
|
321
|
+
value
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
end
|
@@ -10,7 +10,8 @@ module Algolia
|
|
10
10
|
# Universally unique identifier (UUID) of a destination resource.
|
11
11
|
attr_accessor :destination_id
|
12
12
|
|
13
|
-
|
13
|
+
# Cron expression for the task's schedule.
|
14
|
+
attr_accessor :cron
|
14
15
|
|
15
16
|
attr_accessor :input
|
16
17
|
|
@@ -24,7 +25,7 @@ module Algolia
|
|
24
25
|
def self.attribute_map
|
25
26
|
{
|
26
27
|
:destination_id => :destinationID,
|
27
|
-
:
|
28
|
+
:cron => :cron,
|
28
29
|
:input => :input,
|
29
30
|
:enabled => :enabled,
|
30
31
|
:failure_threshold => :failureThreshold
|
@@ -40,7 +41,7 @@ module Algolia
|
|
40
41
|
def self.types_mapping
|
41
42
|
{
|
42
43
|
:destination_id => :"String",
|
43
|
-
:
|
44
|
+
:cron => :"String",
|
44
45
|
:input => :"TaskInput",
|
45
46
|
:enabled => :"Boolean",
|
46
47
|
:failure_threshold => :"Integer"
|
@@ -81,8 +82,8 @@ module Algolia
|
|
81
82
|
self.destination_id = attributes[:destination_id]
|
82
83
|
end
|
83
84
|
|
84
|
-
if attributes.key?(:
|
85
|
-
self.
|
85
|
+
if attributes.key?(:cron)
|
86
|
+
self.cron = attributes[:cron]
|
86
87
|
end
|
87
88
|
|
88
89
|
if attributes.key?(:input)
|
@@ -122,7 +123,7 @@ module Algolia
|
|
122
123
|
return true if self.equal?(other)
|
123
124
|
self.class == other.class &&
|
124
125
|
destination_id == other.destination_id &&
|
125
|
-
|
126
|
+
cron == other.cron &&
|
126
127
|
input == other.input &&
|
127
128
|
enabled == other.enabled &&
|
128
129
|
failure_threshold == other.failure_threshold
|
@@ -137,7 +138,7 @@ module Algolia
|
|
137
138
|
# Calculates hash code according to all attributes.
|
138
139
|
# @return [Integer] Hash code
|
139
140
|
def hash
|
140
|
-
[destination_id,
|
141
|
+
[destination_id, cron, input, enabled, failure_threshold].hash
|
141
142
|
end
|
142
143
|
|
143
144
|
# Builds the object from hash
|
@@ -0,0 +1,269 @@
|
|
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 Ingestion
|
8
|
+
# API request body for updating a task using the V1 shape, please use methods and types that don't contain the V1 suffix.
|
9
|
+
class TaskUpdateV1
|
10
|
+
# Universally unique identifier (UUID) of a destination resource.
|
11
|
+
attr_accessor :destination_id
|
12
|
+
|
13
|
+
attr_accessor :trigger
|
14
|
+
|
15
|
+
attr_accessor :input
|
16
|
+
|
17
|
+
# Whether the task is enabled.
|
18
|
+
attr_accessor :enabled
|
19
|
+
|
20
|
+
# Maximum accepted percentage of failures for a task run to finish successfully.
|
21
|
+
attr_accessor :failure_threshold
|
22
|
+
|
23
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
24
|
+
def self.attribute_map
|
25
|
+
{
|
26
|
+
:destination_id => :destinationID,
|
27
|
+
:trigger => :trigger,
|
28
|
+
:input => :input,
|
29
|
+
:enabled => :enabled,
|
30
|
+
:failure_threshold => :failureThreshold
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns all the JSON keys this model knows about
|
35
|
+
def self.acceptable_attributes
|
36
|
+
attribute_map.values
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attribute type mapping.
|
40
|
+
def self.types_mapping
|
41
|
+
{
|
42
|
+
:destination_id => :"String",
|
43
|
+
:trigger => :"TriggerUpdateInput",
|
44
|
+
:input => :"TaskInput",
|
45
|
+
:enabled => :"Boolean",
|
46
|
+
:failure_threshold => :"Integer"
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
# List of attributes with nullable: true
|
51
|
+
def self.openapi_nullable
|
52
|
+
Set.new(
|
53
|
+
[]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Initializes the object
|
58
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
59
|
+
def initialize(attributes = {})
|
60
|
+
if (!attributes.is_a?(Hash))
|
61
|
+
raise(
|
62
|
+
ArgumentError,
|
63
|
+
"The input argument (attributes) must be a hash in `Algolia::TaskUpdateV1` initialize method"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
68
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
69
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
70
|
+
raise(
|
71
|
+
ArgumentError,
|
72
|
+
"`#{k}` is not a valid attribute in `Algolia::TaskUpdateV1`. Please check the name to make sure it's valid. List of attributes: " +
|
73
|
+
self.class.attribute_map.keys.inspect
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
h[k.to_sym] = v
|
78
|
+
}
|
79
|
+
|
80
|
+
if attributes.key?(:destination_id)
|
81
|
+
self.destination_id = attributes[:destination_id]
|
82
|
+
end
|
83
|
+
|
84
|
+
if attributes.key?(:trigger)
|
85
|
+
self.trigger = attributes[:trigger]
|
86
|
+
end
|
87
|
+
|
88
|
+
if attributes.key?(:input)
|
89
|
+
self.input = attributes[:input]
|
90
|
+
end
|
91
|
+
|
92
|
+
if attributes.key?(:enabled)
|
93
|
+
self.enabled = attributes[:enabled]
|
94
|
+
end
|
95
|
+
|
96
|
+
if attributes.key?(:failure_threshold)
|
97
|
+
self.failure_threshold = attributes[:failure_threshold]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Custom attribute writer method with validation
|
102
|
+
# @param [Object] failure_threshold Value to be assigned
|
103
|
+
def failure_threshold=(failure_threshold)
|
104
|
+
if failure_threshold.nil?
|
105
|
+
raise ArgumentError, "failure_threshold cannot be nil"
|
106
|
+
end
|
107
|
+
|
108
|
+
if failure_threshold > 100
|
109
|
+
raise ArgumentError, "invalid value for \"failure_threshold\", must be smaller than or equal to 100."
|
110
|
+
end
|
111
|
+
|
112
|
+
if failure_threshold < 0
|
113
|
+
raise ArgumentError, "invalid value for \"failure_threshold\", must be greater than or equal to 0."
|
114
|
+
end
|
115
|
+
|
116
|
+
@failure_threshold = failure_threshold
|
117
|
+
end
|
118
|
+
|
119
|
+
# Checks equality by comparing each attribute.
|
120
|
+
# @param [Object] Object to be compared
|
121
|
+
def ==(other)
|
122
|
+
return true if self.equal?(other)
|
123
|
+
self.class == other.class &&
|
124
|
+
destination_id == other.destination_id &&
|
125
|
+
trigger == other.trigger &&
|
126
|
+
input == other.input &&
|
127
|
+
enabled == other.enabled &&
|
128
|
+
failure_threshold == other.failure_threshold
|
129
|
+
end
|
130
|
+
|
131
|
+
# @see the `==` method
|
132
|
+
# @param [Object] Object to be compared
|
133
|
+
def eql?(other)
|
134
|
+
self == other
|
135
|
+
end
|
136
|
+
|
137
|
+
# Calculates hash code according to all attributes.
|
138
|
+
# @return [Integer] Hash code
|
139
|
+
def hash
|
140
|
+
[destination_id, trigger, input, enabled, failure_threshold].hash
|
141
|
+
end
|
142
|
+
|
143
|
+
# Builds the object from hash
|
144
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
145
|
+
# @return [Object] Returns the model itself
|
146
|
+
def self.build_from_hash(attributes)
|
147
|
+
return nil unless attributes.is_a?(Hash)
|
148
|
+
attributes = attributes.transform_keys(&:to_sym)
|
149
|
+
transformed_hash = {}
|
150
|
+
types_mapping.each_pair do |key, type|
|
151
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
152
|
+
transformed_hash[key.to_sym] = nil
|
153
|
+
elsif type =~ /\AArray<(.*)>/i
|
154
|
+
# check to ensure the input is an array given that the attribute
|
155
|
+
# is documented as an array but the input is not
|
156
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
157
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
158
|
+
_deserialize(::Regexp.last_match(1), v)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
elsif !attributes[attribute_map[key]].nil?
|
162
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
new(transformed_hash)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Deserializes the data based on type
|
170
|
+
# @param string type Data type
|
171
|
+
# @param string value Value to be deserialized
|
172
|
+
# @return [Object] Deserialized data
|
173
|
+
def self._deserialize(type, value)
|
174
|
+
case type.to_sym
|
175
|
+
when :Time
|
176
|
+
Time.parse(value)
|
177
|
+
when :Date
|
178
|
+
Date.parse(value)
|
179
|
+
when :String
|
180
|
+
value.to_s
|
181
|
+
when :Integer
|
182
|
+
value.to_i
|
183
|
+
when :Float
|
184
|
+
value.to_f
|
185
|
+
when :Boolean
|
186
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
187
|
+
true
|
188
|
+
else
|
189
|
+
false
|
190
|
+
end
|
191
|
+
|
192
|
+
when :Object
|
193
|
+
# generic object (usually a Hash), return directly
|
194
|
+
value
|
195
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
196
|
+
inner_type = Regexp.last_match[:inner_type]
|
197
|
+
value.map { |v| _deserialize(inner_type, v) }
|
198
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
199
|
+
k_type = Regexp.last_match[:k_type]
|
200
|
+
v_type = Regexp.last_match[:v_type]
|
201
|
+
{}.tap do |hash|
|
202
|
+
value.each do |k, v|
|
203
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
# model
|
207
|
+
else
|
208
|
+
# models (e.g. Pet) or oneOf
|
209
|
+
klass = Algolia::Ingestion.const_get(type)
|
210
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
211
|
+
.build_from_hash(value)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# Returns the string representation of the object
|
216
|
+
# @return [String] String presentation of the object
|
217
|
+
def to_s
|
218
|
+
to_hash.to_s
|
219
|
+
end
|
220
|
+
|
221
|
+
# to_body is an alias to to_hash (backward compatibility)
|
222
|
+
# @return [Hash] Returns the object in the form of hash
|
223
|
+
def to_body
|
224
|
+
to_hash
|
225
|
+
end
|
226
|
+
|
227
|
+
def to_json(*_args)
|
228
|
+
to_hash.to_json
|
229
|
+
end
|
230
|
+
|
231
|
+
# Returns the object in the form of hash
|
232
|
+
# @return [Hash] Returns the object in the form of hash
|
233
|
+
def to_hash
|
234
|
+
hash = {}
|
235
|
+
self.class.attribute_map.each_pair do |attr, param|
|
236
|
+
value = send(attr)
|
237
|
+
if value.nil?
|
238
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
239
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
240
|
+
end
|
241
|
+
|
242
|
+
hash[param] = _to_hash(value)
|
243
|
+
end
|
244
|
+
|
245
|
+
hash
|
246
|
+
end
|
247
|
+
|
248
|
+
# Outputs non-array value in the form of hash
|
249
|
+
# For object, use to_hash. Otherwise, just return the value
|
250
|
+
# @param [Object] value Any valid value
|
251
|
+
# @return [Hash] Returns the value in the form of hash
|
252
|
+
def _to_hash(value)
|
253
|
+
if value.is_a?(Array)
|
254
|
+
value.compact.map { |v| _to_hash(v) }
|
255
|
+
elsif value.is_a?(Hash)
|
256
|
+
{}.tap do |hash|
|
257
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
258
|
+
end
|
259
|
+
elsif value.respond_to?(:to_hash)
|
260
|
+
value.to_hash
|
261
|
+
else
|
262
|
+
value
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
end
|