carbon_ruby_sdk 0.2.20 → 0.2.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -4
  3. data/README.md +107 -2
  4. data/lib/carbon_ruby_sdk/api/embeddings_api.rb +6 -2
  5. data/lib/carbon_ruby_sdk/api/files_api.rb +231 -6
  6. data/lib/carbon_ruby_sdk/api/integrations_api.rb +6 -2
  7. data/lib/carbon_ruby_sdk/models/cold_storage_props.rb +229 -0
  8. data/lib/carbon_ruby_sdk/models/embedding_storage_status.rb +38 -0
  9. data/lib/carbon_ruby_sdk/models/file_sync_config.rb +13 -1
  10. data/lib/carbon_ruby_sdk/models/file_sync_config_nullable.rb +13 -1
  11. data/lib/carbon_ruby_sdk/models/get_embedding_documents_body.rb +17 -5
  12. data/lib/carbon_ruby_sdk/models/modify_cold_storage_parameters_query_input.rb +235 -0
  13. data/lib/carbon_ruby_sdk/models/move_to_hot_storage_query_input.rb +215 -0
  14. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +16 -5
  15. data/lib/carbon_ruby_sdk/models/raw_text_input.rb +14 -5
  16. data/lib/carbon_ruby_sdk/models/sent_webhook_payload.rb +2 -2
  17. data/lib/carbon_ruby_sdk/models/sync_options.rb +16 -5
  18. data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +24 -4
  19. data/lib/carbon_ruby_sdk/models/user_file.rb +39 -1
  20. data/lib/carbon_ruby_sdk/version.rb +1 -1
  21. data/lib/carbon_ruby_sdk.rb +4 -0
  22. data/spec/api/files_api_spec.rb +25 -0
  23. data/spec/models/cold_storage_props_spec.rb +34 -0
  24. data/spec/models/embedding_storage_status_spec.rb +22 -0
  25. data/spec/models/file_sync_config_nullable_spec.rb +6 -0
  26. data/spec/models/file_sync_config_spec.rb +6 -0
  27. data/spec/models/get_embedding_documents_body_spec.rb +6 -0
  28. data/spec/models/modify_cold_storage_parameters_query_input_spec.rb +40 -0
  29. data/spec/models/move_to_hot_storage_query_input_spec.rb +28 -0
  30. data/spec/models/o_auth_url_request_spec.rb +6 -0
  31. data/spec/models/raw_text_input_spec.rb +6 -0
  32. data/spec/models/sent_webhook_payload_spec.rb +1 -1
  33. data/spec/models/sync_options_spec.rb +6 -0
  34. data/spec/models/upload_file_from_url_input_spec.rb +12 -0
  35. data/spec/models/user_file_spec.rb +18 -0
  36. metadata +14 -2
@@ -0,0 +1,38 @@
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 EmbeddingStorageStatus
14
+ HOT_STORAGE = "HOT_STORAGE".freeze
15
+ HOT_TO_COLD = "HOT_TO_COLD".freeze
16
+ COLD_STORAGE = "COLD_STORAGE".freeze
17
+ COLD_TO_HOT = "COLD_TO_HOT".freeze
18
+
19
+ def self.all_vars
20
+ @all_vars ||= [HOT_STORAGE, HOT_TO_COLD, COLD_STORAGE, COLD_TO_HOT].freeze
21
+ end
22
+
23
+ # Builds the enum from string
24
+ # @param [String] The enum value in the form of the string
25
+ # @return [String] The enum value
26
+ def self.build_from_hash(value)
27
+ new.build_from_hash(value)
28
+ end
29
+
30
+ # Builds the enum from string
31
+ # @param [String] The enum value in the form of the string
32
+ # @return [String] The enum value
33
+ def build_from_hash(value)
34
+ return value if EmbeddingStorageStatus.all_vars.include?(value)
35
+ raise "Invalid ENUM value #{value} for class #EmbeddingStorageStatus"
36
+ end
37
+ end
38
+ end
@@ -22,6 +22,9 @@ module Carbon
22
22
 
23
23
  attr_accessor :transcription_service
24
24
 
