carbon_ruby_sdk 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +57 -3
  4. data/lib/carbon_ruby_sdk/api/files_api.rb +6 -6
  5. data/lib/carbon_ruby_sdk/api/integrations_api.rb +104 -8
  6. data/lib/carbon_ruby_sdk/models/authentication_property.rb +436 -0
  7. data/lib/carbon_ruby_sdk/models/confluence_authentication.rb +254 -0
  8. data/lib/carbon_ruby_sdk/models/connect_data_source_input.rb +229 -0
  9. data/lib/carbon_ruby_sdk/models/connect_data_source_response.rb +230 -0
  10. data/lib/carbon_ruby_sdk/models/freskdesk_authentication.rb +244 -0
  11. data/lib/carbon_ruby_sdk/models/gitbook_authetication.rb +244 -0
  12. data/lib/carbon_ruby_sdk/models/notion_authentication.rb +244 -0
  13. data/lib/carbon_ruby_sdk/models/o_auth_authentication.rb +244 -0
  14. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +1 -0
  15. data/lib/carbon_ruby_sdk/models/organization_user_data_source_api.rb +11 -1
  16. data/lib/carbon_ruby_sdk/models/s3_authentication.rb +244 -0
  17. data/lib/carbon_ruby_sdk/models/s3_file_sync_input.rb +1 -0
  18. data/lib/carbon_ruby_sdk/models/salesforce_authentication.rb +254 -0
  19. data/lib/carbon_ruby_sdk/models/sharepoint_authentication.rb +268 -0
  20. data/lib/carbon_ruby_sdk/models/simple_o_auth_data_sources.rb +41 -0
  21. data/lib/carbon_ruby_sdk/models/sitemap_scrape_request.rb +15 -0
  22. data/lib/carbon_ruby_sdk/models/sync_files_request.rb +1 -0
  23. data/lib/carbon_ruby_sdk/models/sync_options.rb +323 -0
  24. data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +1 -0
  25. data/lib/carbon_ruby_sdk/models/webscrape_request.rb +30 -0
  26. data/lib/carbon_ruby_sdk/models/zendesk_authentication.rb +244 -0
  27. data/lib/carbon_ruby_sdk/models/zotero_authentication.rb +272 -0
  28. data/lib/carbon_ruby_sdk/version.rb +1 -1
  29. data/lib/carbon_ruby_sdk.rb +15 -0
  30. data/spec/api/files_api_spec.rb +1 -1
  31. data/spec/api/integrations_api_spec.rb +11 -0
  32. data/spec/models/authentication_property_spec.rb +112 -0
  33. data/spec/models/confluence_authentication_spec.rb +46 -0
  34. data/spec/models/connect_data_source_input_spec.rb +34 -0
  35. data/spec/models/connect_data_source_response_spec.rb +34 -0
  36. data/spec/models/freskdesk_authentication_spec.rb +40 -0
  37. data/spec/models/gitbook_authetication_spec.rb +40 -0
  38. data/spec/models/notion_authentication_spec.rb +40 -0
  39. data/spec/models/o_auth_authentication_spec.rb +40 -0
  40. data/spec/models/organization_user_data_source_api_spec.rb +6 -0
  41. data/spec/models/s3_authentication_spec.rb +40 -0
  42. data/spec/models/salesforce_authentication_spec.rb +46 -0
  43. data/spec/models/sharepoint_authentication_spec.rb +52 -0
  44. data/spec/models/simple_o_auth_data_sources_spec.rb +22 -0
  45. data/spec/models/sync_options_spec.rb +82 -0
  46. data/spec/models/zendesk_authentication_spec.rb +40 -0
  47. data/spec/models/zotero_authentication_spec.rb +52 -0
  48. metadata +47 -2
