carbon_ruby_sdk 0.1.5 → 0.1.7

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +100 -9
  4. data/lib/carbon_ruby_sdk/api/embeddings_api.rb +10 -2
  5. data/lib/carbon_ruby_sdk/api/files_api.rb +6 -2
  6. data/lib/carbon_ruby_sdk/api/integrations_api.rb +168 -19
  7. data/lib/carbon_ruby_sdk/models/authentication_property.rb +436 -0
  8. data/lib/carbon_ruby_sdk/models/chunks_and_embeddings.rb +1 -5
  9. data/lib/carbon_ruby_sdk/models/chunks_and_embeddings_upload_input.rb +24 -4
  10. data/lib/carbon_ruby_sdk/models/confluence_authentication.rb +254 -0
  11. data/lib/carbon_ruby_sdk/models/connect_data_source_input.rb +229 -0
  12. data/lib/carbon_ruby_sdk/models/connect_data_source_response.rb +230 -0
  13. data/lib/carbon_ruby_sdk/models/freskdesk_authentication.rb +244 -0
  14. data/lib/carbon_ruby_sdk/models/gitbook_authetication.rb +244 -0
  15. data/lib/carbon_ruby_sdk/models/gmail_sync_input.rb +15 -5
  16. data/lib/carbon_ruby_sdk/models/notion_authentication.rb +244 -0
  17. data/lib/carbon_ruby_sdk/models/o_auth_authentication.rb +244 -0
  18. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +29 -4
  19. data/lib/carbon_ruby_sdk/models/organization_user_data_source_api.rb +11 -1
  20. data/lib/carbon_ruby_sdk/models/outh_url_response.rb +220 -0
  21. data/lib/carbon_ruby_sdk/models/outlook_sync_input.rb +15 -5
  22. data/lib/carbon_ruby_sdk/models/resync_file_query_input.rb +16 -5
  23. data/lib/carbon_ruby_sdk/models/s3_authentication.rb +244 -0
  24. data/lib/carbon_ruby_sdk/models/s3_file_sync_input.rb +14 -4
  25. data/lib/carbon_ruby_sdk/models/salesforce_authentication.rb +254 -0
  26. data/lib/carbon_ruby_sdk/models/sharepoint_authentication.rb +268 -0
  27. data/lib/carbon_ruby_sdk/models/simple_o_auth_data_sources.rb +41 -0
  28. data/lib/carbon_ruby_sdk/models/sitemap_scrape_request.rb +15 -0
  29. data/lib/carbon_ruby_sdk/models/sync_options.rb +322 -0
  30. data/lib/carbon_ruby_sdk/models/webscrape_request.rb +30 -0
  31. data/lib/carbon_ruby_sdk/models/zendesk_authentication.rb +244 -0
  32. data/lib/carbon_ruby_sdk/models/zotero_authentication.rb +272 -0
  33. data/lib/carbon_ruby_sdk/version.rb +1 -1
  34. data/lib/carbon_ruby_sdk.rb +16 -0
  35. data/spec/api/integrations_api_spec.rb +16 -1
  36. data/spec/models/authentication_property_spec.rb +112 -0
  37. data/spec/models/chunks_and_embeddings_upload_input_spec.rb +12 -0
  38. data/spec/models/confluence_authentication_spec.rb +46 -0
  39. data/spec/models/connect_data_source_input_spec.rb +34 -0
  40. data/spec/models/connect_data_source_response_spec.rb +34 -0
  41. data/spec/models/freskdesk_authentication_spec.rb +40 -0
  42. data/spec/models/gitbook_authetication_spec.rb +40 -0
  43. data/spec/models/gmail_sync_input_spec.rb +6 -0
  44. data/spec/models/notion_authentication_spec.rb +40 -0
  45. data/spec/models/o_auth_authentication_spec.rb +40 -0
  46. data/spec/models/o_auth_url_request_spec.rb +12 -0
  47. data/spec/models/organization_user_data_source_api_spec.rb +6 -0
  48. data/spec/models/outh_url_response_spec.rb +28 -0
  49. data/spec/models/outlook_sync_input_spec.rb +6 -0
  50. data/spec/models/resync_file_query_input_spec.rb +6 -0
  51. data/spec/models/s3_authentication_spec.rb +40 -0
  52. data/spec/models/s3_file_sync_input_spec.rb +6 -0
  53. data/spec/models/salesforce_authentication_spec.rb +46 -0
  54. data/spec/models/sharepoint_authentication_spec.rb +52 -0
  55. data/spec/models/simple_o_auth_data_sources_spec.rb +22 -0
  56. data/spec/models/sync_options_spec.rb +82 -0
  57. data/spec/models/zendesk_authentication_spec.rb +40 -0
  58. data/spec/models/zotero_authentication_spec.rb +52 -0
  59. metadata +50 -2