25
+ # Detect multiple speakers and label segments of speech by speaker for audio files.
26
+ attr_accessor :include_speaker_labels
27
+
25
28
  # Whether to split tabular rows into chunks. Currently only valid for CSV, TSV, and XLSX files.
26
29
  attr_accessor :split_rows
27
30
 
@@ -32,6 +35,7 @@ module Carbon
32
35
  :'sync_attachments' => :'sync_attachments',
33
36
  :'detect_audio_language' => :'detect_audio_language',
34
37
  :'transcription_service' => :'transcription_service',
38
+ :'include_speaker_labels' => :'include_speaker_labels',
35
39
  :'split_rows' => :'split_rows'
36
40
  }
37
41
  end
@@ -48,6 +52,7 @@ module Carbon
48
52
  :'sync_attachments' => :'Boolean',
49
53
  :'detect_audio_language' => :'Boolean',
50
54
  :'transcription_service' => :'TranscriptionServiceNullable',
55
+ :'include_speaker_labels' => :'Boolean',
51
56
  :'split_rows' => :'Boolean'
52
57
  }
53
58
  end
@@ -96,6 +101,12 @@ module Carbon
96
101
  self.transcription_service = attributes[:'transcription_service']
97
102
  end
98
103
 
104
+ if attributes.key?(:'include_speaker_labels')
105
+ self.include_speaker_labels = attributes[:'include_speaker_labels']
106
+ else
107
+ self.include_speaker_labels = false
108
+ end
109
+
99
110
  if attributes.key?(:'split_rows')
100
111
  self.split_rows = attributes[:'split_rows']
101
112
  else
@@ -125,6 +136,7 @@ module Carbon
125
136
  sync_attachments == o.sync_attachments &&
126
137
  detect_audio_language == o.detect_audio_language &&
127
138
  transcription_service == o.transcription_service &&
139
+ include_speaker_labels == o.include_speaker_labels &&
128
140
  split_rows == o.split_rows
129
141
  end
130
142
 
@@ -137,7 +149,7 @@ module Carbon
137
149
  # Calculates hash code according to all attributes.
138
150
  # @return [Integer] Hash code
139
151
  def hash
140
- [auto_synced_source_types, sync_attachments, detect_audio_language, transcription_service, split_rows].hash
152
+ [auto_synced_source_types, sync_attachments, detect_audio_language, transcription_service, include_speaker_labels, split_rows].hash
141
153
  end
142
154
 
143
155
  # Builds the object from hash
@@ -23,6 +23,9 @@ module Carbon
23
23
 
24
24
  attr_accessor :transcription_service
25
25
 
26
+ # Detect multiple speakers and label segments of speech by speaker for audio files.
27
+ attr_accessor :include_speaker_labels
28
+
26
29
  # Whether to split tabular rows into chunks. Currently only valid for CSV, TSV, and XLSX files.
27
30
  attr_accessor :split_rows
28
31
 
@@ -33,6 +36,7 @@ module Carbon
33
36
  :'sync_attachments' => :'sync_attachments',
34
37
  :'detect_audio_language' => :'detect_audio_language',
35
38
  :'transcription_service' => :'transcription_service',
39
+ :'include_speaker_labels' => :'include_speaker_labels',
36
40
  :'split_rows' => :'split_rows'
37
41
  }
38
42
  end
@@ -49,6 +53,7 @@ module Carbon
49
53
  :'sync_attachments' => :'Boolean',
50
54
  :'detect_audio_language' => :'Boolean',
51
55
  :'transcription_service' => :'TranscriptionServiceNullable',
56
+ :'include_speaker_labels' => :'Boolean',
52
57
  :'split_rows' => :'Boolean'
53
58
  }
54
59
  end
@@ -97,6 +102,12 @@ module Carbon
97
102
  self.transcription_service = attributes[:'transcription_service']
98
103
  end
99
104
 
105
+ if attributes.key?(:'include_speaker_labels')
106
+ self.include_speaker_labels = attributes[:'include_speaker_labels']
107
+ else
108
+ self.include_speaker_labels = false
109
+ end
110
+
100
111
  if attributes.key?(:'split_rows')
101
112
  self.split_rows = attributes[:'split_rows']
102
113
  else
@@ -126,6 +137,7 @@ module Carbon
126
137
  sync_attachments == o.sync_attachments &&
