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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +57 -3
- data/lib/carbon_ruby_sdk/api/files_api.rb +6 -6
- data/lib/carbon_ruby_sdk/api/integrations_api.rb +104 -8
- data/lib/carbon_ruby_sdk/models/authentication_property.rb +436 -0
- data/lib/carbon_ruby_sdk/models/confluence_authentication.rb +254 -0
- data/lib/carbon_ruby_sdk/models/connect_data_source_input.rb +229 -0
- data/lib/carbon_ruby_sdk/models/connect_data_source_response.rb +230 -0
- data/lib/carbon_ruby_sdk/models/freskdesk_authentication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/gitbook_authetication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/notion_authentication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/o_auth_authentication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +1 -0
- data/lib/carbon_ruby_sdk/models/organization_user_data_source_api.rb +11 -1
- data/lib/carbon_ruby_sdk/models/s3_authentication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/s3_file_sync_input.rb +1 -0
- data/lib/carbon_ruby_sdk/models/salesforce_authentication.rb +254 -0
- data/lib/carbon_ruby_sdk/models/sharepoint_authentication.rb +268 -0
- data/lib/carbon_ruby_sdk/models/simple_o_auth_data_sources.rb +41 -0
- data/lib/carbon_ruby_sdk/models/sitemap_scrape_request.rb +15 -0
- data/lib/carbon_ruby_sdk/models/sync_files_request.rb +1 -0
- data/lib/carbon_ruby_sdk/models/sync_options.rb +323 -0
- data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +1 -0
- data/lib/carbon_ruby_sdk/models/webscrape_request.rb +30 -0
- data/lib/carbon_ruby_sdk/models/zendesk_authentication.rb +244 -0
- data/lib/carbon_ruby_sdk/models/zotero_authentication.rb +272 -0
- data/lib/carbon_ruby_sdk/version.rb +1 -1
- data/lib/carbon_ruby_sdk.rb +15 -0
- data/spec/api/files_api_spec.rb +1 -1
- data/spec/api/integrations_api_spec.rb +11 -0
- data/spec/models/authentication_property_spec.rb +112 -0
- data/spec/models/confluence_authentication_spec.rb +46 -0
- data/spec/models/connect_data_source_input_spec.rb +34 -0
- data/spec/models/connect_data_source_response_spec.rb +34 -0
- data/spec/models/freskdesk_authentication_spec.rb +40 -0
- data/spec/models/gitbook_authetication_spec.rb +40 -0
- data/spec/models/notion_authentication_spec.rb +40 -0
- data/spec/models/o_auth_authentication_spec.rb +40 -0
- data/spec/models/organization_user_data_source_api_spec.rb +6 -0
- data/spec/models/s3_authentication_spec.rb +40 -0
- data/spec/models/salesforce_authentication_spec.rb +46 -0
- data/spec/models/sharepoint_authentication_spec.rb +52 -0
- data/spec/models/simple_o_auth_data_sources_spec.rb +22 -0
- data/spec/models/sync_options_spec.rb +82 -0
- data/spec/models/zendesk_authentication_spec.rb +40 -0
- data/spec/models/zotero_authentication_spec.rb +52 -0
- metadata +47 -2
@@ -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 OAuthAuthentication
|
14
|
+
attr_accessor :source
|
15
|
+
|
16
|
+
attr_accessor :access_token
|
17
|
+
|
18
|
+
attr_accessor :refresh_token
|
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
|
+
:'refresh_token' => :'refresh_token'
|
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' => :'SimpleOAuthDataSources',
|
38
|
+
:'access_token' => :'String',
|
39
|
+
:'refresh_token' => :'String'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# List of attributes with nullable: true
|
44
|
+
def self.openapi_nullable
|
45
|
+
Set.new([
|
46
|
+
:'refresh_token'
|
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::OAuthAuthentication` 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::OAuthAuthentication`. 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?(:'refresh_token')
|
74
|
+
self.refresh_token = attributes[:'refresh_token']
|
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 @source.nil?
|
83
|
+
invalid_properties.push('invalid value for "source", source cannot be nil.')
|
84
|
+
end
|
85
|
+
|
86
|
+
if @access_token.nil?
|
87
|
+
invalid_properties.push('invalid value for "access_token", access_token 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 @source.nil?
|
97
|
+
return false if @access_token.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
|
+
refresh_token == o.refresh_token
|
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, refresh_token].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
|
@@ -17,6 +17,8 @@ module Carbon
|
|
17
17
|
|
18
18
|
attr_accessor :data_source_type
|
19
19
|
|
20
|
+
attr_accessor :token
|
21
|
+
|
20
22
|
attr_accessor :sync_status
|
21
23
|
|
22
24
|
attr_accessor :source_items_synced_at
|
@@ -43,6 +45,7 @@ module Carbon
|
|
43
45
|
:'id' => :'id',
|
44
46
|
:'data_source_external_id' => :'data_source_external_id',
|
45
47
|
:'data_source_type' => :'data_source_type',
|
48
|
+
:'token' => :'token',
|
46
49
|
:'sync_status' => :'sync_status',
|
47
50
|
:'source_items_synced_at' => :'source_items_synced_at',
|
48
51
|
:'organization_user_id' => :'organization_user_id',
|
@@ -67,6 +70,7 @@ module Carbon
|
|
67
70
|
:'id' => :'Integer',
|
68
71
|
:'data_source_external_id' => :'String',
|
69
72
|
:'data_source_type' => :'DataSourceType',
|
73
|
+
:'token' => :'Object',
|
70
74
|
:'sync_status' => :'DataSourceSyncStatuses',
|
71
75
|
:'source_items_synced_at' => :'Time',
|
72
76
|
:'organization_user_id' => :'Integer',
|
@@ -84,6 +88,7 @@ module Carbon
|
|
84
88
|
def self.openapi_nullable
|
85
89
|
Set.new([
|
86
90
|
:'data_source_external_id',
|
91
|
+
:'token',
|
87
92
|
:'source_items_synced_at',
|
88
93
|
])
|
89
94
|
end
|
@@ -115,6 +120,10 @@ module Carbon
|
|
115
120
|
self.data_source_type = attributes[:'data_source_type']
|
116
121
|
end
|
117
122
|
|
123
|
+
if attributes.key?(:'token')
|
124
|
+
self.token = attributes[:'token']
|
125
|
+
end
|
126
|
+
|
118
127
|
if attributes.key?(:'sync_status')
|
119
128
|
self.sync_status = attributes[:'sync_status']
|
120
129
|
end
|
@@ -232,6 +241,7 @@ module Carbon
|
|
232
241
|
id == o.id &&
|
233
242
|
data_source_external_id == o.data_source_external_id &&
|
234
243
|
data_source_type == o.data_source_type &&
|
244
|
+
token == o.token &&
|
235
245
|
sync_status == o.sync_status &&
|
236
246
|
source_items_synced_at == o.source_items_synced_at &&
|
237
247
|
organization_user_id == o.organization_user_id &&
|
@@ -253,7 +263,7 @@ module Carbon
|
|
253
263
|
# Calculates hash code according to all attributes.
|
254
264
|
# @return [Integer] Hash code
|
255
265
|
def hash
|
256
|
-
[id, data_source_external_id, data_source_type, sync_status, source_items_synced_at, organization_user_id, organization_id, organization_supplied_user_id, revoked_access, last_synced_at, last_sync_action, created_at, updated_at].hash
|
266
|
+
[id, data_source_external_id, data_source_type, token, sync_status, source_items_synced_at, organization_user_id, organization_id, organization_supplied_user_id, revoked_access, last_synced_at, last_sync_action, created_at, updated_at].hash
|
257
267
|
end
|
258
268
|
|
259
269
|
# Builds the object from hash
|
@@ -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 S3Authentication
|
14
|
+
attr_accessor :source
|
15
|
+
|
16
|
+
attr_accessor :access_key
|
17
|
+
|
18
|
+
attr_accessor :access_key_secret
|
19
|
+
|
20
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
21
|
+
def self.attribute_map
|
22
|
+
{
|
23
|
+
:'source' => :'source',
|
24
|
+
:'access_key' => :'access_key',
|
25
|
+
:'access_key_secret' => :'access_key_secret'
|
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_key' => :'String',
|
39
|
+
:'access_key_secret' => :'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::S3Authentication` 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::S3Authentication`. 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_key')
|
70
|
+
self.access_key = attributes[:'access_key']
|
71
|
+
end
|
72
|
+
|
73
|
+
if attributes.key?(:'access_key_secret')
|
74
|
+
self.access_key_secret = attributes[:'access_key_secret']
|
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_key.nil?
|
83
|
+
invalid_properties.push('invalid value for "access_key", access_key cannot be nil.')
|
84
|
+
end
|
85
|
+
|
86
|
+
if @access_key_secret.nil?
|
87
|
+
invalid_properties.push('invalid value for "access_key_secret", access_key_secret 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_key.nil?
|
97
|
+
return false if @access_key_secret.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_key == o.access_key &&
|
108
|
+
access_key_secret == o.access_key_secret
|
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_key, access_key_secret].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
|