pnap_network_storage_api 1.2.0 → 1.4.0

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/VERSION +1 -1
  4. data/docs/NfsPermissionsCreate.md +26 -0
  5. data/docs/NfsPermissionsUpdate.md +26 -0
  6. data/docs/PermissionsCreate.md +18 -0
  7. data/docs/PermissionsUpdate.md +18 -0
  8. data/docs/StorageNetworkCreate.md +4 -2
  9. data/docs/StorageNetworkVolumeCreate.md +26 -0
  10. data/docs/StorageNetworksApi.md +85 -5
  11. data/docs/TagAssignment.md +26 -0
  12. data/docs/TagAssignmentRequest.md +20 -0
  13. data/docs/Volume.md +3 -1
  14. data/docs/VolumeCreate.md +5 -1
  15. data/docs/VolumeUpdate.md +3 -1
  16. data/lib/pnap_network_storage_api/api/storage_networks_api.rb +79 -0
  17. data/lib/pnap_network_storage_api/models/nfs_permissions_create.rb +271 -0
  18. data/lib/pnap_network_storage_api/models/nfs_permissions_update.rb +271 -0
  19. data/lib/pnap_network_storage_api/models/permissions_create.rb +220 -0
  20. data/lib/pnap_network_storage_api/models/permissions_update.rb +220 -0
  21. data/lib/pnap_network_storage_api/models/storage_network_create.rb +38 -4
  22. data/lib/pnap_network_storage_api/models/storage_network_volume_create.rb +370 -0
  23. data/lib/pnap_network_storage_api/models/tag_assignment.rb +310 -0
  24. data/lib/pnap_network_storage_api/models/tag_assignment_request.rb +236 -0
  25. data/lib/pnap_network_storage_api/models/volume.rb +16 -4
  26. data/lib/pnap_network_storage_api/models/volume_create.rb +25 -4
  27. data/lib/pnap_network_storage_api/models/volume_update.rb +13 -4
  28. data/lib/pnap_network_storage_api.rb +7 -0
  29. data/spec/models/nfs_permissions_create_spec.rb +58 -0
  30. data/spec/models/nfs_permissions_update_spec.rb +58 -0
  31. data/spec/models/permissions_create_spec.rb +34 -0
  32. data/spec/models/permissions_update_spec.rb +34 -0
  33. data/spec/models/storage_network_volume_create_spec.rb +52 -0
  34. data/spec/models/tag_assignment_request_spec.rb +40 -0
  35. data/spec/models/tag_assignment_spec.rb +62 -0
  36. metadata +35 -7