127
138
  detect_audio_language == o.detect_audio_language &&
128
139
  transcription_service == o.transcription_service &&
140
+ include_speaker_labels == o.include_speaker_labels &&
129
141
  split_rows == o.split_rows
130
142
  end
131
143
 
@@ -138,7 +150,7 @@ module Carbon
138
150
  # Calculates hash code according to all attributes.
139
151
  # @return [Integer] Hash code
140
152
  def hash
141
- [auto_synced_source_types, sync_attachments, detect_audio_language, transcription_service, split_rows].hash
153
+ [auto_synced_source_types, sync_attachments, detect_audio_language, transcription_service, include_speaker_labels, split_rows].hash
142
154
  end
143
155
 
144
156
  # Builds the object from hash
@@ -64,6 +64,9 @@ module Carbon
64
64
  # Filter files based on their type at the source (for example help center tickets and articles)
65
65
  attr_accessor :file_types_at_source
66
66
 
67
+ # Flag to control whether or not to exclude files that are not in hot storage. If set to False, then an error will be returned if any filtered files are in cold storage.
68
+ attr_accessor :exclude_cold_storage_files
69
+
67
70
  # Attribute mapping from ruby-style variable name to JSON key.
68
71
  def self.attribute_map
69
72
  {
@@ -85,7 +88,8 @@ module Carbon
85
88
  :'include_file_level_metadata' => :'include_file_level_metadata',
86
89
  :'high_accuracy' => :'high_accuracy',
87
90
  :'rerank' => :'rerank',
88
- :'file_types_at_source' => :'file_types_at_source'
91
+ :'file_types_at_source' => :'file_types_at_source',
92
+ :'exclude_cold_storage_files' => :'exclude_cold_storage_files'
89
93
  }
90
94
  end
91
95
 
@@ -115,7 +119,8 @@ module Carbon
115
119
  :'include_file_level_metadata' => :'Boolean',
116
120
  :'high_accuracy' => :'Boolean',
117
121
  :'rerank' => :'RerankParamsNullable',
118
- :'file_types_at_source' => :'Array<HelpdeskFileTypes>'
122
+ :'file_types_at_source' => :'Array<HelpdeskFileTypes>',
123
+ :'exclude_cold_storage_files' => :'Boolean'
119
124
  }
120
125
  end
121
126
 
@@ -137,7 +142,7 @@ module Carbon
137
142
  :'include_file_level_metadata',
138
143
  :'high_accuracy',
139
144
  :'rerank',
140
- :'file_types_at_source'
145
+ :'file_types_at_source',
141
146
  ])
142
147
  end
143
148
 
@@ -249,6 +254,12 @@ module Carbon
249
254
  self.file_types_at_source = value
250
255
  end
251
256
  end
257
+
258
+ if attributes.key?(:'exclude_cold_storage_files')
259
+ self.exclude_cold_storage_files = attributes[:'exclude_cold_storage_files']
260
+ else
261
+ self.exclude_cold_storage_files = false
262
+ end
252
263
  end
253
264
 
254
265
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -335,7 +346,8 @@ module Carbon
335
346
  include_file_level_metadata == o.include_file_level_metadata &&
336
347
  high_accuracy == o.high_accuracy &&
337
348
  rerank == o.rerank &&
338
- file_types_at_source == o.file_types_at_source
349
+ file_types_at_source == o.file_types_at_source &&
350
+ exclude_cold_storage_files == o.exclude_cold_storage_files
339
351
  end
340
352
 
341
353
  # @see the `==` method
@@ -347,7 +359,7 @@ module Carbon
347
359
  # Calculates hash code according to all attributes.
348
360
  # @return [Integer] Hash code
349
361
  def hash
350
- [tags, query, query_vector, k, file_ids, parent_file_ids, include_all_children, tags_v2, include_tags, include_vectors, include_raw_file, hybrid_search, hybrid_search_tuning_parameters, media_type, embedding_model, include_file_level_metadata, high_accuracy, rerank, file_types_at_source].hash
362
+ [tags, query, query_vector, k, file_ids, parent_file_ids, include_all_children, tags_v2, include_tags, include_vectors, include_raw_file, hybrid_search, hybrid_search_tuning_parameters, media_type, embedding_model, include_file_level_metadata, high_accuracy, rerank, file_types_at_source, exclude_cold_storage_files].hash
351
363
  end
