pnap_network_api 2.0.1 → 2.1.1

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -7
  3. data/VERSION +1 -1
  4. data/docs/AsnDetails.md +24 -0
  5. data/docs/BGPPeerGroupsApi.md +361 -0
  6. data/docs/BgpIPv4Prefix.md +26 -0
  7. data/docs/BgpPeerGroup.md +46 -0
  8. data/docs/BgpPeerGroupCreate.md +24 -0
  9. data/docs/BgpPeerGroupPatch.md +22 -0
  10. data/docs/PublicNetwork.md +3 -1
  11. data/docs/PublicNetworkCreate.md +4 -2
  12. data/docs/PublicNetworkIpBlock.md +5 -1
  13. data/docs/PublicNetworkIpBlockCreate.md +18 -0
  14. data/docs/PublicNetworkModify.md +3 -1
  15. data/docs/PublicNetworksApi.md +6 -6
  16. data/lib/pnap_network_api/api/bgp_peer_groups_api.rb +350 -0
  17. data/lib/pnap_network_api/api/private_networks_api.rb +1 -1
  18. data/lib/pnap_network_api/api/public_networks_api.rb +10 -10
  19. data/lib/pnap_network_api/api_client.rb +1 -1
  20. data/lib/pnap_network_api/api_error.rb +1 -1
  21. data/lib/pnap_network_api/configuration.rb +1 -1
  22. data/lib/pnap_network_api/models/asn_details.rb +267 -0
  23. data/lib/pnap_network_api/models/bgp_ipv4_prefix.rb +312 -0
  24. data/lib/pnap_network_api/models/bgp_peer_group.rb +481 -0
  25. data/lib/pnap_network_api/models/bgp_peer_group_create.rb +306 -0
  26. data/lib/pnap_network_api/models/bgp_peer_group_patch.rb +275 -0
  27. data/lib/pnap_network_api/models/error.rb +1 -1
  28. data/lib/pnap_network_api/models/network_membership.rb +1 -1
  29. data/lib/pnap_network_api/models/private_network.rb +1 -1
  30. data/lib/pnap_network_api/models/private_network_create.rb +1 -1
  31. data/lib/pnap_network_api/models/private_network_modify.rb +1 -1
  32. data/lib/pnap_network_api/models/private_network_server.rb +1 -1
  33. data/lib/pnap_network_api/models/public_network.rb +15 -5
  34. data/lib/pnap_network_api/models/public_network_create.rb +21 -11
  35. data/lib/pnap_network_api/models/public_network_ip_block.rb +39 -5
  36. data/lib/pnap_network_api/models/public_network_ip_block_create.rb +223 -0
  37. data/lib/pnap_network_api/models/public_network_modify.rb +15 -5
  38. data/lib/pnap_network_api/version.rb +1 -1
  39. data/lib/pnap_network_api.rb +8 -1
  40. data/pnap_network_api.gemspec +1 -1
  41. data/spec/api/bgp_peer_groups_api_spec.rb +96 -0
  42. data/spec/api/private_networks_api_spec.rb +1 -1
  43. data/spec/api/public_networks_api_spec.rb +2 -2
  44. data/spec/models/asn_details_spec.rb +54 -0
  45. data/spec/models/bgp_ipv4_prefix_spec.rb +60 -0
  46. data/spec/models/bgp_peer_group_create_spec.rb +54 -0
  47. data/spec/models/bgp_peer_group_patch_spec.rb +48 -0
  48. data/spec/models/bgp_peer_group_spec.rb +120 -0
  49. data/spec/models/error_spec.rb +1 -1
  50. data/spec/models/network_membership_spec.rb +1 -1
  51. data/spec/models/private_network_create_spec.rb +1 -1
  52. data/spec/models/private_network_modify_spec.rb +1 -1
  53. data/spec/models/private_network_server_spec.rb +1 -1
  54. data/spec/models/private_network_spec.rb +1 -1
  55. data/spec/models/public_network_create_spec.rb +7 -1
  56. data/spec/models/public_network_ip_block_create_spec.rb +36 -0
  57. data/spec/models/public_network_ip_block_spec.rb +13 -1
  58. data/spec/models/public_network_modify_spec.rb +7 -1
  59. data/spec/models/public_network_spec.rb +7 -1
  60. data/spec/spec_helper.rb +1 -1
  61. metadata +40 -12
