lingara 0.1.0.pre.alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +142 -0
  4. data/lib/lingara/access_token.rb +47 -0
  5. data/lib/lingara/client.rb +182 -0
  6. data/lib/lingara/client_credentials.rb +176 -0
  7. data/lib/lingara/deprecation.rb +128 -0
  8. data/lib/lingara/errors.rb +162 -0
  9. data/lib/lingara/event_stream.rb +135 -0
  10. data/lib/lingara/models/allowance_row.rb +378 -0
  11. data/lib/lingara/models/create_lesson_plan_event_error.rb +287 -0
  12. data/lib/lingara/models/create_lesson_plan_event_phase.rb +287 -0
  13. data/lib/lingara/models/create_lesson_plan_event_result.rb +287 -0
  14. data/lib/lingara/models/create_lesson_plan_event_started.rb +287 -0
  15. data/lib/lingara/models/error_envelope.rb +264 -0
  16. data/lib/lingara/models/generate_vocabulary_event_done.rb +287 -0
  17. data/lib/lingara/models/generate_vocabulary_event_error.rb +287 -0
  18. data/lib/lingara/models/generate_vocabulary_event_item.rb +287 -0
  19. data/lib/lingara/models/generate_vocabulary_event_started.rb +287 -0
  20. data/lib/lingara/models/lesson_plan.rb +463 -0
  21. data/lib/lingara/models/lesson_plan_content.rb +305 -0
  22. data/lib/lingara/models/lesson_plan_create_request.rb +333 -0
  23. data/lib/lingara/models/notice.rb +263 -0
  24. data/lib/lingara/models/plan_pending.rb +285 -0
  25. data/lib/lingara/models/plan_phase.rb +281 -0
  26. data/lib/lingara/models/plan_question.rb +337 -0
  27. data/lib/lingara/models/plan_result.rb +237 -0
  28. data/lib/lingara/models/plan_set.rb +293 -0
  29. data/lib/lingara/models/plan_started.rb +237 -0
  30. data/lib/lingara/models/plan_status.rb +42 -0
  31. data/lib/lingara/models/plan_word.rb +273 -0
  32. data/lib/lingara/models/send_tutor_message_event_delta.rb +287 -0
  33. data/lib/lingara/models/send_tutor_message_event_done.rb +287 -0
  34. data/lib/lingara/models/send_tutor_message_event_error.rb +287 -0
  35. data/lib/lingara/models/send_tutor_message_event_notice.rb +287 -0
  36. data/lib/lingara/models/stream_error.rb +273 -0
  37. data/lib/lingara/models/stream_lesson_plan_event_error.rb +287 -0
  38. data/lib/lingara/models/stream_lesson_plan_event_pending.rb +287 -0
  39. data/lib/lingara/models/stream_lesson_plan_event_phase.rb +287 -0
  40. data/lib/lingara/models/stream_lesson_plan_event_result.rb +287 -0
  41. data/lib/lingara/models/stream_lesson_plan_event_started.rb +287 -0
  42. data/lib/lingara/models/turn_delta.rb +237 -0
  43. data/lib/lingara/models/turn_entry.rb +285 -0
  44. data/lib/lingara/models/turn_role.rb +41 -0
  45. data/lib/lingara/models/tutor_turn_request.rb +354 -0
  46. data/lib/lingara/models/usage.rb +250 -0
  47. data/lib/lingara/models/usage_ledger.rb +307 -0
  48. data/lib/lingara/models/version_detail.rb +415 -0
  49. data/lib/lingara/models/version_history_entry.rb +285 -0
  50. data/lib/lingara/models/version_list.rb +263 -0
  51. data/lib/lingara/models/version_spec.rb +249 -0
  52. data/lib/lingara/models/version_state.rb +44 -0
  53. data/lib/lingara/models/version_summary.rb +349 -0
  54. data/lib/lingara/models/vocab_example.rb +263 -0
  55. data/lib/lingara/models/vocab_item.rb +303 -0
  56. data/lib/lingara/models/vocab_meta.rb +394 -0
  57. data/lib/lingara/models/vocab_request.rb +341 -0
  58. data/lib/lingara/models/vocab_started.rb +237 -0
  59. data/lib/lingara/operations.rb +91 -0
  60. data/lib/lingara/response.rb +46 -0
  61. data/lib/lingara/retry.rb +88 -0
  62. data/lib/lingara/sse_decoder.rb +80 -0
  63. data/lib/lingara/streams.rb +104 -0
  64. data/lib/lingara/transport.rb +131 -0
  65. data/lib/lingara/user_agent.rb +24 -0
  66. data/lib/lingara/version.rb +13 -0
  67. data/lib/lingara.rb +23 -0
  68. data/sig/lingara.rbs +151 -0
  69. metadata +114 -0
