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