@@ -0,0 +1,322 @@
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 SyncOptions
14
+ attr_accessor :tags
15
+
16
+ attr_accessor :chunk_size
17
+
18
+ attr_accessor :chunk_overlap
19
+
20
+ attr_accessor :skip_embedding_generation
21
+
22
+ attr_accessor :embedding_model
23
+
24
+ attr_accessor :generate_sparse_vectors
25
+
26
+ attr_accessor :prepend_filename_to_chunks
27
+
28
+ attr_accessor :max_items_per_chunk
29
+
30
+ # Used to specify whether Carbon should attempt to sync all your files automatically when authorization is complete. This is only supported for a subset of connectors and will be ignored for the rest. Supported connectors: Intercom, Zendesk, Gitbook, Confluence, Salesforce, Freshdesk
31
+ attr_accessor :sync_files_on_connection
32
+
33
+ attr_accessor :set_page_as_boundary
34
+
35
+ # Attribute mapping from ruby-style variable name to JSON key.
36
+ def self.attribute_map
37
+ {
38
+ :'tags' => :'tags',
39
+ :'chunk_size' => :'chunk_size',
40
+ :'chunk_overlap' => :'chunk_overlap',
41
+ :'skip_embedding_generation' => :'skip_embedding_generation',
42
+ :'embedding_model' => :'embedding_model',
43
+ :'generate_sparse_vectors' => :'generate_sparse_vectors',
44
+ :'prepend_filename_to_chunks' => :'prepend_filename_to_chunks',
45
+ :'max_items_per_chunk' => :'max_items_per_chunk',
46
+ :'sync_files_on_connection' => :'sync_files_on_connection',
47
+ :'set_page_as_boundary' => :'set_page_as_boundary'
48
+ }
49
+ end
50
+
51
+ # Returns all the JSON keys this model knows about
52
+ def self.acceptable_attributes
53
+ attribute_map.values
54
+ end
55
+
56
+ # Attribute type mapping.
57
+ def self.openapi_types
58
+ {
59
+ :'tags' => :'Object',
60
+ :'chunk_size' => :'Integer',
61
+ :'chunk_overlap' => :'Integer',
62
+ :'skip_embedding_generation' => :'Boolean',
63
+ :'embedding_model' => :'EmbeddingGeneratorsNullable',
64
+ :'generate_sparse_vectors' => :'Boolean',
65
+ :'prepend_filename_to_chunks' => :'Boolean',
66
+ :'max_items_per_chunk' => :'Integer',
67
+ :'sync_files_on_connection' => :'Boolean',
68
+ :'set_page_as_boundary' => :'Boolean'
69
+ }
70
+ end
71
+
72
+ # List of attributes with nullable: true
73
+ def self.openapi_nullable
74
+ Set.new([
75
+ :'tags',
76
+ :'chunk_size',
77
+ :'chunk_overlap',
78
+ :'skip_embedding_generation',
79
+ :'embedding_model',
80
+ :'generate_sparse_vectors',
81
+ :'prepend_filename_to_chunks',
82
+ :'max_items_per_chunk',
83
+ :'sync_files_on_connection',
84
+ ])
85
+ end
86
+
87
+ # Initializes the object
88
+ # @param [Hash] attributes Model attributes in the form of hash
89
+ def initialize(attributes = {})
90
+ if (!attributes.is_a?(Hash))
91
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::SyncOptions` initialize method"
92
+ end
93
+
94
+ # check to see if the attribute exists and convert string to symbol for hash key
95
+ attributes = attributes.each_with_object({}) { |(k, v), h|
96
+ if (!self.class.attribute_map.key?(k.to_sym))
97
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::SyncOptions`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
98
+ end
99
+ h[k.to_sym] = v
100
+ }
101
+
102
+ if attributes.key?(:'tags')
103
+ self.tags = attributes[:'tags']
104
+ end
105
+
106
+ if attributes.key?(:'chunk_size')
107
+ self.chunk_size = attributes[:'chunk_size']
108
+ else
109
+ self.chunk_size = 1500
110
+ end
111
+
112
+ if attributes.key?(:'chunk_overlap')
113
+ self.chunk_overlap = attributes[:'chunk_overlap']
114
+ else
115
+ self.chunk_overlap = 20
116
+ end
117
+
118
+ if attributes.key?(:'skip_embedding_generation')
119
+ self.skip_embedding_generation = attributes[:'skip_embedding_generation']
120
+ else
121
+ self.skip_embedding_generation = false
122
+ end
123
+
124
+ if attributes.key?(:'embedding_model')
125
+ self.embedding_model = attributes[:'embedding_model']
126
+ else
127
+ self.embedding_model = 'OPENAI'
128
+ end
129
+
130
+ if attributes.key?(:'generate_sparse_vectors')
131
+ self.generate_sparse_vectors = attributes[:'generate_sparse_vectors']
132
+ else
133
+ self.generate_sparse_vectors = false
134
+ end
135
+
136
+ if attributes.key?(:'prepend_filename_to_chunks')
137
+ self.prepend_filename_to_chunks = attributes[:'prepend_filename_to_chunks']
138
+ else
139
+ self.prepend_filename_to_chunks = false
140
+ end
141
+
142
+ if attributes.key?(:'max_items_per_chunk')
143
+ self.max_items_per_chunk = attributes[:'max_items_per_chunk']
144
+ end
145
+
146
+ if attributes.key?(:'sync_files_on_connection')
147
+ self.sync_files_on_connection = attributes[:'sync_files_on_connection']
148
+ else
149
+ self.sync_files_on_connection = true
150
+ end
151
+
152
+ if attributes.key?(:'set_page_as_boundary')
153
+ self.set_page_as_boundary = attributes[:'set_page_as_boundary']
154
+ else
155
+ self.set_page_as_boundary = false
156
+ end
157
+ end
158
+
159
+ # Show invalid properties with the reasons. Usually used together with valid?
160
+ # @return Array for valid properties with the reasons
161
+ def list_invalid_properties
162
+ invalid_properties = Array.new
163
+ invalid_properties
164
+ end
165
+
166
+ # Check to see if the all the properties in the model are valid
167
+ # @return true if the model is valid
168
+ def valid?
169
+ true
170
+ end
171
+
172
+ # Checks equality by comparing each attribute.
173
+ # @param [Object] Object to be compared
174
+ def ==(o)
175
+ return true if self.equal?(o)
176
+ self.class == o.class &&
177
+ tags == o.tags &&
178
+ chunk_size == o.chunk_size &&
179
+ chunk_overlap == o.chunk_overlap &&
180
+ skip_embedding_generation == o.skip_embedding_generation &&
181
+ embedding_model == o.embedding_model &&
182
+ generate_sparse_vectors == o.generate_sparse_vectors &&
183
+ prepend_filename_to_chunks == o.prepend_filename_to_chunks &&
184
+ max_items_per_chunk == o.max_items_per_chunk &&
185
+ sync_files_on_connection == o.sync_files_on_connection &&
186
+ set_page_as_boundary == o.set_page_as_boundary
187
+ end
188
+
189
+ # @see the `==` method
190
+ # @param [Object] Object to be compared
191
+ def eql?(o)
192
+ self == o
193
+ end
194
+
195
+ # Calculates hash code according to all attributes.
196
+ # @return [Integer] Hash code
197
+ def hash
198
+ [tags, chunk_size, chunk_overlap, skip_embedding_generation, embedding_model, generate_sparse_vectors, prepend_filename_to_chunks, max_items_per_chunk, sync_files_on_connection, set_page_as_boundary].hash
199
+ end
200
+
201
+ # Builds the object from hash
202
+ # @param [Hash] attributes Model attributes in the form of hash
203
+ # @return [Object] Returns the model itself
204
+ def self.build_from_hash(attributes)
205
+ new.build_from_hash(attributes)
206
+ end
207
+
208
+ # Builds the object from hash
209
+ # @param [Hash] attributes Model attributes in the form of hash
210
+ # @return [Object] Returns the model itself
211
+ def build_from_hash(attributes)
212
+ return nil unless attributes.is_a?(Hash)
213
+ attributes = attributes.transform_keys(&:to_sym)
214
+ self.class.openapi_types.each_pair do |key, type|
215
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
216
+ self.send("#{key}=", nil)
217
+ elsif type =~ /\AArray<(.*)>/i
218
+ # check to ensure the input is an array given that the attribute
219
+ # is documented as an array but the input is not
220
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
221
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
222
+ end
223
+ elsif !attributes[self.class.attribute_map[key]].nil?
224
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
225
+ end
226
+ end
227
+
228
+ self
229
+ end
230
+
231
+ # Deserializes the data based on type
232
+ # @param string type Data type
233
+ # @param string value Value to be deserialized
234
+ # @return [Object] Deserialized data
235
+ def _deserialize(type, value)
236
+ case type.to_sym
237
+ when :Time
238
+ Time.parse(value)
239
+ when :Date
240
+ Date.parse(value)
241
+ when :String
242
+ value.to_s
243
+ when :Integer
244
+ value.to_i
245
+ when :Float
246
+ value.to_f
247
+ when :Boolean
248
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
249
+ true
250
+ else
251
+ false
252
+ end
253
+ when :Object
254
+ # generic object (usually a Hash), return directly
255
+ value
256
+ when /\AArray<(?<inner_type>.+)>\z/
257
+ inner_type = Regexp.last_match[:inner_type]
258
+ value.map { |v| _deserialize(inner_type, v) }
259
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
260
+ k_type = Regexp.last_match[:k_type]
261
+ v_type = Regexp.last_match[:v_type]
262
+ {}.tap do |hash|
263
+ value.each do |k, v|
264
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
265
+ end
266
+ end
267
+ else # model
268
+ # models (e.g. Pet) or oneOf
269
+ klass = Carbon.const_get(type)
270
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.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
+ # Returns the object in the form of hash
287
+ # @return [Hash] Returns the object in the form of hash
288
+ def to_hash
289
+ hash = {}
290
+ self.class.attribute_map.each_pair do |attr, param|
291
+ value = self.send(attr)
292
+ if value.nil?
293
+ is_nullable = self.class.openapi_nullable.include?(attr)
294
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
295
+ end
296
+
297
+ hash[param] = _to_hash(value)
298
+ end
299
+ hash
300
+ end
301
+
302
+ # Outputs non-array value in the form of hash
303
+ # For object, use to_hash. Otherwise, just return the value
304
+ # @param [Object] value Any valid value
305
+ # @return [Hash] Returns the value in the form of hash
306
+ def _to_hash(value)
307
+ if value.is_a?(Array)
308
+ value.compact.map { |v| _to_hash(v) }
309
+ elsif value.is_a?(Hash)
310
+ {}.tap do |hash|
311
+ value.each { |k, v| hash[k] = _to_hash(v) }
312
+ end
313
+ elsif value.respond_to? :to_hash
314
+ value.to_hash
315
+ else
316
+ value
317
+ end
318
+ end
319
+
320
+ end
321
+
322
+ end
@@ -208,6 +208,14 @@ module Carbon
208
208
  invalid_properties.push('invalid value for "url", url cannot be nil.')