352
364
 
353
365
  # Builds the object from hash
@@ -0,0 +1,235 @@
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 ModifyColdStorageParametersQueryInput
14
+ attr_accessor :filters
15
+
16
+ attr_accessor :enable_cold_storage
17
+
18
+ attr_accessor :hot_storage_time_to_live
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'filters' => :'filters',
24
+ :'enable_cold_storage' => :'enable_cold_storage',
25
+ :'hot_storage_time_to_live' => :'hot_storage_time_to_live'
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
+ :'filters' => :'OrganizationUserFilesToSyncFilters',
38
+ :'enable_cold_storage' => :'Boolean',
39
+ :'hot_storage_time_to_live' => :'Integer'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ :'enable_cold_storage',
47
+ :'hot_storage_time_to_live'
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ModifyColdStorageParametersQueryInput` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ModifyColdStorageParametersQueryInput`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'filters')
67
+ self.filters = attributes[:'filters']
68
+ end
69
+
70
+ if attributes.key?(:'enable_cold_storage')
71
+ self.enable_cold_storage = attributes[:'enable_cold_storage']
72
+ end
73
+
74
+ if attributes.key?(:'hot_storage_time_to_live')
75
+ self.hot_storage_time_to_live = attributes[:'hot_storage_time_to_live']
76
+ end
77
+ end
78
+
79
+ # Show invalid properties with the reasons. Usually used together with valid?
80
+ # @return Array for valid properties with the reasons
81
+ def list_invalid_properties
82
+ invalid_properties = Array.new
83
+ invalid_properties
84
+ end
85
+
86
+ # Check to see if the all the properties in the model are valid
87
+ # @return true if the model is valid
88
+ def valid?
89
+ true
90
+ end
91
+
92
+ # Checks equality by comparing each attribute.
93
+ # @param [Object] Object to be compared
94
+ def ==(o)
95
+ return true if self.equal?(o)
96
+ self.class == o.class &&
97
+ filters == o.filters &&
98
+ enable_cold_storage == o.enable_cold_storage &&
99
+ hot_storage_time_to_live == o.hot_storage_time_to_live
100
+ end
101
+
102
+ # @see the `==` method
103
+ # @param [Object] Object to be compared
104
+ def eql?(o)
105
+ self == o
106
+ end
107
+
108
+ # Calculates hash code according to all attributes.
109
+ # @return [Integer] Hash code
110
+ def hash
111
+ [filters, enable_cold_storage, hot_storage_time_to_live].hash
112
+ end
113
+
114
+ # Builds the object from hash
115
+ # @param [Hash] attributes Model attributes in the form of hash
116
+ # @return [Object] Returns the model itself
117
+ def self.build_from_hash(attributes)
118
+ new.build_from_hash(attributes)
119
+ end
120
+
121
+ # Builds the object from hash
122
+ # @param [Hash] attributes Model attributes in the form of hash
123
+ # @return [Object] Returns the model itself
124
+ def build_from_hash(attributes)
125
+ return nil unless attributes.is_a?(Hash)
126
+ attributes = attributes.transform_keys(&:to_sym)
127
+ self.class.openapi_types.each_pair do |key, type|
128
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
129
+ self.send("#{key}=", nil)
130
+ elsif type =~ /\AArray<(.*)>/i
131
+ # check to ensure the input is an array given that the attribute
132
+ # is documented as an array but the input is not
133
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
134
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
135
+ end
136
+ elsif !attributes[self.class.attribute_map[key]].nil?
137
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
138
+ end
139
+ end
140
+
141
+ self
142
+ end
143
+
144
+ # Deserializes the data based on type
145
+ # @param string type Data type
146
+ # @param string value Value to be deserialized
147
+ # @return [Object] Deserialized data
148
+ def _deserialize(type, value)
149
+ case type.to_sym
150
+ when :Time
151
+ Time.parse(value)
152
+ when :Date
153
+ Date.parse(value)
154
+ when :String
155
+ value.to_s
156
+ when :Integer
157
+ value.to_i
158
+ when :Float
159
+ value.to_f
160
+ when :Boolean
161
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
162
+ true
163
+ else
164
+ false
165
+ end
166
+ when :Object
167
+ # generic object (usually a Hash), return directly
168
+ value
169
+ when /\AArray<(?<inner_type>.+)>\z/
170
+ inner_type = Regexp.last_match[:inner_type]
171
+ value.map { |v| _deserialize(inner_type, v) }
172
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
173
+ k_type = Regexp.last_match[:k_type]
174
+ v_type = Regexp.last_match[:v_type]
175
+ {}.tap do |hash|
176
+ value.each do |k, v|
177
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
178
+ end
179
+ end
180
+ else # model
181
+ # models (e.g. Pet) or oneOf
182
+ klass = Carbon.const_get(type)
183
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
184
+ end
185
+ end
186
+
187
+ # Returns the string representation of the object
188
+ # @return [String] String presentation of the object
189
+ def to_s
190
+ to_hash.to_s
191
+ end
192
+
193
+ # to_body is an alias to to_hash (backward compatibility)
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_body
196
+ to_hash
197
+ end
198
+
199
+ # Returns the object in the form of hash
200
+ # @return [Hash] Returns the object in the form of hash
201
+ def to_hash
202
+ hash = {}
203
+ self.class.attribute_map.each_pair do |attr, param|
204
+ value = self.send(attr)
205
+ if value.nil?
206
+ is_nullable = self.class.openapi_nullable.include?(attr)
207
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
208
+ end
209
+
210
+ hash[param] = _to_hash(value)
211
+ end
212
+ hash
213
+ end
214
+
215
+ # Outputs non-array value in the form of hash
216
+ # For object, use to_hash. Otherwise, just return the value
217
+ # @param [Object] value Any valid value
218
+ # @return [Hash] Returns the value in the form of hash
219
+ def _to_hash(value)
220
+ if value.is_a?(Array)
221
+ value.compact.map { |v| _to_hash(v) }
222
+ elsif value.is_a?(Hash)
223
+ {}.tap do |hash|
224
+ value.each { |k, v| hash[k] = _to_hash(v) }
225
+ end
226
+ elsif value.respond_to? :to_hash
227
+ value.to_hash
228
+ else
229
+ value
230
+ end
231
+ end
232
+
233
+ end
234
+
235
+ end
@@ -0,0 +1,215 @@
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 MoveToHotStorageQueryInput
14
+ attr_accessor :filters
15
+
16
+ # Attribute mapping from ruby-style variable name to JSON key.
17
+ def self.attribute_map
18
+ {
19
+ :'filters' => :'filters'
20
+ }
21
+ end
22
+
23
+ # Returns all the JSON keys this model knows about
24
+ def self.acceptable_attributes
25
+ attribute_map.values
26
+ end
27
+
28
+ # Attribute type mapping.
29
+ def self.openapi_types
30
+ {
31
+ :'filters' => :'OrganizationUserFilesToSyncFilters'
32
+ }
33
+ end
34
+
35
+ # List of attributes with nullable: true
36
+ def self.openapi_nullable
37
+ Set.new([
38
+ ])
39
+ end
40
+
41
+ # Initializes the object
42
+ # @param [Hash] attributes Model attributes in the form of hash
43
+ def initialize(attributes = {})
44
+ if (!attributes.is_a?(Hash))
45
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::MoveToHotStorageQueryInput` initialize method"
46
+ end
47
+
48
+ # check to see if the attribute exists and convert string to symbol for hash key
49
+ attributes = attributes.each_with_object({}) { |(k, v), h|
50
+ if (!self.class.attribute_map.key?(k.to_sym))
51
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::MoveToHotStorageQueryInput`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
52
+ end
53
+ h[k.to_sym] = v
54
+ }
55
+
56
+ if attributes.key?(:'filters')
57
+ self.filters = attributes[:'filters']
58
+ end
59
+ end
60
+
61
+ # Show invalid properties with the reasons. Usually used together with valid?
62
+ # @return Array for valid properties with the reasons
63
+ def list_invalid_properties
64
+ invalid_properties = Array.new
65
+ invalid_properties
66
+ end
67
+
68
+ # Check to see if the all the properties in the model are valid
69
+ # @return true if the model is valid
70
+ def valid?
71
+ true
72
+ end
73
+
74
+ # Checks equality by comparing each attribute.
75
+ # @param [Object] Object to be compared
76
+ def ==(o)
77
+ return true if self.equal?(o)
78
+ self.class == o.class &&
79
+ filters == o.filters
80
+ end
81
+
82
+ # @see the `==` method
83
+ # @param [Object] Object to be compared
84
+ def eql?(o)
85
+ self == o
86
+ end
87
+
88
+ # Calculates hash code according to all attributes.
89
+ # @return [Integer] Hash code
90
+ def hash
91
+ [filters].hash
92
+ end
93
+
94
+ # Builds the object from hash
95
+ # @param [Hash] attributes Model attributes in the form of hash
96
+ # @return [Object] Returns the model itself
97
+ def self.build_from_hash(attributes)
98
+ new.build_from_hash(attributes)
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+ attributes = attributes.transform_keys(&:to_sym)
107
+ self.class.openapi_types.each_pair do |key, type|
108
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
109
+ self.send("#{key}=", nil)
110
+ elsif type =~ /\AArray<(.*)>/i
111
+ # check to ensure the input is an array given that the attribute
112
+ # is documented as an array but the input is not
113
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
114
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
115
+ end
116
+ elsif !attributes[self.class.attribute_map[key]].nil?
117
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
118
+ end
119
+ end
120
+
121
+ self
122
+ end
123
+
124
+ # Deserializes the data based on type
125
+ # @param string type Data type
126
+ # @param string value Value to be deserialized
127
+ # @return [Object] Deserialized data
128
+ def _deserialize(type, value)
129
+ case type.to_sym
130
+ when :Time
131
+ Time.parse(value)
132
+ when :Date
133
+ Date.parse(value)
134
+ when :String
135
+ value.to_s
136
+ when :Integer
137
+ value.to_i
138
+ when :Float
139
+ value.to_f
140
+ when :Boolean
141
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
142
+ true
143
+ else
144
+ false
145
+ end
146
+ when :Object
147
+ # generic object (usually a Hash), return directly
148
+ value
149
+ when /\AArray<(?<inner_type>.+)>\z/
150
+ inner_type = Regexp.last_match[:inner_type]
151
+ value.map { |v| _deserialize(inner_type, v) }
152
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
153
+ k_type = Regexp.last_match[:k_type]
154
+ v_type = Regexp.last_match[:v_type]
155
+ {}.tap do |hash|
156
+ value.each do |k, v|
157
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
158
+ end
159
+ end
160
+ else # model
161
+ # models (e.g. Pet) or oneOf
162
+ klass = Carbon.const_get(type)
163
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
164
+ end
165
+ end
166
+
167
+ # Returns the string representation of the object
168
+ # @return [String] String presentation of the object
169
+ def to_s
170
+ to_hash.to_s
171
+ end
172
+
173
+ # to_body is an alias to to_hash (backward compatibility)
174
+ # @return [Hash] Returns the object in the form of hash
175
+ def to_body
176
+ to_hash
177
+ end
178
+
179
+ # Returns the object in the form of hash
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_hash
182
+ hash = {}
183
+ self.class.attribute_map.each_pair do |attr, param|
184
+ value = self.send(attr)
185
+ if value.nil?
186
+ is_nullable = self.class.openapi_nullable.include?(attr)
187
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
188
+ end
189
+
190
+ hash[param] = _to_hash(value)
191
+ end
192
+ hash
193
+ end
194
+
195
+ # Outputs non-array value in the form of hash
196
+ # For object, use to_hash. Otherwise, just return the value
197
+ # @param [Object] value Any valid value
198
+ # @return [Hash] Returns the value in the form of hash
199
+ def _to_hash(value)
200
+ if value.is_a?(Array)
201
+ value.compact.map { |v| _to_hash(v) }
202
+ elsif value.is_a?(Hash)
203
+ {}.tap do |hash|
204
+ value.each { |k, v| hash[k] = _to_hash(v) }
205
+ end
206
+ elsif value.respond_to? :to_hash
207
+ value.to_hash
208
+ else
209
+ value
210
+ end
211
+ end
212
+
213
+ end
214
+
215
+ end