@@ -0,0 +1,307 @@
1
+ =begin
2
+ #Lingara API
3
+
4
+ #Generate vocabulary lists and lesson plans, and hold tutor conversations, in the languages Lingara teaches. Each call is paid for by the client that makes it: an `allowance` client spends its owner's allowance, and a `metered` client is billed for its usage.
5
+
6
+ The version of the OpenAPI document: 2026-09-glowing-hoatzin
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.14.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Lingara
17
+ class UsageLedger
18
+ attr_accessor :since
19
+
20
+ attr_accessor :calls
21
+
22
+ attr_accessor :units
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'since' => :'since',
28
+ :'calls' => :'calls',
29
+ :'units' => :'units'
30
+ }
31
+ end
32
+
33
+ # Returns attribute mapping this model knows about
34
+ def self.acceptable_attribute_map
35
+ attribute_map
36
+ end
37
+
38
+ # Returns all the JSON keys this model knows about
39
+ def self.acceptable_attributes
40
+ acceptable_attribute_map.values
41
+ end
42
+
43
+ # Attribute type mapping.
44
+ def self.openapi_types
45
+ {
46
+ :'since' => :'Time',
47
+ :'calls' => :'Integer',
48
+ :'units' => :'Integer'
49
+ }
50
+ end
51
+
52
+ # List of attributes with nullable: true
53
+ def self.openapi_nullable
54
+ Set.new([
55
+ ])
56
+ end
57
+
58
+ # Initializes the object
59
+ # @param [Hash] attributes Model attributes in the form of hash
60
+ def initialize(attributes = {})
61
+ if (!attributes.is_a?(Hash))
62
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Lingara::UsageLedger` initialize method"
63
+ end
64
+
65
+ # check to see if the attribute exists and convert string to symbol for hash key
66
+ acceptable_attribute_map = self.class.acceptable_attribute_map
67
+ attributes = attributes.each_with_object({}) { |(k, v), h|
68
+ if (!acceptable_attribute_map.key?(k.to_sym))
69
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Lingara::UsageLedger`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
70
+ end
71
+ h[k.to_sym] = v
72
+ }
73
+
74
+ if attributes.key?(:'since')
75
+ self.since = attributes[:'since']
76
+ else
77
+ self.since = nil
78
+ end
79
+
80
+ if attributes.key?(:'calls')
81
+ self.calls = attributes[:'calls']
82
+ else
83
+ self.calls = nil
84
+ end
85
+
86
+ if attributes.key?(:'units')
87
+ self.units = attributes[:'units']
88
+ else
89
+ self.units = nil
90
+ end
91
+ end
92
+
93
+ # Show invalid properties with the reasons. Usually used together with valid?
94
+ # @return Array for valid properties with the reasons
95
+ def list_invalid_properties
96
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
97
+ invalid_properties = Array.new
98
+ if @since.nil?
99
+ invalid_properties.push('invalid value for "since", since cannot be nil.')
100
+ end
101
+
102
+ if @calls.nil?
103
+ invalid_properties.push('invalid value for "calls", calls cannot be nil.')
104
+ end
105
+
106
+ if @calls < 0
107
+ invalid_properties.push('invalid value for "calls", must be greater than or equal to 0.')
108
+ end
109
+
110
+ if @units.nil?
111
+ invalid_properties.push('invalid value for "units", units cannot be nil.')
112
+ end
113
+
114
+ if @units < 0
115
+ invalid_properties.push('invalid value for "units", must be greater than or equal to 0.')
116
+ end
117
+
118
+ invalid_properties
119
+ end
120
+
121
+ # Check to see if the all the properties in the model are valid
122
+ # @return true if the model is valid
123
+ def valid?
124
+ warn '[DEPRECATED] the `valid?` method is obsolete'
125
+ return false if @since.nil?
126
+ return false if @calls.nil?
127
+ return false if @calls < 0
128
+ return false if @units.nil?
129
+ return false if @units < 0
130
+ true
131
+ end
132
+
133
+ # Custom attribute writer method with validation
134
+ # @param [Object] since Value to be assigned
135
+ def since=(since)
136
+ if since.nil?
137
+ fail ArgumentError, 'since cannot be nil'
138
+ end
139
+
140
+ @since = since
141
+ end
142
+
143
+ # Custom attribute writer method with validation
144
+ # @param [Object] calls Value to be assigned
145
+ def calls=(calls)
146
+ if calls.nil?
147
+ fail ArgumentError, 'calls cannot be nil'
148
+ end
149
+
150
+ if calls < 0
151
+ fail ArgumentError, 'invalid value for "calls", must be greater than or equal to 0.'
152
+ end
153
+
154
+ @calls = calls
155
+ end
156
+
157
+ # Custom attribute writer method with validation
158
+ # @param [Object] units Value to be assigned
159
+ def units=(units)
160
+ if units.nil?
161
+ fail ArgumentError, 'units cannot be nil'
162
+ end
163
+
164
+ if units < 0
165
+ fail ArgumentError, 'invalid value for "units", must be greater than or equal to 0.'
166
+ end
167
+
168
+ @units = units
169
+ end
170
+
171
+ # Checks equality by comparing each attribute.
172
+ # @param [Object] Object to be compared
173
+ def ==(o)
174
+ return true if self.equal?(o)
175
+ self.class == o.class &&
176
+ since == o.since &&
177
+ calls == o.calls &&
178
+ units == o.units
179
+ end
180
+
181
+ # @see the `==` method
182
+ # @param [Object] Object to be compared
183
+ def eql?(o)
184
+ self == o
185
+ end
186
+
187
+ # Calculates hash code according to all attributes.
188
+ # @return [Integer] Hash code
189
+ def hash
190
+ [since, calls, units].hash
191
+ end
192
+
193
+ # Builds the object from hash
194
+ # @param [Hash] attributes Model attributes in the form of hash
195
+ # @return [Object] Returns the model itself
196
+ def self.build_from_hash(attributes)
197
+ return nil unless attributes.is_a?(Hash)
198
+ attributes = attributes.transform_keys(&:to_sym)
199
+ transformed_hash = {}
200
+ openapi_types.each_pair do |key, type|
201
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
202
+ transformed_hash["#{key}"] = nil
203
+ elsif type =~ /\AArray<(.*)>/i
204
+ # check to ensure the input is an array given that the attribute
205
+ # is documented as an array but the input is not
206
+ if attributes[attribute_map[key]].is_a?(Array)
207
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
208
+ end
209
+ elsif !attributes[attribute_map[key]].nil?
210
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
211
+ end
212
+ end
213
+ new(transformed_hash)
214
+ end
215
+
216
+ # Deserializes the data based on type
217
+ # @param string type Data type
218
+ # @param string value Value to be deserialized
219
+ # @return [Object] Deserialized data
220
+ def self._deserialize(type, value)
221
+ case type.to_sym
222
+ when :Time
223
+ Time.parse(value)
224
+ when :Date
225
+ Date.parse(value)
226
+ when :String
227
+ value.to_s
228
+ when :Integer
229
+ value.to_i
230
+ when :Float
231
+ value.to_f
232
+ when :Boolean
233
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
234
+ true
235
+ else
236
+ false
237
+ end
238
+ when :Object
239
+ # generic object (usually a Hash), return directly
240
+ value
241
+ when /\AArray<(?<inner_type>.+)>\z/
242
+ inner_type = Regexp.last_match[:inner_type]
243
+ value.map { |v| _deserialize(inner_type, v) }
244
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
245
+ k_type = Regexp.last_match[:k_type]
246
+ v_type = Regexp.last_match[:v_type]
247
+ {}.tap do |hash|
248
+ value.each do |k, v|
249
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
250
+ end
251
+ end
252
+ else # model
253
+ # models (e.g. Pet) or oneOf
254
+ klass = Lingara.const_get(type)
255
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
256
+ end
257
+ end
258
+
259
+ # Returns the string representation of the object
260
+ # @return [String] String presentation of the object
261
+ def to_s
262
+ to_hash.to_s
263
+ end
264
+
265
+ # to_body is an alias to to_hash (backward compatibility)
266
+ # @return [Hash] Returns the object in the form of hash
267
+ def to_body
268
+ to_hash
269
+ end
270
+
271
+ # Returns the object in the form of hash
272
+ # @return [Hash] Returns the object in the form of hash
273
+ def to_hash
274
+ hash = {}
275
+ self.class.attribute_map.each_pair do |attr, param|
276
+ value = self.send(attr)
277
+ if value.nil?
278
+ is_nullable = self.class.openapi_nullable.include?(attr)
279
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
280
+ end
281
+
282
+ hash[param] = _to_hash(value)
283
+ end
284
+ hash
285
+ end
286
+
287
+ # Outputs non-array value in the form of hash
288
+ # For object, use to_hash. Otherwise, just return the value
289
+ # @param [Object] value Any valid value
290
+ # @return [Hash] Returns the value in the form of hash
291
+ def _to_hash(value)
292
+ if value.is_a?(Array)
293
+ value.compact.map { |v| _to_hash(v) }
294
+ elsif value.is_a?(Hash)
295
+ {}.tap do |hash|
296
+ value.each { |k, v| hash[k] = _to_hash(v) }
297
+ end
298
+ elsif value.respond_to? :to_hash
299
+ value.to_hash
300
+ else
301
+ value
302
+ end
303
+ end
304
+
305
+ end
306
+
307
+ end
@@ -0,0 +1,415 @@
1
+ =begin
2
+ #Lingara API
3
+
4
+ #Generate vocabulary lists and lesson plans, and hold tutor conversations, in the languages Lingara teaches. Each call is paid for by the client that makes it: an `allowance` client spends its owner's allowance, and a `metered` client is billed for its usage.
5
+
6
+ The version of the OpenAPI document: 2026-09-glowing-hoatzin
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.14.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Lingara
17
+ class VersionDetail
18
+ attr_accessor :id
19
+
20
+ attr_accessor :state
21
+
22
+ attr_accessor :lts
23
+
24
+ attr_accessor :minted_at
25
+
26
+ attr_accessor :sunset_at
27
+
28
+ attr_accessor :summary
29
+
30
+ attr_accessor :history
31
+
32
+ attr_accessor :spec
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
56
+ # Attribute mapping from ruby-style variable name to JSON key.
57
+ def self.attribute_map
58
+ {
59
+ :'id' => :'id',
60
+ :'state' => :'state',
61
+ :'lts' => :'lts',
62
+ :'minted_at' => :'minted_at',
63
+ :'sunset_at' => :'sunset_at',
64
+ :'summary' => :'summary',
65
+ :'history' => :'history',
66
+ :'spec' => :'spec'
67
+ }
68
+ end
69
+
70
+ # Returns attribute mapping this model knows about
71
+ def self.acceptable_attribute_map
72
+ attribute_map
73
+ end
74
+
75
+ # Returns all the JSON keys this model knows about
76
+ def self.acceptable_attributes
77
+ acceptable_attribute_map.values
78
+ end
79
+
80
+ # Attribute type mapping.
81
+ def self.openapi_types
82
+ {
83
+ :'id' => :'String',
84
+ :'state' => :'VersionState',
85
+ :'lts' => :'Boolean',
86
+ :'minted_at' => :'Time',
87
+ :'sunset_at' => :'Time',
88
+ :'summary' => :'String',
89
+ :'history' => :'Array<VersionHistoryEntry>',
90
+ :'spec' => :'VersionSpec'
91
+ }
92
+ end
93
+
94
+ # List of attributes with nullable: true
95
+ def self.openapi_nullable
96
+ Set.new([
97
+ :'sunset_at',
98
+ :'summary',
99
+ ])
100
+ end
101
+
102
+ # Initializes the object
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ def initialize(attributes = {})
105
+ if (!attributes.is_a?(Hash))
106
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Lingara::VersionDetail` initialize method"
107
+ end
108
+
109
+ # check to see if the attribute exists and convert string to symbol for hash key
110
+ acceptable_attribute_map = self.class.acceptable_attribute_map
111
+ attributes = attributes.each_with_object({}) { |(k, v), h|
112
+ if (!acceptable_attribute_map.key?(k.to_sym))
113
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Lingara::VersionDetail`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
114
+ end
115
+ h[k.to_sym] = v
116
+ }
117
+
118
+ if attributes.key?(:'id')
119
+ self.id = attributes[:'id']
120
+ else
121
+ self.id = nil
122
+ end
123
+
124
+ if attributes.key?(:'state')
125
+ self.state = attributes[:'state']
126
+ else
127
+ self.state = nil
128
+ end
129
+
130
+ if attributes.key?(:'lts')
131
+ self.lts = attributes[:'lts']
132
+ else
133
+ self.lts = nil
134
+ end
135
+
136
+ if attributes.key?(:'minted_at')
137
+ self.minted_at = attributes[:'minted_at']
138
+ else
139
+ self.minted_at = nil
140
+ end
141
+
142
+ if attributes.key?(:'sunset_at')
143
+ self.sunset_at = attributes[:'sunset_at']
144
+ else
145
+ self.sunset_at = nil
146
+ end
147
+
148
+ if attributes.key?(:'summary')
149
+ self.summary = attributes[:'summary']
150
+ else
151
+ self.summary = nil
152
+ end
153
+
154
+ if attributes.key?(:'history')
155
+ if (value = attributes[:'history']).is_a?(Array)
156
+ self.history = value
157
+ end
158
+ else
159
+ self.history = nil
160
+ end
161
+
162
+ if attributes.key?(:'spec')
163
+ self.spec = attributes[:'spec']
164
+ else
165
+ self.spec = nil
166
+ end
167
+ end
168
+
169
+ # Show invalid properties with the reasons. Usually used together with valid?
170
+ # @return Array for valid properties with the reasons
171
+ def list_invalid_properties
172
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
173
+ invalid_properties = Array.new
174
+ if @id.nil?
175
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
176
+ end
177
+
178
+ if @state.nil?
179
+ invalid_properties.push('invalid value for "state", state cannot be nil.')
180
+ end
181
+
182
+ if @lts.nil?
183
+ invalid_properties.push('invalid value for "lts", lts cannot be nil.')
184
+ end
185
+
186
+ if @minted_at.nil?
187
+ invalid_properties.push('invalid value for "minted_at", minted_at cannot be nil.')
188
+ end
189
+
190
+ if @history.nil?
191
+ invalid_properties.push('invalid value for "history", history cannot be nil.')
192
+ end
193
+
194
+ if @spec.nil?
195
+ invalid_properties.push('invalid value for "spec", spec cannot be nil.')
196
+ end
197
+
198
+ invalid_properties
199
+ end
200
+
201
+ # Check to see if the all the properties in the model are valid
202
+ # @return true if the model is valid
203
+ def valid?
204
+ warn '[DEPRECATED] the `valid?` method is obsolete'
205
+ return false if @id.nil?
206
+ return false if @state.nil?
207
+ return false if @lts.nil?
208
+ return false if @minted_at.nil?
209
+ return false if @history.nil?
210
+ return false if @spec.nil?
211
+ true
212
+ end
213
+
214
+ # Custom attribute writer method with validation
215
+ # @param [Object] id Value to be assigned
216
+ def id=(id)
217
+ if id.nil?
218
+ fail ArgumentError, 'id cannot be nil'
219
+ end
220
+
221
+ @id = id
222
+ end
223
+
224
+ # Custom attribute writer method with validation
225
+ # @param [Object] state Value to be assigned
226
+ def state=(state)
227
+ if state.nil?
228
+ fail ArgumentError, 'state cannot be nil'
229
+ end
230
+
231
+ @state = state
232
+ end
233
+
234
+ # Custom attribute writer method with validation
235
+ # @param [Object] lts Value to be assigned
236
+ def lts=(lts)
237
+ if lts.nil?
238
+ fail ArgumentError, 'lts cannot be nil'
239
+ end
240
+
241
+ @lts = lts
242
+ end
243
+
244
+ # Custom attribute writer method with validation
245
+ # @param [Object] minted_at Value to be assigned
246
+ def minted_at=(minted_at)
247
+ if minted_at.nil?
248
+ fail ArgumentError, 'minted_at cannot be nil'
249
+ end
250
+
251
+ @minted_at = minted_at
252
+ end
253
+
254
+ # Custom attribute writer method with validation
255
+ # @param [Object] history Value to be assigned
256
+ def history=(history)
257
+ if history.nil?
258
+ fail ArgumentError, 'history cannot be nil'
259
+ end
260
+
261
+ @history = history
262
+ end
263
+
264
+ # Custom attribute writer method with validation
265
+ # @param [Object] spec Value to be assigned
266
+ def spec=(spec)
267
+ if spec.nil?
268
+ fail ArgumentError, 'spec cannot be nil'
269
+ end
270
+
271
+ @spec = spec
272
+ end
273
+
274
+ # Checks equality by comparing each attribute.
275
+ # @param [Object] Object to be compared
276
+ def ==(o)
277
+ return true if self.equal?(o)
278
+ self.class == o.class &&
279
+ id == o.id &&
280
+ state == o.state &&
281
+ lts == o.lts &&
282
+ minted_at == o.minted_at &&
283
+ sunset_at == o.sunset_at &&
284
+ summary == o.summary &&
285
+ history == o.history &&
286
+ spec == o.spec
287
+ end
288
+
289
+ # @see the `==` method
290
+ # @param [Object] Object to be compared
291
+ def eql?(o)
292
+ self == o
293
+ end
294
+
295
+ # Calculates hash code according to all attributes.
296
+ # @return [Integer] Hash code
297
+ def hash
298
+ [id, state, lts, minted_at, sunset_at, summary, history, spec].hash
299
+ end
300
+
301
+ # Builds the object from hash
302
+ # @param [Hash] attributes Model attributes in the form of hash
303
+ # @return [Object] Returns the model itself
304
+ def self.build_from_hash(attributes)
305
+ return nil unless attributes.is_a?(Hash)
306
+ attributes = attributes.transform_keys(&:to_sym)
307
+ transformed_hash = {}
308
+ openapi_types.each_pair do |key, type|
309
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
310
+ transformed_hash["#{key}"] = nil
311
+ elsif type =~ /\AArray<(.*)>/i
312
+ # check to ensure the input is an array given that the attribute
313
+ # is documented as an array but the input is not
314
+ if attributes[attribute_map[key]].is_a?(Array)
315
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
316
+ end
317
+ elsif !attributes[attribute_map[key]].nil?
318
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
319
+ end
320
+ end
321
+ new(transformed_hash)
322
+ end
323
+
324
+ # Deserializes the data based on type
325
+ # @param string type Data type
326
+ # @param string value Value to be deserialized
327
+ # @return [Object] Deserialized data
328
+ def self._deserialize(type, value)
329
+ case type.to_sym
330
+ when :Time
331
+ Time.parse(value)
332
+ when :Date
333
+ Date.parse(value)
334
+ when :String
335
+ value.to_s
336
+ when :Integer
337
+ value.to_i
338
+ when :Float
339
+ value.to_f
340
+ when :Boolean
341
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
342
+ true
343
+ else
344
+ false
345
+ end
346
+ when :Object
347
+ # generic object (usually a Hash), return directly
348
+ value
349
+ when /\AArray<(?<inner_type>.+)>\z/
350
+ inner_type = Regexp.last_match[:inner_type]
351
+ value.map { |v| _deserialize(inner_type, v) }
352
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
353
+ k_type = Regexp.last_match[:k_type]
354
+ v_type = Regexp.last_match[:v_type]
355
+ {}.tap do |hash|
356
+ value.each do |k, v|
357
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
358
+ end
359
+ end
360
+ else # model
361
+ # models (e.g. Pet) or oneOf
362
+ klass = Lingara.const_get(type)
363
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
364
+ end
365
+ end
366
+
367
+ # Returns the string representation of the object
368
+ # @return [String] String presentation of the object
369
+ def to_s
370
+ to_hash.to_s
371
+ end
372
+
373
+ # to_body is an alias to to_hash (backward compatibility)
374
+ # @return [Hash] Returns the object in the form of hash
375
+ def to_body
376
+ to_hash
377
+ end
378
+
379
+ # Returns the object in the form of hash
380
+ # @return [Hash] Returns the object in the form of hash
381
+ def to_hash
382
+ hash = {}
383
+ self.class.attribute_map.each_pair do |attr, param|
384
+ value = self.send(attr)
385
+ if value.nil?
386
+ is_nullable = self.class.openapi_nullable.include?(attr)
387
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
388
+ end
389
+
390
+ hash[param] = _to_hash(value)
391
+ end
392
+ hash
393
+ end
394
+
395
+ # Outputs non-array value in the form of hash
396
+ # For object, use to_hash. Otherwise, just return the value
397
+ # @param [Object] value Any valid value
398
+ # @return [Hash] Returns the value in the form of hash
399
+ def _to_hash(value)
400
+ if value.is_a?(Array)
401
+ value.compact.map { |v| _to_hash(v) }
402
+ elsif value.is_a?(Hash)
403
+ {}.tap do |hash|
404
+ value.each { |k, v| hash[k] = _to_hash(v) }
405
+ end
406
+ elsif value.respond_to? :to_hash
407
+ value.to_hash
408
+ else
409
+ value
410
+ end
411
+ end
412
+
413
+ end
414
+
415
+ end