@@ -0,0 +1,436 @@
1
+ =begin
2
+ #Carbon
3
+
4
+ #Connect external data to LLMs, no matter the source.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ =end
8
+
9
+ require 'date'
10
+ require 'time'
11
+
12
+ module Carbon
13
+ class AuthenticationProperty
14
+ attr_accessor :source
15
+
16
+ attr_accessor :access_token
17
+
18
+ attr_accessor :refresh_token
19
+
20
+ attr_accessor :workspace_id
21
+
22
+ attr_accessor :tenant_name
23
+
24
+ attr_accessor :site_name
25
+
26
+ attr_accessor :subdomain
27
+
28
+ attr_accessor :access_token_secret
29
+
30
+ attr_accessor :username
31
+
32
+ attr_accessor :zotero_id
33
+
34
+ attr_accessor :organization_name
35
+
36
+ attr_accessor :domain
37
+
38
+ attr_accessor :api_key
39
+
40
+ attr_accessor :access_key
41
+
42
+ attr_accessor :access_key_secret
43
+
44
+ # Attribute mapping from ruby-style variable name to JSON key.
45
+ def self.attribute_map
46
+ {
47
+ :'source' => :'source',
48
+ :'access_token' => :'access_token',
49
+ :'refresh_token' => :'refresh_token',
50
+ :'workspace_id' => :'workspace_id',
51
+ :'tenant_name' => :'tenant_name',
52
+ :'site_name' => :'site_name',
53
+ :'subdomain' => :'subdomain',
54
+ :'access_token_secret' => :'access_token_secret',
55
+ :'username' => :'username',
56
+ :'zotero_id' => :'zotero_id',
57
+ :'organization_name' => :'organization_name',
58
+ :'domain' => :'domain',
59
+ :'api_key' => :'api_key',
60
+ :'access_key' => :'access_key',
61
+ :'access_key_secret' => :'access_key_secret'
62
+ }
63
+ end
64
+
65
+ # Returns all the JSON keys this model knows about
66
+ def self.acceptable_attributes
67
+ attribute_map.values
68
+ end
69
+
70
+ # Attribute type mapping.
71
+ def self.openapi_types
72
+ {
73
+ :'source' => :'Object',
74
+ :'access_token' => :'String',
75
+ :'refresh_token' => :'String',
76
+ :'workspace_id' => :'String',
77
+ :'tenant_name' => :'String',
78
+ :'site_name' => :'String',
79
+ :'subdomain' => :'String',
80
+ :'access_token_secret' => :'String',
81
+ :'username' => :'String',
82
+ :'zotero_id' => :'String',
83
+ :'organization_name' => :'String',
84
+ :'domain' => :'String',
85
+ :'api_key' => :'String',
86
+ :'access_key' => :'String',
87
+ :'access_key_secret' => :'String'
88
+ }
89
+ end
90
+
91
+ # List of attributes with nullable: true
92
+ def self.openapi_nullable
93
+ Set.new([
94
+ :'source',
95
+ :'refresh_token',
96
+ ])
97
+ end
98
+
99
+ # List of class defined in anyOf (OpenAPI v3)
100
+ def self.openapi_any_of
101
+ [
102
+ :'ConfluenceAuthentication',
103
+ :'FreskdeskAuthentication',
104
+ :'GitbookAuthetication',
105
+ :'NotionAuthentication',
106
+ :'OAuthAuthentication',
107
+ :'S3Authentication',
108
+ :'SalesforceAuthentication',
109
+ :'SharepointAuthentication',
110
+ :'ZendeskAuthentication',
111
+ :'ZoteroAuthentication'
112
+ ]
113
+ end
114
+
115
+ # Initializes the object
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ def initialize(attributes = {})
118
+ if (!attributes.is_a?(Hash))
119
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::AuthenticationProperty` initialize method"
120
+ end
121
+
122
+ # check to see if the attribute exists and convert string to symbol for hash key
123
+ attributes = attributes.each_with_object({}) { |(k, v), h|
124
+ if (!self.class.attribute_map.key?(k.to_sym))
125
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::AuthenticationProperty`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
126
+ end
127
+ h[k.to_sym] = v
128
+ }
129
+
130
+ if attributes.key?(:'source')
131
+ self.source = attributes[:'source']
132
+ end
133
+
134
+ if attributes.key?(:'access_token')
135
+ self.access_token = attributes[:'access_token']
136
+ end
137
+
138
+ if attributes.key?(:'refresh_token')
139
+ self.refresh_token = attributes[:'refresh_token']
140
+ end
141
+
142
+ if attributes.key?(:'workspace_id')
143
+ self.workspace_id = attributes[:'workspace_id']
144
+ end
145
+
146
+ if attributes.key?(:'tenant_name')
147
+ self.tenant_name = attributes[:'tenant_name']
148
+ end
149
+
150
+ if attributes.key?(:'site_name')
151
+ self.site_name = attributes[:'site_name']
152
+ end
153
+
154
+ if attributes.key?(:'subdomain')
155
+ self.subdomain = attributes[:'subdomain']
156
+ end
157
+
158
+ if attributes.key?(:'access_token_secret')
159
+ self.access_token_secret = attributes[:'access_token_secret']
160
+ end
161
+
162
+ if attributes.key?(:'username')
163
+ self.username = attributes[:'username']
164
+ end
165
+
166
+ if attributes.key?(:'zotero_id')
167
+ self.zotero_id = attributes[:'zotero_id']
168
+ end
169
+
170
+ if attributes.key?(:'organization_name')
171
+ self.organization_name = attributes[:'organization_name']
172
+ end
173
+
174
+ if attributes.key?(:'domain')
175
+ self.domain = attributes[:'domain']
176
+ end
177
+
178
+ if attributes.key?(:'api_key')
179
+ self.api_key = attributes[:'api_key']
180
+ end
181
+
182
+ if attributes.key?(:'access_key')
183
+ self.access_key = attributes[:'access_key']
184
+ end
185
+
186
+ if attributes.key?(:'access_key_secret')
187
+ self.access_key_secret = attributes[:'access_key_secret']
188
+ end
189
+ end
190
+
191
+ # Show invalid properties with the reasons. Usually used together with valid?
192
+ # @return Array for valid properties with the reasons
193
+ def list_invalid_properties
194
+ invalid_properties = Array.new
195
+ if @access_token.nil?
196
+ invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
197
+ end
198
+
199
+ if @workspace_id.nil?
200
+ invalid_properties.push('invalid value for "workspace_id", workspace_id cannot be nil.')
201
+ end
202
+
203
+ if @tenant_name.nil?
204
+ invalid_properties.push('invalid value for "tenant_name", tenant_name cannot be nil.')
205
+ end
206
+
207
+ if @site_name.nil?
208
+ invalid_properties.push('invalid value for "site_name", site_name cannot be nil.')
209
+ end
210
+
211
+ if @subdomain.nil?
212
+ invalid_properties.push('invalid value for "subdomain", subdomain cannot be nil.')
213
+ end
214
+
215
+ if @access_token_secret.nil?
216
+ invalid_properties.push('invalid value for "access_token_secret", access_token_secret cannot be nil.')
217
+ end
218
+
219
+ if @username.nil?
220
+ invalid_properties.push('invalid value for "username", username cannot be nil.')
221
+ end
222
+
223
+ if @zotero_id.nil?
224
+ invalid_properties.push('invalid value for "zotero_id", zotero_id cannot be nil.')
225
+ end
226
+
227
+ if @organization_name.nil?
228
+ invalid_properties.push('invalid value for "organization_name", organization_name cannot be nil.')
229
+ end
230
+
231
+ if @domain.nil?
232
+ invalid_properties.push('invalid value for "domain", domain cannot be nil.')
233
+ end
234
+
235
+ if @api_key.nil?
236
+ invalid_properties.push('invalid value for "api_key", api_key cannot be nil.')
237
+ end
238
+
239
+ if @access_key.nil?
240
+ invalid_properties.push('invalid value for "access_key", access_key cannot be nil.')
241
+ end
242
+
243
+ if @access_key_secret.nil?
244
+ invalid_properties.push('invalid value for "access_key_secret", access_key_secret cannot be nil.')
245
+ end
246
+
247
+ invalid_properties
248
+ end
249
+
250
+ # Check to see if the all the properties in the model are valid
251
+ # @return true if the model is valid
252
+ def valid?
253
+ return false if @access_token.nil?
254
+ return false if @workspace_id.nil?
255
+ return false if @tenant_name.nil?
256
+ return false if @site_name.nil?
257
+ return false if @subdomain.nil?
258
+ return false if @access_token_secret.nil?
259
+ return false if @username.nil?
260
+ return false if @zotero_id.nil?
261
+ return false if @organization_name.nil?
262
+ return false if @domain.nil?
263
+ return false if @api_key.nil?
264
+ return false if @access_key.nil?
265
+ return false if @access_key_secret.nil?
266
+ _any_of_found = false
267
+ self.class.openapi_any_of.each do |_class|
268
+ _any_of = Carbon.const_get(_class).build_from_hash(self.to_hash)
269
+ if _any_of.valid?
270
+ _any_of_found = true
271
+ end
272
+ end
273
+
274
+ if !_any_of_found
275
+ return false
276
+ end
277
+
278
+ true
279
+ end
280
+
281
+ # Checks equality by comparing each attribute.
282
+ # @param [Object] Object to be compared
283
+ def ==(o)
284
+ return true if self.equal?(o)
285
+ self.class == o.class &&
286
+ source == o.source &&
287
+ access_token == o.access_token &&
288
+ refresh_token == o.refresh_token &&
289
+ workspace_id == o.workspace_id &&
290
+ tenant_name == o.tenant_name &&
291
+ site_name == o.site_name &&
292
+ subdomain == o.subdomain &&
293
+ access_token_secret == o.access_token_secret &&
294
+ username == o.username &&
295
+ zotero_id == o.zotero_id &&
296
+ organization_name == o.organization_name &&
297
+ domain == o.domain &&
298
+ api_key == o.api_key &&
299
+ access_key == o.access_key &&
300
+ access_key_secret == o.access_key_secret
301
+ end
302
+
303
+ # @see the `==` method
304
+ # @param [Object] Object to be compared
305
+ def eql?(o)
306
+ self == o
307
+ end
308
+
309
+ # Calculates hash code according to all attributes.
310
+ # @return [Integer] Hash code
311
+ def hash
312
+ [source, access_token, refresh_token, workspace_id, tenant_name, site_name, subdomain, access_token_secret, username, zotero_id, organization_name, domain, api_key, access_key, access_key_secret].hash
313
+ end
314
+
315
+ # Builds the object from hash
316
+ # @param [Hash] attributes Model attributes in the form of hash
317
+ # @return [Object] Returns the model itself
318
+ def self.build_from_hash(attributes)
319
+ new.build_from_hash(attributes)
320
+ end
321
+
322
+ # Builds the object from hash
323
+ # @param [Hash] attributes Model attributes in the form of hash
324
+ # @return [Object] Returns the model itself
325
+ def build_from_hash(attributes)
326
+ return nil unless attributes.is_a?(Hash)
327
+ attributes = attributes.transform_keys(&:to_sym)
328
+ self.class.openapi_types.each_pair do |key, type|
329
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
330
+ self.send("#{key}=", nil)
331
+ elsif type =~ /\AArray<(.*)>/i
332
+ # check to ensure the input is an array given that the attribute
333
+ # is documented as an array but the input is not
334
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
335
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
336
+ end
337
+ elsif !attributes[self.class.attribute_map[key]].nil?
338
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
339
+ end
340
+ end
341
+
342
+ self
343
+ end
344
+
345
+ # Deserializes the data based on type
346
+ # @param string type Data type
347
+ # @param string value Value to be deserialized
348
+ # @return [Object] Deserialized data
349
+ def _deserialize(type, value)
350
+ case type.to_sym
351
+ when :Time
352
+ Time.parse(value)
353
+ when :Date
354
+ Date.parse(value)
355
+ when :String
356
+ value.to_s
357
+ when :Integer
358
+ value.to_i
359
+ when :Float
360
+ value.to_f
361
+ when :Boolean
362
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
363
+ true
364
+ else
365
+ false
366
+ end
367
+ when :Object
368
+ # generic object (usually a Hash), return directly
369
+ value
370
+ when /\AArray<(?<inner_type>.+)>\z/
371
+ inner_type = Regexp.last_match[:inner_type]
372
+ value.map { |v| _deserialize(inner_type, v) }
373
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
374
+ k_type = Regexp.last_match[:k_type]
375
+ v_type = Regexp.last_match[:v_type]
376
+ {}.tap do |hash|
377
+ value.each do |k, v|
378
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
379
+ end
380
+ end
381
+ else # model
382
+ # models (e.g. Pet) or oneOf
383
+ klass = Carbon.const_get(type)
384
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
385
+ end
386
+ end
387
+
388
+ # Returns the string representation of the object
389
+ # @return [String] String presentation of the object
390
+ def to_s
391
+ to_hash.to_s
392
+ end
393
+
394
+ # to_body is an alias to to_hash (backward compatibility)
395
+ # @return [Hash] Returns the object in the form of hash
396
+ def to_body
397
+ to_hash
398
+ end
399
+
400
+ # Returns the object in the form of hash
401
+ # @return [Hash] Returns the object in the form of hash
402
+ def to_hash
403
+ hash = {}
404
+ self.class.attribute_map.each_pair do |attr, param|
405
+ value = self.send(attr)
406
+ if value.nil?
407
+ is_nullable = self.class.openapi_nullable.include?(attr)
408
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
409
+ end
410
+
411
+ hash[param] = _to_hash(value)
412
+ end
413
+ hash
414
+ end
415
+
416
+ # Outputs non-array value in the form of hash
417
+ # For object, use to_hash. Otherwise, just return the value
418
+ # @param [Object] value Any valid value
419
+ # @return [Hash] Returns the value in the form of hash
420
+ def _to_hash(value)
421
+ if value.is_a?(Array)
422
+ value.compact.map { |v| _to_hash(v) }
423
+ elsif value.is_a?(Hash)
424
+ {}.tap do |hash|
425
+ value.each { |k, v| hash[k] = _to_hash(v) }
426
+ end
427
+ elsif value.respond_to? :to_hash
428
+ value.to_hash
429
+ else
430
+ value
431
+ end
432
+ end
433
+
434
+ end
435
+
436
+ end
@@ -0,0 +1,254 @@
1
+ =begin
2
+ #Carbon
3
+
4
+ #Connect external data to LLMs, no matter the source.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ =end
8
+
9
+ require 'date'
10
+ require 'time'
11
+
12
+ module Carbon
13
+ class ConfluenceAuthentication
14
+ attr_accessor :source
15
+
16
+ attr_accessor :access_token
17
+
18
+ attr_accessor :refresh_token
19
+
20
+ attr_accessor :subdomain
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'source' => :'source',
26
+ :'access_token' => :'access_token',
27
+ :'refresh_token' => :'refresh_token',
28
+ :'subdomain' => :'subdomain'
29
+ }
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'source' => :'Object',
41
+ :'access_token' => :'String',
42
+ :'refresh_token' => :'String',
43
+ :'subdomain' => :'String'
44
+ }
45
+ end
46
+
47
+ # List of attributes with nullable: true
48
+ def self.openapi_nullable
49
+ Set.new([
50
+ :'source',
51
+ :'refresh_token',
52
+ ])
53
+ end
54
+
55
+ # Initializes the object
56
+ # @param [Hash] attributes Model attributes in the form of hash
57
+ def initialize(attributes = {})
58
+ if (!attributes.is_a?(Hash))
59
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ConfluenceAuthentication` initialize method"
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
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ConfluenceAuthentication`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
66
+ end
67
+ h[k.to_sym] = v
68
+ }
69
+
70
+ if attributes.key?(:'source')
71
+ self.source = attributes[:'source']
72
+ end
73
+
74
+ if attributes.key?(:'access_token')
75
+ self.access_token = attributes[:'access_token']
76
+ end
77
+
78
+ if attributes.key?(:'refresh_token')
79
+ self.refresh_token = attributes[:'refresh_token']
80
+ end
81
+
82
+ if attributes.key?(:'subdomain')
83
+ self.subdomain = attributes[:'subdomain']
84
+ end
85
+ end
86
+
87
+ # Show invalid properties with the reasons. Usually used together with valid?
88
+ # @return Array for valid properties with the reasons
89
+ def list_invalid_properties
90
+ invalid_properties = Array.new
91
+ if @access_token.nil?
92
+ invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
93
+ end
94
+
95
+ if @subdomain.nil?
96
+ invalid_properties.push('invalid value for "subdomain", subdomain cannot be nil.')
97
+ end
98
+
99
+ invalid_properties
100
+ end
101
+
102
+ # Check to see if the all the properties in the model are valid
103
+ # @return true if the model is valid
104
+ def valid?
105
+ return false if @access_token.nil?
106
+ return false if @subdomain.nil?
107
+ true
108
+ end
109
+
110
+ # Checks equality by comparing each attribute.
111
+ # @param [Object] Object to be compared
112
+ def ==(o)
113
+ return true if self.equal?(o)
114
+ self.class == o.class &&
115
+ source == o.source &&
116
+ access_token == o.access_token &&
117
+ refresh_token == o.refresh_token &&
118
+ subdomain == o.subdomain
119
+ end
120
+
121
+ # @see the `==` method
122
+ # @param [Object] Object to be compared
123
+ def eql?(o)
124
+ self == o
125
+ end
126
+
127
+ # Calculates hash code according to all attributes.
128
+ # @return [Integer] Hash code
129
+ def hash
130
+ [source, access_token, refresh_token, subdomain].hash
131
+ end
132
+
133
+ # Builds the object from hash
134
+ # @param [Hash] attributes Model attributes in the form of hash
135
+ # @return [Object] Returns the model itself
136
+ def self.build_from_hash(attributes)
137
+ new.build_from_hash(attributes)
138
+ end
139
+
140
+ # Builds the object from hash
141
+ # @param [Hash] attributes Model attributes in the form of hash
142
+ # @return [Object] Returns the model itself
143
+ def build_from_hash(attributes)
144
+ return nil unless attributes.is_a?(Hash)
145
+ attributes = attributes.transform_keys(&:to_sym)
146
+ self.class.openapi_types.each_pair do |key, type|
147
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
148
+ self.send("#{key}=", nil)
149
+ elsif type =~ /\AArray<(.*)>/i
150
+ # check to ensure the input is an array given that the attribute
151
+ # is documented as an array but the input is not
152
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
153
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
154
+ end
155
+ elsif !attributes[self.class.attribute_map[key]].nil?
156
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
157
+ end
158
+ end
159
+
160
+ self
161
+ end
162
+
163
+ # Deserializes the data based on type
164
+ # @param string type Data type
165
+ # @param string value Value to be deserialized
166
+ # @return [Object] Deserialized data
167
+ def _deserialize(type, value)
168
+ case type.to_sym
169
+ when :Time
170
+ Time.parse(value)
171
+ when :Date
172
+ Date.parse(value)
173
+ when :String
174
+ value.to_s
175
+ when :Integer
176
+ value.to_i
177
+ when :Float
178
+ value.to_f
179
+ when :Boolean
180
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
181
+ true
182
+ else
183
+ false
184
+ end
185
+ when :Object
186
+ # generic object (usually a Hash), return directly
187
+ value
188
+ when /\AArray<(?<inner_type>.+)>\z/
189
+ inner_type = Regexp.last_match[:inner_type]
190
+ value.map { |v| _deserialize(inner_type, v) }
191
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
192
+ k_type = Regexp.last_match[:k_type]
193
+ v_type = Regexp.last_match[:v_type]
194
+ {}.tap do |hash|
195
+ value.each do |k, v|
196
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
197
+ end
198
+ end
199
+ else # model
200
+ # models (e.g. Pet) or oneOf
201
+ klass = Carbon.const_get(type)
202
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
203
+ end
204
+ end
205
+
206
+ # Returns the string representation of the object
207
+ # @return [String] String presentation of the object
208
+ def to_s
209
+ to_hash.to_s
210
+ end
211
+
212
+ # to_body is an alias to to_hash (backward compatibility)
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_body
215
+ to_hash
216
+ end
217
+
218
+ # Returns the object in the form of hash
219
+ # @return [Hash] Returns the object in the form of hash
220
+ def to_hash
221
+ hash = {}
222
+ self.class.attribute_map.each_pair do |attr, param|
223
+ value = self.send(attr)
224
+ if value.nil?
225
+ is_nullable = self.class.openapi_nullable.include?(attr)
226
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
227
+ end
228
+
229
+ hash[param] = _to_hash(value)
230
+ end
231
+ hash
232
+ end
233
+
234
+ # Outputs non-array value in the form of hash
235
+ # For object, use to_hash. Otherwise, just return the value
236
+ # @param [Object] value Any valid value
237
+ # @return [Hash] Returns the value in the form of hash
238
+ def _to_hash(value)
239
+ if value.is_a?(Array)
240
+ value.compact.map { |v| _to_hash(v) }
241
+ elsif value.is_a?(Hash)
242
+ {}.tap do |hash|
243
+ value.each { |k, v| hash[k] = _to_hash(v) }
244
+ end
245
+ elsif value.respond_to? :to_hash
246
+ value.to_hash
247
+ else
248
+ value
249
+ end
250
+ end
251
+
252
+ end
253
+
254
+ end