pnap_bmc_api 1.0.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 (114) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +196 -0
  4. data/Rakefile +10 -0
  5. data/VERSION +1 -0
  6. data/docs/ActionResult.md +18 -0
  7. data/docs/DeleteResult.md +20 -0
  8. data/docs/DeleteSshKeyResult.md +20 -0
  9. data/docs/Error.md +20 -0
  10. data/docs/IpBlocksConfiguration.md +20 -0
  11. data/docs/NetworkConfiguration.md +20 -0
  12. data/docs/OsConfiguration.md +24 -0
  13. data/docs/OsConfigurationMap.md +22 -0
  14. data/docs/OsConfigurationMapEsxi.md +22 -0
  15. data/docs/OsConfigurationMapProxmox.md +22 -0
  16. data/docs/OsConfigurationWindows.md +18 -0
  17. data/docs/PrivateNetworkConfiguration.md +22 -0
  18. data/docs/Quota.md +32 -0
  19. data/docs/QuotaEditLimitRequest.md +20 -0
  20. data/docs/QuotaEditLimitRequestDetails.md +22 -0
  21. data/docs/QuotaEditLimitRequestDetailsAllOf.md +18 -0
  22. data/docs/QuotasApi.md +217 -0
  23. data/docs/RelinquishIpBlock.md +18 -0
  24. data/docs/ResetResult.md +22 -0
  25. data/docs/SSHKeysApi.md +360 -0
  26. data/docs/Server.md +64 -0
  27. data/docs/ServerCreate.md +44 -0
  28. data/docs/ServerIpBlock.md +20 -0
  29. data/docs/ServerPatch.md +20 -0
  30. data/docs/ServerPrivateNetwork.md +24 -0
  31. data/docs/ServerReserve.md +18 -0
  32. data/docs/ServerReset.md +24 -0
  33. data/docs/ServersApi.md +1237 -0
  34. data/docs/SshKey.md +30 -0
  35. data/docs/SshKeyCreate.md +22 -0
  36. data/docs/SshKeyUpdate.md +20 -0
  37. data/docs/TagAssignment.md +26 -0
  38. data/docs/TagAssignmentRequest.md +20 -0
  39. data/lib/pnap_bmc_api/api/quotas_api.rb +212 -0
  40. data/lib/pnap_bmc_api/api/servers_api.rb +1159 -0
  41. data/lib/pnap_bmc_api/api/ssh_keys_api.rb +339 -0
  42. data/lib/pnap_bmc_api/api_client.rb +392 -0
  43. data/lib/pnap_bmc_api/api_error.rb +57 -0
  44. data/lib/pnap_bmc_api/configuration.rb +278 -0
  45. data/lib/pnap_bmc_api/models/action_result.rb +225 -0
  46. data/lib/pnap_bmc_api/models/delete_result.rb +240 -0
  47. data/lib/pnap_bmc_api/models/delete_ssh_key_result.rb +240 -0
  48. data/lib/pnap_bmc_api/models/error.rb +236 -0
  49. data/lib/pnap_bmc_api/models/ip_blocks_configuration.rb +283 -0
  50. data/lib/pnap_bmc_api/models/network_configuration.rb +228 -0
  51. data/lib/pnap_bmc_api/models/os_configuration.rb +266 -0
  52. data/lib/pnap_bmc_api/models/os_configuration_map.rb +237 -0
  53. data/lib/pnap_bmc_api/models/os_configuration_map_esxi.rb +257 -0
  54. data/lib/pnap_bmc_api/models/os_configuration_map_proxmox.rb +257 -0
  55. data/lib/pnap_bmc_api/models/os_configuration_windows.rb +237 -0
  56. data/lib/pnap_bmc_api/models/private_network_configuration.rb +244 -0
  57. data/lib/pnap_bmc_api/models/quota.rb +415 -0
  58. data/lib/pnap_bmc_api/models/quota_edit_limit_request.rb +259 -0
  59. data/lib/pnap_bmc_api/models/quota_edit_limit_request_details.rb +281 -0
  60. data/lib/pnap_bmc_api/models/quota_edit_limit_request_details_all_of.rb +225 -0
  61. data/lib/pnap_bmc_api/models/relinquish_ip_block.rb +222 -0
  62. data/lib/pnap_bmc_api/models/reset_result.rb +244 -0
  63. data/lib/pnap_bmc_api/models/server.rb +687 -0
  64. data/lib/pnap_bmc_api/models/server_create.rb +434 -0
  65. data/lib/pnap_bmc_api/models/server_ip_block.rb +235 -0
  66. data/lib/pnap_bmc_api/models/server_patch.rb +280 -0
  67. data/lib/pnap_bmc_api/models/server_private_network.rb +274 -0
  68. data/lib/pnap_bmc_api/models/server_reserve.rb +225 -0
  69. data/lib/pnap_bmc_api/models/server_reset.rb +255 -0
  70. data/lib/pnap_bmc_api/models/ssh_key.rb +315 -0
  71. data/lib/pnap_bmc_api/models/ssh_key_create.rb +283 -0
  72. data/lib/pnap_bmc_api/models/ssh_key_update.rb +268 -0
  73. data/lib/pnap_bmc_api/models/tag_assignment.rb +309 -0
  74. data/lib/pnap_bmc_api/models/tag_assignment_request.rb +235 -0
  75. data/lib/pnap_bmc_api/version.rb +19 -0
  76. data/lib/pnap_bmc_api.rb +72 -0
  77. data/pnap_bmc_api.gemspec +39 -0
  78. data/spec/api/quotas_api_spec.rb +71 -0
  79. data/spec/api/servers_api_spec.rb +249 -0
  80. data/spec/api/ssh_keys_api_spec.rb +95 -0
  81. data/spec/api_client_spec.rb +226 -0
  82. data/spec/configuration_spec.rb +42 -0
  83. data/spec/models/action_result_spec.rb +34 -0
  84. data/spec/models/delete_result_spec.rb +40 -0
  85. data/spec/models/delete_ssh_key_result_spec.rb +40 -0
  86. data/spec/models/error_spec.rb +40 -0
  87. data/spec/models/ip_blocks_configuration_spec.rb +44 -0
  88. data/spec/models/network_configuration_spec.rb +40 -0
  89. data/spec/models/os_configuration_map_esxi_spec.rb +46 -0
  90. data/spec/models/os_configuration_map_proxmox_spec.rb +46 -0
  91. data/spec/models/os_configuration_map_spec.rb +46 -0
  92. data/spec/models/os_configuration_spec.rb +52 -0
  93. data/spec/models/os_configuration_windows_spec.rb +34 -0
  94. data/spec/models/private_network_configuration_spec.rb +46 -0
  95. data/spec/models/quota_edit_limit_request_details_all_of_spec.rb +34 -0
  96. data/spec/models/quota_edit_limit_request_details_spec.rb +46 -0
  97. data/spec/models/quota_edit_limit_request_spec.rb +40 -0
  98. data/spec/models/quota_spec.rb +84 -0
  99. data/spec/models/relinquish_ip_block_spec.rb +34 -0
  100. data/spec/models/reset_result_spec.rb +46 -0
  101. data/spec/models/server_create_spec.rb +112 -0
  102. data/spec/models/server_ip_block_spec.rb +40 -0
  103. data/spec/models/server_patch_spec.rb +40 -0
  104. data/spec/models/server_private_network_spec.rb +52 -0
  105. data/spec/models/server_reserve_spec.rb +34 -0
  106. data/spec/models/server_reset_spec.rb +52 -0
  107. data/spec/models/server_spec.rb +172 -0
  108. data/spec/models/ssh_key_create_spec.rb +46 -0
  109. data/spec/models/ssh_key_spec.rb +70 -0
  110. data/spec/models/ssh_key_update_spec.rb +40 -0
  111. data/spec/models/tag_assignment_request_spec.rb +40 -0
  112. data/spec/models/tag_assignment_spec.rb +62 -0
  113. data/spec/spec_helper.rb +111 -0
  114. metadata +232 -0