@@ -0,0 +1,267 @@
1
+ =begin
2
+ #Networks API
3
+
4
+ #Create, list, edit and delete public/private networks with the Network API. Use public networks to place multiple servers on the same network or VLAN. Assign new servers with IP addresses from the same CIDR range. Use private networks to avoid unnecessary egress data charges. Model your networks according to your business needs.<br> <br> <span class='pnap-api-knowledge-base-link'> Helpful knowledge base articles are available for <a href='https://phoenixnap.com/kb/bmc-server-management-via-api#multi-private-backend-network-api' target='_blank'>multi-private backend networks</a>, <a href='https://phoenixnap.com/kb/bmc-server-management-via-api#ftoc-heading-15' target='_blank'>public networks</a> and <a href='https://phoenixnap.com/kb/border-gateway-protocol-bmc' target='_blank'>border gateway protocol peer groups</a>. </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/networks/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: 7.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module NetworkApi
17
+ # BGP Peer Group ASN details.
18
+ class AsnDetails
19
+ # The BGP Peer Group ASN.
20
+ attr_accessor :asn
21
+
22
+ # True if the BGP Peer Group ASN is a `bring your own` ASN.
23
+ attr_accessor :is_bring_your_own
24
+
25
+ # The BGP Peer Group ASN verification status. Can have one of the following values: `PENDING_VERIFICATION`, `FAILED_VERIFICATION` and `VERIFIED`.
26
+ attr_accessor :verification_status
27
+
28
+ # The BGP Peer Group ASN verification reason for the respective status.
29
+ attr_accessor :verification_reason
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'asn' => :'asn',
35
+ :'is_bring_your_own' => :'isBringYourOwn',
36
+ :'verification_status' => :'verificationStatus',
37
+ :'verification_reason' => :'verificationReason'
38
+ }
39
+ end
40
+
41
+ # Returns all the JSON keys this model knows about
42
+ def self.acceptable_attributes
43
+ attribute_map.values
44
+ end
45
+
46
+ # Attribute type mapping.
47
+ def self.openapi_types
48
+ {
49
+ :'asn' => :'Integer',
50
+ :'is_bring_your_own' => :'Boolean',
51
+ :'verification_status' => :'String',
52
+ :'verification_reason' => :'String'
53
+ }
54
+ end
55
+
56
+ # List of attributes with nullable: true
57
+ def self.openapi_nullable
58
+ Set.new([
59
+ ])
60
+ end
61
+
62
+ # Initializes the object
63
+ # @param [Hash] attributes Model attributes in the form of hash
64
+ def initialize(attributes = {})
65
+ if (!attributes.is_a?(Hash))
66
+ fail ArgumentError, "The input argument (attributes) must be a hash in `NetworkApi::AsnDetails` initialize method"
67
+ end
68
+
69
+ # check to see if the attribute exists and convert string to symbol for hash key
70
+ attributes = attributes.each_with_object({}) { |(k, v), h|
71
+ if (!self.class.attribute_map.key?(k.to_sym))
72
+ fail ArgumentError, "`#{k}` is not a valid attribute in `NetworkApi::AsnDetails`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
73
+ end
74
+ h[k.to_sym] = v
75
+ }
76
+
77
+ if attributes.key?(:'asn')
78
+ self.asn = attributes[:'asn']
79
+ else
80
+ self.asn = nil
81
+ end
82
+
83
+ if attributes.key?(:'is_bring_your_own')
84
+ self.is_bring_your_own = attributes[:'is_bring_your_own']
85
+ else
86
+ self.is_bring_your_own = nil
87
+ end
88
+
89
+ if attributes.key?(:'verification_status')
90
+ self.verification_status = attributes[:'verification_status']
91
+ else
92
+ self.verification_status = nil
93
+ end
94
+
95
+ if attributes.key?(:'verification_reason')
96
+ self.verification_reason = attributes[:'verification_reason']
97
+ end
98
+ end
99
+
100
+ # Show invalid properties with the reasons. Usually used together with valid?
101
+ # @return Array for valid properties with the reasons
102
+ def list_invalid_properties
103
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
104
+ invalid_properties = Array.new
105
+ if @asn.nil?
106
+ invalid_properties.push('invalid value for "asn", asn cannot be nil.')
107
+ end
108
+
109
+ if @is_bring_your_own.nil?
110
+ invalid_properties.push('invalid value for "is_bring_your_own", is_bring_your_own cannot be nil.')
111
+ end
112
+
113
+ if @verification_status.nil?
114
+ invalid_properties.push('invalid value for "verification_status", verification_status cannot be nil.')
115
+ end
116
+
117
+ invalid_properties
118
+ end
119
+
120
+ # Check to see if the all the properties in the model are valid
121
+ # @return true if the model is valid
122
+ def valid?
123
+ warn '[DEPRECATED] the `valid?` method is obsolete'
124
+ return false if @asn.nil?
125
+ return false if @is_bring_your_own.nil?
126
+ return false if @verification_status.nil?
127
+ true
128
+ end
129
+
130
+ # Checks equality by comparing each attribute.
131
+ # @param [Object] Object to be compared
132
+ def ==(o)
133
+ return true if self.equal?(o)
134
+ self.class == o.class &&
135
+ asn == o.asn &&
136
+ is_bring_your_own == o.is_bring_your_own &&
137
+ verification_status == o.verification_status &&
138
+ verification_reason == o.verification_reason
139
+ end
140
+
141
+ # @see the `==` method
142
+ # @param [Object] Object to be compared
143
+ def eql?(o)
144
+ self == o
145
+ end
146
+
147
+ # Calculates hash code according to all attributes.
148
+ # @return [Integer] Hash code
149
+ def hash
150
+ [asn, is_bring_your_own, verification_status, verification_reason].hash
151
+ end
152
+
153
+ # Builds the object from hash
154
+ # @param [Hash] attributes Model attributes in the form of hash
155
+ # @return [Object] Returns the model itself
156
+ def self.build_from_hash(attributes)
157
+ return nil unless attributes.is_a?(Hash)
158
+ attributes = attributes.transform_keys(&:to_sym)
159
+ transformed_hash = {}
160
+ openapi_types.each_pair do |key, type|
161
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
162
+ transformed_hash["#{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[attribute_map[key]].is_a?(Array)
167
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
168
+ end
169
+ elsif !attributes[attribute_map[key]].nil?
170
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
171
+ end
172
+ end
173
+ new(transformed_hash)
174
+ end
175
+
176
+ # Deserializes the data based on type
177
+ # @param string type Data type
178
+ # @param string value Value to be deserialized
179
+ # @return [Object] Deserialized data
180
+ def self._deserialize(type, value)
181
+ case type.to_sym
182
+ when :Time
183
+ Time.parse(value)
184
+ when :Date
185
+ Date.parse(value)
186
+ when :String
187
+ value.to_s
188
+ when :Integer
189
+ value.to_i
190
+ when :Float
191
+ value.to_f
192
+ when :Boolean
193
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
194
+ true
195
+ else
196
+ false
197
+ end
198
+ when :Object
199
+ # generic object (usually a Hash), return directly
200
+ value
201
+ when /\AArray<(?<inner_type>.+)>\z/
202
+ inner_type = Regexp.last_match[:inner_type]
203
+ value.map { |v| _deserialize(inner_type, v) }
204
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
205
+ k_type = Regexp.last_match[:k_type]
206
+ v_type = Regexp.last_match[:v_type]
207
+ {}.tap do |hash|
208
+ value.each do |k, v|
209
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
210
+ end
211
+ end
212
+ else # model
213
+ # models (e.g. Pet) or oneOf
214
+ klass = NetworkApi.const_get(type)
215
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
216
+ end
217
+ end
218
+
219
+ # Returns the string representation of the object
220
+ # @return [String] String presentation of the object
221
+ def to_s
222
+ to_hash.to_s
223
+ end
224
+
225
+ # to_body is an alias to to_hash (backward compatibility)
226
+ # @return [Hash] Returns the object in the form of hash
227
+ def to_body
228
+ to_hash
229
+ end
230
+
231
+ # Returns the object in the form of hash
232
+ # @return [Hash] Returns the object in the form of hash
233
+ def to_hash
234
+ hash = {}
235
+ self.class.attribute_map.each_pair do |attr, param|
236
+ value = self.send(attr)
237
+ if value.nil?
238
+ is_nullable = self.class.openapi_nullable.include?(attr)
239
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
240
+ end
241
+
242
+ hash[param] = _to_hash(value)
243
+ end
244
+ hash
245
+ end
246
+
247
+ # Outputs non-array value in the form of hash
248
+ # For object, use to_hash. Otherwise, just return the value
249
+ # @param [Object] value Any valid value
250
+ # @return [Hash] Returns the value in the form of hash
251
+ def _to_hash(value)
252
+ if value.is_a?(Array)
253
+ value.compact.map { |v| _to_hash(v) }
254
+ elsif value.is_a?(Hash)
255
+ {}.tap do |hash|
256
+ value.each { |k, v| hash[k] = _to_hash(v) }
257
+ end
258
+ elsif value.respond_to? :to_hash
259
+ value.to_hash
260
+ else
261
+ value
262
+ end
263
+ end
264
+
265
+ end
266
+
267
+ end
@@ -0,0 +1,312 @@
1
+ =begin
2
+ #Networks API
3
+
4
+ #Create, list, edit and delete public/private networks with the Network API. Use public networks to place multiple servers on the same network or VLAN. Assign new servers with IP addresses from the same CIDR range. Use private networks to avoid unnecessary egress data charges. Model your networks according to your business needs.<br> <br> <span class='pnap-api-knowledge-base-link'> Helpful knowledge base articles are available for <a href='https://phoenixnap.com/kb/bmc-server-management-via-api#multi-private-backend-network-api' target='_blank'>multi-private backend networks</a>, <a href='https://phoenixnap.com/kb/bmc-server-management-via-api#ftoc-heading-15' target='_blank'>public networks</a> and <a href='https://phoenixnap.com/kb/border-gateway-protocol-bmc' target='_blank'>border gateway protocol peer groups</a>. </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/networks/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: 7.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module NetworkApi
17
+ # The BGP IPv4 Prefix.
18
+ class BgpIPv4Prefix
19
+ # IPv4 allocation ID.
20
+ attr_accessor :ipv4_allocation_id
21
+
22
+ # The IP block in CIDR format.
23
+ attr_accessor :cidr
24
+
25
+ # The BGP IPv4 Prefix status. Can have one of the following values: `PENDING`, `BUSY`, `READY`, `ERROR` and `DELETING`.
26
+ attr_accessor :status
27
+
28
+ # Identifies IP as a `bring your own` IP block.
29
+ attr_accessor :is_bring_your_own_ip
30
+
31
+ # The Boolean value of the BGP IPv4 Prefix is in use.
32
+ attr_accessor :in_use
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'ipv4_allocation_id' => :'ipv4AllocationId',
38
+ :'cidr' => :'cidr',
39
+ :'status' => :'status',
40
+ :'is_bring_your_own_ip' => :'isBringYourOwnIp',
41
+ :'in_use' => :'inUse'
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
+ :'ipv4_allocation_id' => :'String',
54
+ :'cidr' => :'String',
55
+ :'status' => :'String',
56
+ :'is_bring_your_own_ip' => :'Boolean',
57
+ :'in_use' => :'Boolean'
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 `NetworkApi::BgpIPv4Prefix` 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 `NetworkApi::BgpIPv4Prefix`. 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?(:'ipv4_allocation_id')
83
+ self.ipv4_allocation_id = attributes[:'ipv4_allocation_id']
84
+ else
85
+ self.ipv4_allocation_id = nil
86
+ end
87
+
88
+ if attributes.key?(:'cidr')
89
+ self.cidr = attributes[:'cidr']
90
+ else
91
+ self.cidr = nil
92
+ end
93
+
94
+ if attributes.key?(:'status')
95
+ self.status = attributes[:'status']
96
+ else
97
+ self.status = nil
98
+ end
99
+
100
+ if attributes.key?(:'is_bring_your_own_ip')
101
+ self.is_bring_your_own_ip = attributes[:'is_bring_your_own_ip']
102
+ else
103
+ self.is_bring_your_own_ip = nil
104
+ end
105
+
106
+ if attributes.key?(:'in_use')
107
+ self.in_use = attributes[:'in_use']
108
+ else
109
+ self.in_use = nil
110
+ end
111
+ end
112
+
113
+ # Show invalid properties with the reasons. Usually used together with valid?
114
+ # @return Array for valid properties with the reasons
115
+ def list_invalid_properties
116
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
117
+ invalid_properties = Array.new
118
+ if @ipv4_allocation_id.nil?
119
+ invalid_properties.push('invalid value for "ipv4_allocation_id", ipv4_allocation_id cannot be nil.')
120
+ end
121
+
122
+ if @cidr.nil?
123
+ invalid_properties.push('invalid value for "cidr", cidr cannot be nil.')
124
+ end
125
+
126
+ pattern = Regexp.new(/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[1-9]|[1-2]\d|3[0-2])$/)
127
+ if @cidr !~ pattern
128
+ invalid_properties.push("invalid value for \"cidr\", must conform to the pattern #{pattern}.")
129
+ end
130
+
131
+ if @status.nil?
132
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
133
+ end
134
+
135
+ if @is_bring_your_own_ip.nil?
136
+ invalid_properties.push('invalid value for "is_bring_your_own_ip", is_bring_your_own_ip cannot be nil.')
137
+ end
138
+
139
+ if @in_use.nil?
140
+ invalid_properties.push('invalid value for "in_use", in_use cannot be nil.')
141
+ end
142
+
143
+ invalid_properties
144
+ end
145
+
146
+ # Check to see if the all the properties in the model are valid
147
+ # @return true if the model is valid
148
+ def valid?
149
+ warn '[DEPRECATED] the `valid?` method is obsolete'
150
+ return false if @ipv4_allocation_id.nil?
151
+ return false if @cidr.nil?
152
+ return false if @cidr !~ Regexp.new(/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[1-9]|[1-2]\d|3[0-2])$/)
153
+ return false if @status.nil?
154
+ return false if @is_bring_your_own_ip.nil?
155
+ return false if @in_use.nil?
156
+ true
157
+ end
158
+
159
+ # Custom attribute writer method with validation
160
+ # @param [Object] cidr Value to be assigned
161
+ def cidr=(cidr)
162
+ if cidr.nil?
163
+ fail ArgumentError, 'cidr cannot be nil'
164
+ end
165
+
166
+ pattern = Regexp.new(/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[1-9]|[1-2]\d|3[0-2])$/)
167
+ if cidr !~ pattern
168
+ fail ArgumentError, "invalid value for \"cidr\", must conform to the pattern #{pattern}."
169
+ end
170
+
171
+ @cidr = cidr
172
+ end
173
+
174
+ # Checks equality by comparing each attribute.
175
+ # @param [Object] Object to be compared
176
+ def ==(o)
177
+ return true if self.equal?(o)
178
+ self.class == o.class &&
179
+ ipv4_allocation_id == o.ipv4_allocation_id &&
180
+ cidr == o.cidr &&
181
+ status == o.status &&
182
+ is_bring_your_own_ip == o.is_bring_your_own_ip &&
183
+ in_use == o.in_use
184
+ end
185
+
186
+ # @see the `==` method
187
+ # @param [Object] Object to be compared
188
+ def eql?(o)
189
+ self == o
190
+ end
191
+
192
+ # Calculates hash code according to all attributes.
193
+ # @return [Integer] Hash code
194
+ def hash
195
+ [ipv4_allocation_id, cidr, status, is_bring_your_own_ip, in_use].hash
196
+ end
197
+
198
+ # Builds the object from hash
199
+ # @param [Hash] attributes Model attributes in the form of hash
200
+ # @return [Object] Returns the model itself
201
+ def self.build_from_hash(attributes)
202
+ return nil unless attributes.is_a?(Hash)
203
+ attributes = attributes.transform_keys(&:to_sym)
204
+ transformed_hash = {}
205
+ openapi_types.each_pair do |key, type|
206
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
207
+ transformed_hash["#{key}"] = nil
208
+ elsif type =~ /\AArray<(.*)>/i
209
+ # check to ensure the input is an array given that the attribute
210
+ # is documented as an array but the input is not
211
+ if attributes[attribute_map[key]].is_a?(Array)
212
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
213
+ end
214
+ elsif !attributes[attribute_map[key]].nil?
215
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
216
+ end
217
+ end
218
+ new(transformed_hash)
219
+ end
220
+
221
+ # Deserializes the data based on type
222
+ # @param string type Data type
223
+ # @param string value Value to be deserialized
224
+ # @return [Object] Deserialized data
225
+ def self._deserialize(type, value)
226
+ case type.to_sym
227
+ when :Time
228
+ Time.parse(value)
229
+ when :Date
230
+ Date.parse(value)
231
+ when :String
232
+ value.to_s
233
+ when :Integer
234
+ value.to_i
235
+ when :Float
236
+ value.to_f
237
+ when :Boolean
238
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
239
+ true
240
+ else
241
+ false
242
+ end
243
+ when :Object
244
+ # generic object (usually a Hash), return directly
245
+ value
246
+ when /\AArray<(?<inner_type>.+)>\z/
247
+ inner_type = Regexp.last_match[:inner_type]
248
+ value.map { |v| _deserialize(inner_type, v) }
249
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
250
+ k_type = Regexp.last_match[:k_type]
251
+ v_type = Regexp.last_match[:v_type]
252
+ {}.tap do |hash|
253
+ value.each do |k, v|
254
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
255
+ end
256
+ end
257
+ else # model
258
+ # models (e.g. Pet) or oneOf
259
+ klass = NetworkApi.const_get(type)
260
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
261
+ end
262
+ end
263
+
264
+ # Returns the string representation of the object
265
+ # @return [String] String presentation of the object
266
+ def to_s
267
+ to_hash.to_s
268
+ end
269
+
270
+ # to_body is an alias to to_hash (backward compatibility)
271
+ # @return [Hash] Returns the object in the form of hash
272
+ def to_body
273
+ to_hash
274
+ end
275
+
276
+ # Returns the object in the form of hash
277
+ # @return [Hash] Returns the object in the form of hash
278
+ def to_hash
279
+ hash = {}
280
+ self.class.attribute_map.each_pair do |attr, param|
281
+ value = self.send(attr)
282
+ if value.nil?
283
+ is_nullable = self.class.openapi_nullable.include?(attr)
284
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
285
+ end
286
+
287
+ hash[param] = _to_hash(value)
288
+ end
289
+ hash
290
+ end
291
+
292
+ # Outputs non-array value in the form of hash
293
+ # For object, use to_hash. Otherwise, just return the value
294
+ # @param [Object] value Any valid value
295
+ # @return [Hash] Returns the value in the form of hash
296
+ def _to_hash(value)
297
+ if value.is_a?(Array)
298
+ value.compact.map { |v| _to_hash(v) }
299
+ elsif value.is_a?(Hash)
300
+ {}.tap do |hash|
301
+ value.each { |k, v| hash[k] = _to_hash(v) }
302
+ end
303
+ elsif value.respond_to? :to_hash
304
+ value.to_hash
305
+ else
306
+ value
307
+ end
308
+ end
309
+
310
+ end
311
+
312
+ end