209
209
  end
210
210
 
211
+ if !@recursion_depth.nil? && @recursion_depth < 0
212
+ invalid_properties.push('invalid value for "recursion_depth", must be greater than or equal to 0.')
213
+ end
214
+
215
+ if !@max_pages_to_scrape.nil? && @max_pages_to_scrape < 1
216
+ invalid_properties.push('invalid value for "max_pages_to_scrape", must be greater than or equal to 1.')
217
+ end
218
+
211
219
  invalid_properties
212
220
  end
213
221
 
@@ -215,9 +223,31 @@ module Carbon
215
223
  # @return true if the model is valid
216
224
  def valid?
217
225
  return false if @url.nil?
226
+ return false if !@recursion_depth.nil? && @recursion_depth < 0
227
+ return false if !@max_pages_to_scrape.nil? && @max_pages_to_scrape < 1
218
228
  true
219
229
  end
220
230
 
231
+ # Custom attribute writer method with validation
232
+ # @param [Object] recursion_depth Value to be assigned
233
+ def recursion_depth=(recursion_depth)
234
+ if !recursion_depth.nil? && recursion_depth < 0
235
+ fail ArgumentError, 'invalid value for "recursion_depth", must be greater than or equal to 0.'
236
+ end
237
+
238
+ @recursion_depth = recursion_depth
239
+ end
240
+
241
+ # Custom attribute writer method with validation
242
+ # @param [Object] max_pages_to_scrape Value to be assigned
243
+ def max_pages_to_scrape=(max_pages_to_scrape)
244
+ if !max_pages_to_scrape.nil? && max_pages_to_scrape < 1
245
+ fail ArgumentError, 'invalid value for "max_pages_to_scrape", must be greater than or equal to 1.'
246
+ end
247
+
248
+ @max_pages_to_scrape = max_pages_to_scrape
249
+ end
250
+
221
251
  # Checks equality by comparing each attribute.