@@ -0,0 +1,370 @@
1
+ =begin
2
+ #Network Storage API
3
+
4
+ #Create, list, edit, and delete storage networks with the Network Storage API. Use storage networks to expand storage capacity on a private network. <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/bare-metal-cloud-storage' target='_blank'>here</a> </span> <br> <b>All URLs are relative to (https://api.phoenixnap.com/network-storage/v1/)</b>
5
+
6
+ The version of the OpenAPI document: 1.0
7
+ Contact: support@phoenixnap.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module NetworkStorageApi
17
+ # Create Volume.
18
+ class StorageNetworkVolumeCreate
19
+ # Volume friendly name.
20
+ attr_accessor :name
21
+
22
+ # Volume description.
23
+ attr_accessor :description
24
+
25
+ # Last part of volume's path.
26
+ attr_accessor :path_suffix
27
+
28
+ # Capacity of Volume in GB. Currently only whole numbers and multiples of 1000GB are supported.
29
+ attr_accessor :capacity_in_gb
30
+
31
+ # Tags to set to the resource. To create a new tag or list all the existing tags that you can use, refer to [Tags API](https://developers.phoenixnap.com/docs/tags/1/overview).
32
+ attr_accessor :tags
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'name' => :'name',
38
+ :'description' => :'description',
39
+ :'path_suffix' => :'pathSuffix',
40
+ :'capacity_in_gb' => :'capacityInGb',
41
+ :'tags' => :'tags'
42
+ }
43
+ end
44
+
45
+ # Returns all the JSON keys this model knows about
46
+ def self.acceptable_attributes
47
+ attribute_map.values
48
+ end
49
+
50
+ # Attribute type mapping.
51
+ def self.openapi_types
52
+ {
53
+ :'name' => :'String',
54
+ :'description' => :'String',
55
+ :'path_suffix' => :'String',
56
+ :'capacity_in_gb' => :'Integer',
57
+ :'tags' => :'Array<TagAssignmentRequest>'
58
+ }
59
+ end
60
+
61
+ # List of attributes with nullable: true
62
+ def self.openapi_nullable
63
+ Set.new([
64
+ ])
65
+ end
66
+
67
+ # Initializes the object
68
+ # @param [Hash] attributes Model attributes in the form of hash
69
+ def initialize(attributes = {})
70
+ if (!attributes.is_a?(Hash))
71
+ fail ArgumentError, "The input argument (attributes) must be a hash in `NetworkStorageApi::StorageNetworkVolumeCreate` initialize method"
72
+ end
73
+
74
+ # check to see if the attribute exists and convert string to symbol for hash key
75
+ attributes = attributes.each_with_object({}) { |(k, v), h|
76
+ if (!self.class.attribute_map.key?(k.to_sym))
77
+ fail ArgumentError, "`#{k}` is not a valid attribute in `NetworkStorageApi::StorageNetworkVolumeCreate`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
78
+ end
79
+ h[k.to_sym] = v
80
+ }
81
+
82
+ if attributes.key?(:'name')
83
+ self.name = attributes[:'name']
84
+ end
85
+
86
+ if attributes.key?(:'description')
87
+ self.description = attributes[:'description']
88
+ end
89
+
90
+ if attributes.key?(:'path_suffix')
91
+ self.path_suffix = attributes[:'path_suffix']
92
+ end
93
+
94
+ if attributes.key?(:'capacity_in_gb')
95
+ self.capacity_in_gb = attributes[:'capacity_in_gb']
96
+ end
97
+
98
+ if attributes.key?(:'tags')
99
+ if (value = attributes[:'tags']).is_a?(Array)
100
+ self.tags = value
101
+ end
102
+ end
103
+ end
104
+
105
+ # Show invalid properties with the reasons. Usually used together with valid?
106
+ # @return Array for valid properties with the reasons
107
+ def list_invalid_properties
108
+ invalid_properties = Array.new
109
+ if @name.nil?
110
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
111
+ end
112
+
113
+ if @name.to_s.length > 100
114
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 100.')
115
+ end
116
+
117
+ if @name.to_s.length < 1
118
+ invalid_properties.push('invalid value for "name", the character length must be great than or equal to 1.')
119
+ end
120
+
121
+ if !@description.nil? && @description.to_s.length > 250
122
+ invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 250.')
123
+ end
124
+
125
+ if !@path_suffix.nil? && @path_suffix.to_s.length > 27
126
+ invalid_properties.push('invalid value for "path_suffix", the character length must be smaller than or equal to 27.')
127
+ end
128
+
129
+ if !@path_suffix.nil? && @path_suffix.to_s.length < 0
130
+ invalid_properties.push('invalid value for "path_suffix", the character length must be great than or equal to 0.')
131
+ end
132
+
133
+ pattern = Regexp.new(/^(\/[\w-]+)+$|^$/)
134
+ if !@path_suffix.nil? && @path_suffix !~ pattern
135
+ invalid_properties.push("invalid value for \"path_suffix\", must conform to the pattern #{pattern}.")
136
+ end
137
+
138
+ if @capacity_in_gb.nil?
139
+ invalid_properties.push('invalid value for "capacity_in_gb", capacity_in_gb cannot be nil.')
140
+ end
141
+
142
+ if @capacity_in_gb < 1000
143
+ invalid_properties.push('invalid value for "capacity_in_gb", must be greater than or equal to 1000.')
144
+ end
145
+
146
+ invalid_properties
147
+ end
148
+
149
+ # Check to see if the all the properties in the model are valid
150
+ # @return true if the model is valid
151
+ def valid?
152
+ return false if @name.nil?
153
+ return false if @name.to_s.length > 100
154
+ return false if @name.to_s.length < 1
155
+ return false if !@description.nil? && @description.to_s.length > 250
156
+ return false if !@path_suffix.nil? && @path_suffix.to_s.length > 27
157
+ return false if !@path_suffix.nil? && @path_suffix.to_s.length < 0
158
+ return false if !@path_suffix.nil? && @path_suffix !~ Regexp.new(/^(\/[\w-]+)+$|^$/)
159
+ return false if @capacity_in_gb.nil?
160
+ return false if @capacity_in_gb < 1000
161
+ true
162
+ end
163
+
164
+ # Custom attribute writer method with validation
165
+ # @param [Object] name Value to be assigned
166
+ def name=(name)
167
+ if name.nil?
168
+ fail ArgumentError, 'name cannot be nil'
169
+ end
170
+
171
+ if name.to_s.length > 100
172
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 100.'
173
+ end
174
+
175
+ if name.to_s.length < 1
176
+ fail ArgumentError, 'invalid value for "name", the character length must be great than or equal to 1.'
177
+ end
178
+
179
+ @name = name
180
+ end
181
+
182
+ # Custom attribute writer method with validation
183
+ # @param [Object] description Value to be assigned
184
+ def description=(description)
185
+ if !description.nil? && description.to_s.length > 250
186
+ fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 250.'
187
+ end
188
+
189
+ @description = description
190
+ end
191
+
192
+ # Custom attribute writer method with validation
193
+ # @param [Object] path_suffix Value to be assigned
194
+ def path_suffix=(path_suffix)
195
+ if !path_suffix.nil? && path_suffix.to_s.length > 27
196
+ fail ArgumentError, 'invalid value for "path_suffix", the character length must be smaller than or equal to 27.'
197
+ end
198
+
199
+ if !path_suffix.nil? && path_suffix.to_s.length < 0
200
+ fail ArgumentError, 'invalid value for "path_suffix", the character length must be great than or equal to 0.'
201
+ end
202
+
203
+ pattern = Regexp.new(/^(\/[\w-]+)+$|^$/)
204
+ if !path_suffix.nil? && path_suffix !~ pattern
205
+ fail ArgumentError, "invalid value for \"path_suffix\", must conform to the pattern #{pattern}."
206
+ end
207
+
208
+ @path_suffix = path_suffix
209
+ end
210
+
211
+ # Custom attribute writer method with validation
212
+ # @param [Object] capacity_in_gb Value to be assigned
213
+ def capacity_in_gb=(capacity_in_gb)
214
+ if capacity_in_gb.nil?
215
+ fail ArgumentError, 'capacity_in_gb cannot be nil'
216
+ end
217
+
218
+ if capacity_in_gb < 1000
219
+ fail ArgumentError, 'invalid value for "capacity_in_gb", must be greater than or equal to 1000.'
220
+ end
221
+
222
+ @capacity_in_gb = capacity_in_gb
223
+ end
224
+
225
+ # Checks equality by comparing each attribute.
226
+ # @param [Object] Object to be compared
227
+ def ==(o)
228
+ return true if self.equal?(o)
229
+ self.class == o.class &&
230
+ name == o.name &&
231
+ description == o.description &&
232
+ path_suffix == o.path_suffix &&
233
+ capacity_in_gb == o.capacity_in_gb &&
234
+ tags == o.tags
235
+ end
236
+
237
+ # @see the `==` method
238
+ # @param [Object] Object to be compared
239
+ def eql?(o)
240
+ self == o
241
+ end
242
+
243
+ # Calculates hash code according to all attributes.
244
+ # @return [Integer] Hash code
245
+ def hash
246
+ [name, description, path_suffix, capacity_in_gb, tags].hash
247
+ end
248
+
249
+ # Builds the object from hash
250
+ # @param [Hash] attributes Model attributes in the form of hash
251
+ # @return [Object] Returns the model itself
252
+ def self.build_from_hash(attributes)
253
+ new.build_from_hash(attributes)
254
+ end
255
+
256
+ # Builds the object from hash
257
+ # @param [Hash] attributes Model attributes in the form of hash
258
+ # @return [Object] Returns the model itself
259
+ def build_from_hash(attributes)
260
+ return nil unless attributes.is_a?(Hash)
261
+ attributes = attributes.transform_keys(&:to_sym)
262
+ self.class.openapi_types.each_pair do |key, type|
263
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
264
+ self.send("#{key}=", nil)
265
+ elsif type =~ /\AArray<(.*)>/i
266
+ # check to ensure the input is an array given that the attribute
267
+ # is documented as an array but the input is not
268
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
269
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
270
+ end
271
+ elsif !attributes[self.class.attribute_map[key]].nil?
272
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
273
+ end
274
+ end
275
+
276
+ self
277
+ end
278
+
279
+ # Deserializes the data based on type
280
+ # @param string type Data type
281
+ # @param string value Value to be deserialized
282
+ # @return [Object] Deserialized data
283
+ def _deserialize(type, value)
284
+ case type.to_sym
285
+ when :Time
286
+ Time.parse(value)
287
+ when :Date
288
+ Date.parse(value)
289
+ when :String
290
+ value.to_s
291
+ when :Integer
292
+ value.to_i
293
+ when :Float
294
+ value.to_f
295
+ when :Boolean
296
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
297
+ true
298
+ else
299
+ false
300
+ end
301
+ when :Object
302
+ # generic object (usually a Hash), return directly
303
+ value
304
+ when /\AArray<(?<inner_type>.+)>\z/
305
+ inner_type = Regexp.last_match[:inner_type]
306
+ value.map { |v| _deserialize(inner_type, v) }
307
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
308
+ k_type = Regexp.last_match[:k_type]
309
+ v_type = Regexp.last_match[:v_type]
310
+ {}.tap do |hash|
311
+ value.each do |k, v|
312
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
313
+ end
314
+ end
315
+ else # model
316
+ # models (e.g. Pet) or oneOf
317
+ klass = NetworkStorageApi.const_get(type)
318
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
319
+ end
320
+ end
321
+
322
+ # Returns the string representation of the object
323
+ # @return [String] String presentation of the object
324
+ def to_s
325
+ to_hash.to_s
326
+ end
327
+
328
+ # to_body is an alias to to_hash (backward compatibility)
329
+ # @return [Hash] Returns the object in the form of hash
330
+ def to_body
331
+ to_hash
332
+ end
333
+
334
+ # Returns the object in the form of hash
335
+ # @return [Hash] Returns the object in the form of hash
336
+ def to_hash
337
+ hash = {}
338
+ self.class.attribute_map.each_pair do |attr, param|
339
+ value = self.send(attr)
340
+ if value.nil?
341
+ is_nullable = self.class.openapi_nullable.include?(attr)
342
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
343
+ end
344
+
345
+ hash[param] = _to_hash(value)
346
+ end
347
+ hash
348
+ end
349
+
350
+ # Outputs non-array value in the form of hash
351
+ # For object, use to_hash. Otherwise, just return the value
352
+ # @param [Object] value Any valid value
353
+ # @return [Hash] Returns the value in the form of hash
354
+ def _to_hash(value)
355
+ if value.is_a?(Array)
356
+ value.compact.map { |v| _to_hash(v) }
357
+ elsif value.is_a?(Hash)
358
+ {}.tap do |hash|
359
+ value.each { |k, v| hash[k] = _to_hash(v) }
360
+ end
361
+ elsif value.respond_to? :to_hash
362
+ value.to_hash
363
+ else
364
+ value
365
+ end
366
+ end
367
+
368
+ end
369
+
370
+ end
@@ -0,0 +1,310 @@
1
+ =begin
2
+ #Network Storage API
3
+
4
+ #Create, list, edit, and delete storage networks with the Network Storage API. Use storage networks to expand storage capacity on a private network. <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/bare-metal-cloud-storage' target='_blank'>here</a> </span> <br> <b>All URLs are relative to (https://api.phoenixnap.com/network-storage/v1/)</b>
5
+
6
+ The version of the OpenAPI document: 1.0
7
+ Contact: support@phoenixnap.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module NetworkStorageApi
17
+ # Tag assigned to resource.
18
+ class TagAssignment
19
+ # The unique id of the tag.
20
+ attr_accessor :id
21
+
22
+ # The name of the tag.
23
+ attr_accessor :name
24
+
25
+ # The value of the tag assigned to the resource.
26
+ attr_accessor :value
27
+
28
+ # Whether or not to show the tag as part of billing and invoices
29
+ attr_accessor :is_billing_tag
30
+
31
+ # Who the tag was created by.
32
+ attr_accessor :created_by
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
56
+ # Attribute mapping from ruby-style variable name to JSON key.
57
+ def self.attribute_map
58
+ {
59
+ :'id' => :'id',
60
+ :'name' => :'name',
61
+ :'value' => :'value',
62
+ :'is_billing_tag' => :'isBillingTag',
63
+ :'created_by' => :'createdBy'
64
+ }
65
+ end
66
+
67
+ # Returns all the JSON keys this model knows about
68
+ def self.acceptable_attributes
69
+ attribute_map.values
70
+ end
71
+
72
+ # Attribute type mapping.
73
+ def self.openapi_types
74
+ {
75
+ :'id' => :'String',
76
+ :'name' => :'String',
77
+ :'value' => :'String',
78
+ :'is_billing_tag' => :'Boolean',
79
+ :'created_by' => :'String'
80
+ }
81
+ end
82
+
83
+ # List of attributes with nullable: true
84
+ def self.openapi_nullable
85
+ Set.new([
86
+ ])
87
+ end
88
+
89
+ # Initializes the object
90
+ # @param [Hash] attributes Model attributes in the form of hash
91
+ def initialize(attributes = {})
92
+ if (!attributes.is_a?(Hash))
93
+ fail ArgumentError, "The input argument (attributes) must be a hash in `NetworkStorageApi::TagAssignment` initialize method"
94
+ end
95
+
96
+ # check to see if the attribute exists and convert string to symbol for hash key
97
+ attributes = attributes.each_with_object({}) { |(k, v), h|
98
+ if (!self.class.attribute_map.key?(k.to_sym))
99
+ fail ArgumentError, "`#{k}` is not a valid attribute in `NetworkStorageApi::TagAssignment`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
100
+ end
101
+ h[k.to_sym] = v
102
+ }
103
+
104
+ if attributes.key?(:'id')
105
+ self.id = attributes[:'id']
106
+ end
107
+
108
+ if attributes.key?(:'name')
109
+ self.name = attributes[:'name']
110
+ end
111
+
112
+ if attributes.key?(:'value')
113
+ self.value = attributes[:'value']
114
+ end
115
+
116
+ if attributes.key?(:'is_billing_tag')
117
+ self.is_billing_tag = attributes[:'is_billing_tag']
118
+ end
119
+
120
+ if attributes.key?(:'created_by')
121
+ self.created_by = attributes[:'created_by']
122
+ end
123
+ end
124
+
125
+ # Show invalid properties with the reasons. Usually used together with valid?
126
+ # @return Array for valid properties with the reasons
127
+ def list_invalid_properties
128
+ invalid_properties = Array.new
129
+ if @id.nil?
130
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
131
+ end
132
+
133
+ if @name.nil?
134
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
135
+ end
136
+
137
+ if @is_billing_tag.nil?
138
+ invalid_properties.push('invalid value for "is_billing_tag", is_billing_tag cannot be nil.')
139
+ end
140
+
141
+ invalid_properties
142
+ end
143
+
144
+ # Check to see if the all the properties in the model are valid
145
+ # @return true if the model is valid
146
+ def valid?
147
+ return false if @id.nil?
148
+ return false if @name.nil?
149
+ return false if @is_billing_tag.nil?
150
+ created_by_validator = EnumAttributeValidator.new('String', ["USER", "SYSTEM"])
151
+ return false unless created_by_validator.valid?(@created_by)
152
+ true
153
+ end
154
+
155
+ # Custom attribute writer method checking allowed values (enum).
156
+ # @param [Object] created_by Object to be assigned
157
+ def created_by=(created_by)
158
+ validator = EnumAttributeValidator.new('String', ["USER", "SYSTEM"])
159
+ unless validator.valid?(created_by)
160
+ fail ArgumentError, "invalid value for \"created_by\", must be one of #{validator.allowable_values}."
161
+ end
162
+ @created_by = created_by
163
+ end
164
+
165
+ # Checks equality by comparing each attribute.
166
+ # @param [Object] Object to be compared
167
+ def ==(o)
168
+ return true if self.equal?(o)
169
+ self.class == o.class &&
170
+ id == o.id &&
171
+ name == o.name &&
172
+ value == o.value &&
173
+ is_billing_tag == o.is_billing_tag &&
174
+ created_by == o.created_by
175
+ end
176
+
177
+ # @see the `==` method
178
+ # @param [Object] Object to be compared
179
+ def eql?(o)
180
+ self == o
181
+ end
182
+
183
+ # Calculates hash code according to all attributes.
184
+ # @return [Integer] Hash code
185
+ def hash
186
+ [id, name, value, is_billing_tag, created_by].hash
187
+ end
188
+
189
+ # Builds the object from hash
190
+ # @param [Hash] attributes Model attributes in the form of hash
191
+ # @return [Object] Returns the model itself
192
+ def self.build_from_hash(attributes)
193
+ new.build_from_hash(attributes)
194
+ end
195
+
196
+ # Builds the object from hash
197
+ # @param [Hash] attributes Model attributes in the form of hash
198
+ # @return [Object] Returns the model itself
199
+ def build_from_hash(attributes)
200
+ return nil unless attributes.is_a?(Hash)
201
+ attributes = attributes.transform_keys(&:to_sym)
202
+ self.class.openapi_types.each_pair do |key, type|
203
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
204
+ self.send("#{key}=", nil)
205
+ elsif type =~ /\AArray<(.*)>/i
206
+ # check to ensure the input is an array given that the attribute
207
+ # is documented as an array but the input is not
208
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
209
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
210
+ end
211
+ elsif !attributes[self.class.attribute_map[key]].nil?
212
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
213
+ end
214
+ end
215
+
216
+ self
217
+ end
218
+
219
+ # Deserializes the data based on type
220
+ # @param string type Data type
221
+ # @param string value Value to be deserialized
222
+ # @return [Object] Deserialized data
223
+ def _deserialize(type, value)
224
+ case type.to_sym
225
+ when :Time
226
+ Time.parse(value)
227
+ when :Date
228
+ Date.parse(value)
229
+ when :String
230
+ value.to_s
231
+ when :Integer
232
+ value.to_i
233
+ when :Float
234
+ value.to_f
235
+ when :Boolean
236
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
237
+ true
238
+ else
239
+ false
240
+ end
241
+ when :Object
242
+ # generic object (usually a Hash), return directly
243
+ value
244
+ when /\AArray<(?<inner_type>.+)>\z/
245
+ inner_type = Regexp.last_match[:inner_type]
246
+ value.map { |v| _deserialize(inner_type, v) }
247
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
248
+ k_type = Regexp.last_match[:k_type]
249
+ v_type = Regexp.last_match[:v_type]
250
+ {}.tap do |hash|
251
+ value.each do |k, v|
252
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
253
+ end
254
+ end
255
+ else # model
256
+ # models (e.g. Pet) or oneOf
257
+ klass = NetworkStorageApi.const_get(type)
258
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
259
+ end
260
+ end
261
+
262
+ # Returns the string representation of the object
263
+ # @return [String] String presentation of the object
264
+ def to_s
265
+ to_hash.to_s
266
+ end
267
+
268
+ # to_body is an alias to to_hash (backward compatibility)
269
+ # @return [Hash] Returns the object in the form of hash
270
+ def to_body
271
+ to_hash
272
+ end
273
+
274
+ # Returns the object in the form of hash
275
+ # @return [Hash] Returns the object in the form of hash
276
+ def to_hash
277
+ hash = {}
278
+ self.class.attribute_map.each_pair do |attr, param|
279
+ value = self.send(attr)
280
+ if value.nil?
281
+ is_nullable = self.class.openapi_nullable.include?(attr)
282
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
283
+ end
284
+
285
+ hash[param] = _to_hash(value)
286
+ end
287
+ hash
288
+ end
289
+
290
+ # Outputs non-array value in the form of hash
291
+ # For object, use to_hash. Otherwise, just return the value
292
+ # @param [Object] value Any valid value
293
+ # @return [Hash] Returns the value in the form of hash
294
+ def _to_hash(value)
295
+ if value.is_a?(Array)
296
+ value.compact.map { |v| _to_hash(v) }
297
+ elsif value.is_a?(Hash)
298
+ {}.tap do |hash|
299
+ value.each { |k, v| hash[k] = _to_hash(v) }
300
+ end
301
+ elsif value.respond_to? :to_hash
302
+ value.to_hash
303
+ else
304
+ value
305
+ end
306
+ end
307
+
308
+ end
309
+
310
+ end