@@ -0,0 +1,268 @@
1
+ =begin
2
+ #Bare Metal Cloud API
3
+
4
+ #Create, power off, power on, reset, reboot, or shut down your server with the Bare Metal Cloud API. Deprovision servers, get or edit SSH key details, and a lot more. Manage your infrastructure more efficiently using just a few simple api calls.<br> <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/how-to-deploy-bare-metal-cloud-server' target='_blank'>here</a> </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/bmc/v1/)</b>
5
+
6
+ The version of the OpenAPI document: 0.1
7
+ Contact: support@phoenixnap.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BmcApi
17
+ # SSH key modification model.
18
+ class SshKeyUpdate
19
+ # Keys marked as default are always included on server creation and reset unless toggled off in creation/reset request.
20
+ attr_accessor :default
21
+
22
+ # SSH key name that can represent the key as an alternative to its ID.
23
+ attr_accessor :name
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'default' => :'default',
29
+ :'name' => :'name'
30
+ }
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'default' => :'Boolean',
42
+ :'name' => :'String'
43
+ }
44
+ end
45
+
46
+ # List of attributes with nullable: true
47
+ def self.openapi_nullable
48
+ Set.new([
49
+ ])
50
+ end
51
+
52
+ # Initializes the object
53
+ # @param [Hash] attributes Model attributes in the form of hash
54
+ def initialize(attributes = {})
55
+ if (!attributes.is_a?(Hash))
56
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BmcApi::SshKeyUpdate` initialize method"
57
+ end
58
+
59
+ # check to see if the attribute exists and convert string to symbol for hash key
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ if (!self.class.attribute_map.key?(k.to_sym))
62
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BmcApi::SshKeyUpdate`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ end
64
+ h[k.to_sym] = v
65
+ }
66
+
67
+ if attributes.key?(:'default')
68
+ self.default = attributes[:'default']
69
+ end
70
+
71
+ if attributes.key?(:'name')
72
+ self.name = attributes[:'name']
73
+ end
74
+ end
75
+
76
+ # Show invalid properties with the reasons. Usually used together with valid?
77
+ # @return Array for valid properties with the reasons
78
+ def list_invalid_properties
79
+ invalid_properties = Array.new
80
+ if @default.nil?
81
+ invalid_properties.push('invalid value for "default", default cannot be nil.')
82
+ end
83
+
84
+ if @name.nil?
85
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
86
+ end
87
+
88
+ if @name.to_s.length > 100
89
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 100.')
90
+ end
91
+
92
+ if @name.to_s.length < 1
93
+ invalid_properties.push('invalid value for "name", the character length must be great than or equal to 1.')
94
+ end
95
+
96
+ invalid_properties
97
+ end
98
+
99
+ # Check to see if the all the properties in the model are valid
100
+ # @return true if the model is valid
101
+ def valid?
102
+ return false if @default.nil?
103
+ return false if @name.nil?
104
+ return false if @name.to_s.length > 100
105
+ return false if @name.to_s.length < 1
106
+ true
107
+ end
108
+
109
+ # Custom attribute writer method with validation
110
+ # @param [Object] name Value to be assigned
111
+ def name=(name)
112
+ if name.nil?
113
+ fail ArgumentError, 'name cannot be nil'
114
+ end
115
+
116
+ if name.to_s.length > 100
117
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 100.'
118
+ end
119
+
120
+ if name.to_s.length < 1
121
+ fail ArgumentError, 'invalid value for "name", the character length must be great than or equal to 1.'
122
+ end
123
+
124
+ @name = name
125
+ end
126
+
127
+ # Checks equality by comparing each attribute.
128
+ # @param [Object] Object to be compared
129
+ def ==(o)
130
+ return true if self.equal?(o)
131
+ self.class == o.class &&
132
+ default == o.default &&
133
+ name == o.name
134
+ end
135
+
136
+ # @see the `==` method
137
+ # @param [Object] Object to be compared
138
+ def eql?(o)
139
+ self == o
140
+ end
141
+
142
+ # Calculates hash code according to all attributes.
143
+ # @return [Integer] Hash code
144
+ def hash
145
+ [default, name].hash
146
+ end
147
+
148
+ # Builds the object from hash
149
+ # @param [Hash] attributes Model attributes in the form of hash
150
+ # @return [Object] Returns the model itself
151
+ def self.build_from_hash(attributes)
152
+ new.build_from_hash(attributes)
153
+ end
154
+
155
+ # Builds the object from hash
156
+ # @param [Hash] attributes Model attributes in the form of hash
157
+ # @return [Object] Returns the model itself
158
+ def build_from_hash(attributes)
159
+ return nil unless attributes.is_a?(Hash)
160
+ self.class.openapi_types.each_pair do |key, type|
161
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
162
+ self.send("#{key}=", nil)
163
+ elsif type =~ /\AArray<(.*)>/i
164
+ # check to ensure the input is an array given that the attribute
165
+ # is documented as an array but the input is not
166
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
167
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
168
+ end
169
+ elsif !attributes[self.class.attribute_map[key]].nil?
170
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
171
+ end
172
+ end
173
+
174
+ self
175
+ end
176
+
177
+ # Deserializes the data based on type
178
+ # @param string type Data type
179
+ # @param string value Value to be deserialized
180
+ # @return [Object] Deserialized data
181
+ def _deserialize(type, value)
182
+ case type.to_sym
183
+ when :Time
184
+ Time.parse(value)
185
+ when :Date
186
+ Date.parse(value)
187
+ when :String
188
+ value.to_s
189
+ when :Integer
190
+ value.to_i
191
+ when :Float
192
+ value.to_f
193
+ when :Boolean
194
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
195
+ true
196
+ else
197
+ false
198
+ end
199
+ when :Object
200
+ # generic object (usually a Hash), return directly
201
+ value
202
+ when /\AArray<(?<inner_type>.+)>\z/
203
+ inner_type = Regexp.last_match[:inner_type]
204
+ value.map { |v| _deserialize(inner_type, v) }
205
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
206
+ k_type = Regexp.last_match[:k_type]
207
+ v_type = Regexp.last_match[:v_type]
208
+ {}.tap do |hash|
209
+ value.each do |k, v|
210
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
211
+ end
212
+ end
213
+ else # model
214
+ # models (e.g. Pet) or oneOf
215
+ klass = BmcApi.const_get(type)
216
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
217
+ end
218
+ end
219
+
220
+ # Returns the string representation of the object
221
+ # @return [String] String presentation of the object
222
+ def to_s
223
+ to_hash.to_s
224
+ end
225
+
226
+ # to_body is an alias to to_hash (backward compatibility)
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_body
229
+ to_hash
230
+ end
231
+
232
+ # Returns the object in the form of hash
233
+ # @return [Hash] Returns the object in the form of hash
234
+ def to_hash
235
+ hash = {}
236
+ self.class.attribute_map.each_pair do |attr, param|
237
+ value = self.send(attr)
238
+ if value.nil?
239
+ is_nullable = self.class.openapi_nullable.include?(attr)
240
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
241
+ end
242
+
243
+ hash[param] = _to_hash(value)
244
+ end
245
+ hash
246
+ end
247
+
248
+ # Outputs non-array value in the form of hash
249
+ # For object, use to_hash. Otherwise, just return the value
250
+ # @param [Object] value Any valid value
251
+ # @return [Hash] Returns the value in the form of hash
252
+ def _to_hash(value)
253
+ if value.is_a?(Array)
254
+ value.compact.map { |v| _to_hash(v) }
255
+ elsif value.is_a?(Hash)
256
+ {}.tap do |hash|
257
+ value.each { |k, v| hash[k] = _to_hash(v) }
258
+ end
259
+ elsif value.respond_to? :to_hash
260
+ value.to_hash
261
+ else
262
+ value
263
+ end
264
+ end
265
+
266
+ end
267
+
268
+ end
@@ -0,0 +1,309 @@
1
+ =begin
2
+ #Bare Metal Cloud API
3
+
4
+ #Create, power off, power on, reset, reboot, or shut down your server with the Bare Metal Cloud API. Deprovision servers, get or edit SSH key details, and a lot more. Manage your infrastructure more efficiently using just a few simple api calls.<br> <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/how-to-deploy-bare-metal-cloud-server' target='_blank'>here</a> </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/bmc/v1/)</b>
5
+
6
+ The version of the OpenAPI document: 0.1
7
+ Contact: support@phoenixnap.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BmcApi
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 `BmcApi::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 `BmcApi::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
+ self.class.openapi_types.each_pair do |key, type|
202
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
203
+ self.send("#{key}=", nil)
204
+ elsif type =~ /\AArray<(.*)>/i
205
+ # check to ensure the input is an array given that the attribute
206
+ # is documented as an array but the input is not
207
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
208
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
209
+ end
210
+ elsif !attributes[self.class.attribute_map[key]].nil?
211
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
212
+ end
213
+ end
214
+
215
+ self
216
+ end
217
+
218
+ # Deserializes the data based on type
219
+ # @param string type Data type
220
+ # @param string value Value to be deserialized
221
+ # @return [Object] Deserialized data
222
+ def _deserialize(type, value)
223
+ case type.to_sym
224
+ when :Time
225
+ Time.parse(value)
226
+ when :Date
227
+ Date.parse(value)
228
+ when :String
229
+ value.to_s
230
+ when :Integer
231
+ value.to_i
232
+ when :Float
233
+ value.to_f
234
+ when :Boolean
235
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
236
+ true
237
+ else
238
+ false
239
+ end
240
+ when :Object
241
+ # generic object (usually a Hash), return directly
242
+ value
243
+ when /\AArray<(?<inner_type>.+)>\z/
244
+ inner_type = Regexp.last_match[:inner_type]
245
+ value.map { |v| _deserialize(inner_type, v) }
246
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
247
+ k_type = Regexp.last_match[:k_type]
248
+ v_type = Regexp.last_match[:v_type]
249
+ {}.tap do |hash|
250
+ value.each do |k, v|
251
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
252
+ end
253
+ end
254
+ else # model
255
+ # models (e.g. Pet) or oneOf
256
+ klass = BmcApi.const_get(type)
257
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
258
+ end
259
+ end
260
+
261
+ # Returns the string representation of the object
262
+ # @return [String] String presentation of the object
263
+ def to_s
264
+ to_hash.to_s
265
+ end
266
+
267
+ # to_body is an alias to to_hash (backward compatibility)
268
+ # @return [Hash] Returns the object in the form of hash
269
+ def to_body
270
+ to_hash
271
+ end
272
+
273
+ # Returns the object in the form of hash
274
+ # @return [Hash] Returns the object in the form of hash
275
+ def to_hash
276
+ hash = {}
277
+ self.class.attribute_map.each_pair do |attr, param|
278
+ value = self.send(attr)
279
+ if value.nil?
280
+ is_nullable = self.class.openapi_nullable.include?(attr)
281
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
282
+ end
283
+
284
+ hash[param] = _to_hash(value)
285
+ end
286
+ hash
287
+ end
288
+
289
+ # Outputs non-array value in the form of hash
290
+ # For object, use to_hash. Otherwise, just return the value
291
+ # @param [Object] value Any valid value
292
+ # @return [Hash] Returns the value in the form of hash
293
+ def _to_hash(value)
294
+ if value.is_a?(Array)
295
+ value.compact.map { |v| _to_hash(v) }
296
+ elsif value.is_a?(Hash)
297
+ {}.tap do |hash|
298
+ value.each { |k, v| hash[k] = _to_hash(v) }
299
+ end
300
+ elsif value.respond_to? :to_hash
301
+ value.to_hash
302
+ else
303
+ value
304
+ end
305
+ end
306
+
307
+ end
308
+
309
+ end