222
252
  # @param [Object] Object to be compared
223
253
  def ==(o)
@@ -0,0 +1,244 @@
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 ZendeskAuthentication
14
+ attr_accessor :source
15
+
16
+ attr_accessor :access_token
17
+
18
+ attr_accessor :subdomain
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'source' => :'source',
24
+ :'access_token' => :'access_token',
25
+ :'subdomain' => :'subdomain'
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :'source' => :'Object',
38
+ :'access_token' => :'String',
39
+ :'subdomain' => :'String'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ :'source',
47
+ ])
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ZendeskAuthentication` initialize method"
55
+ end
56
+
57
+ # check to see if the attribute exists and convert string to symbol for hash key
58
+ attributes = attributes.each_with_object({}) { |(k, v), h|
59
+ if (!self.class.attribute_map.key?(k.to_sym))
60
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ZendeskAuthentication`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
61
+ end
62
+ h[k.to_sym] = v
63
+ }
64
+
65
+ if attributes.key?(:'source')
66
+ self.source = attributes[:'source']
67
+ end
68
+
69
+ if attributes.key?(:'access_token')
70
+ self.access_token = attributes[:'access_token']
71
+ end
72
+
73
+ if attributes.key?(:'subdomain')
74
+ self.subdomain = attributes[:'subdomain']
75
+ end
76
+ end
77
+
78
+ # Show invalid properties with the reasons. Usually used together with valid?
79
+ # @return Array for valid properties with the reasons
80
+ def list_invalid_properties
81
+ invalid_properties = Array.new
82
+ if @access_token.nil?
83
+ invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
84
+ end
85
+
86
+ if @subdomain.nil?
87
+ invalid_properties.push('invalid value for "subdomain", subdomain cannot be nil.')
88
+ end
89
+
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ return false if @access_token.nil?
97
+ return false if @subdomain.nil?
98
+ true
99
+ end
100
+
101
+ # Checks equality by comparing each attribute.
102
+ # @param [Object] Object to be compared
103
+ def ==(o)
104
+ return true if self.equal?(o)
105
+ self.class == o.class &&
106
+ source == o.source &&
107
+ access_token == o.access_token &&
108
+ subdomain == o.subdomain
109
+ end
110
+
111
+ # @see the `==` method
112
+ # @param [Object] Object to be compared
113
+ def eql?(o)
114
+ self == o
115
+ end
116
+
117
+ # Calculates hash code according to all attributes.
118
+ # @return [Integer] Hash code
119
+ def hash
120
+ [source, access_token, subdomain].hash
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def self.build_from_hash(attributes)
127
+ new.build_from_hash(attributes)
128
+ end
129
+
130
+ # Builds the object from hash
131
+ # @param [Hash] attributes Model attributes in the form of hash
132
+ # @return [Object] Returns the model itself
133
+ def build_from_hash(attributes)
134
+ return nil unless attributes.is_a?(Hash)
135
+ attributes = attributes.transform_keys(&:to_sym)
136
+ self.class.openapi_types.each_pair do |key, type|
137
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
138
+ self.send("#{key}=", nil)
139
+ elsif type =~ /\AArray<(.*)>/i
140
+ # check to ensure the input is an array given that the attribute
141
+ # is documented as an array but the input is not
142
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
143
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
144
+ end
145
+ elsif !attributes[self.class.attribute_map[key]].nil?
146
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
147
+ end
148
+ end
149
+
150
+ self
151
+ end
152
+
153
+ # Deserializes the data based on type
154
+ # @param string type Data type
155
+ # @param string value Value to be deserialized
156
+ # @return [Object] Deserialized data
157
+ def _deserialize(type, value)
158
+ case type.to_sym
159
+ when :Time
160
+ Time.parse(value)
161
+ when :Date
162
+ Date.parse(value)
163
+ when :String
164
+ value.to_s
165
+ when :Integer
166
+ value.to_i
167
+ when :Float
168
+ value.to_f
169
+ when :Boolean
170
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
171
+ true
172
+ else
173
+ false
174
+ end
175
+ when :Object
176
+ # generic object (usually a Hash), return directly
177
+ value
178
+ when /\AArray<(?<inner_type>.+)>\z/
179
+ inner_type = Regexp.last_match[:inner_type]
180
+ value.map { |v| _deserialize(inner_type, v) }
181
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
182
+ k_type = Regexp.last_match[:k_type]
183
+ v_type = Regexp.last_match[:v_type]
184
+ {}.tap do |hash|
185
+ value.each do |k, v|
186
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
187
+ end
188
+ end
189
+ else # model
190
+ # models (e.g. Pet) or oneOf
191
+ klass = Carbon.const_get(type)
192
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
193
+ end
194
+ end
195
+
196
+ # Returns the string representation of the object
197
+ # @return [String] String presentation of the object
198
+ def to_s
199
+ to_hash.to_s
200
+ end
201
+
202
+ # to_body is an alias to to_hash (backward compatibility)
203
+ # @return [Hash] Returns the object in the form of hash
204
+ def to_body
205
+ to_hash
206
+ end
207
+
208
+ # Returns the object in the form of hash
209
+ # @return [Hash] Returns the object in the form of hash
210
+ def to_hash
211
+ hash = {}
212
+ self.class.attribute_map.each_pair do |attr, param|
213
+ value = self.send(attr)
214
+ if value.nil?
215
+ is_nullable = self.class.openapi_nullable.include?(attr)
216
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
217
+ end
218
+
219
+ hash[param] = _to_hash(value)
220
+ end
221
+ hash
222
+ end
223
+
224
+ # Outputs non-array value in the form of hash
225
+ # For object, use to_hash. Otherwise, just return the value
226
+ # @param [Object] value Any valid value
227
+ # @return [Hash] Returns the value in the form of hash
228
+ def _to_hash(value)
229
+ if value.is_a?(Array)
230
+ value.compact.map { |v| _to_hash(v) }
231
+ elsif value.is_a?(Hash)
232
+ {}.tap do |hash|
233
+ value.each { |k, v| hash[k] = _to_hash(v) }
234
+ end
235
+ elsif value.respond_to? :to_hash
236
+ value.to_hash
237
+ else
238
+ value
239
+ end
240
+ end
241
+
242
+ end
243
+
244
+ end