forestvpn_cloud_api 0.1.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 (81) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +139 -0
  4. data/Rakefile +10 -0
  5. data/docs/Action.md +32 -0
  6. data/docs/Activity.md +36 -0
  7. data/docs/Address.md +28 -0
  8. data/docs/Billing.md +24 -0
  9. data/docs/Country.md +26 -0
  10. data/docs/CreateBillingRequest.md +22 -0
  11. data/docs/CreateOrUpdateDataUsageLimitRequest.md +20 -0
  12. data/docs/CreateOrUpdatePaymentProfileRequest.md +34 -0
  13. data/docs/CreateOrUpdateProfileRequest.md +22 -0
  14. data/docs/DataUsageLimit.md +24 -0
  15. data/docs/Error.md +20 -0
  16. data/docs/GeoApi.md +77 -0
  17. data/docs/LimitsApi.md +447 -0
  18. data/docs/Location.md +28 -0
  19. data/docs/PaymentMethod.md +24 -0
  20. data/docs/PaymentProfile.md +32 -0
  21. data/docs/Profile.md +26 -0
  22. data/docs/ProfileStats.md +26 -0
  23. data/docs/ProfilesApi.md +996 -0
  24. data/docs/Project.md +22 -0
  25. data/docs/ResourceRef.md +20 -0
  26. data/docs/User.md +32 -0
  27. data/forestvpn_cloud_api.gemspec +39 -0
  28. data/git_push.sh +57 -0
  29. data/lib/forestvpn_cloud_api/api/geo_api.rb +77 -0
  30. data/lib/forestvpn_cloud_api/api/limits_api.rb +405 -0
  31. data/lib/forestvpn_cloud_api/api/profiles_api.rb +915 -0
  32. data/lib/forestvpn_cloud_api/api_client.rb +426 -0
  33. data/lib/forestvpn_cloud_api/api_error.rb +57 -0
  34. data/lib/forestvpn_cloud_api/configuration.rb +335 -0
  35. data/lib/forestvpn_cloud_api/models/action.rb +348 -0
  36. data/lib/forestvpn_cloud_api/models/activity.rb +360 -0
  37. data/lib/forestvpn_cloud_api/models/address.rb +269 -0
  38. data/lib/forestvpn_cloud_api/models/billing.rb +266 -0
  39. data/lib/forestvpn_cloud_api/models/country.rb +282 -0
  40. data/lib/forestvpn_cloud_api/models/create_billing_request.rb +252 -0
  41. data/lib/forestvpn_cloud_api/models/create_or_update_data_usage_limit_request.rb +230 -0
  42. data/lib/forestvpn_cloud_api/models/create_or_update_payment_profile_request.rb +328 -0
  43. data/lib/forestvpn_cloud_api/models/create_or_update_profile_request.rb +275 -0
  44. data/lib/forestvpn_cloud_api/models/data_usage_limit.rb +302 -0
  45. data/lib/forestvpn_cloud_api/models/error.rb +238 -0
  46. data/lib/forestvpn_cloud_api/models/location.rb +296 -0
  47. data/lib/forestvpn_cloud_api/models/payment_method.rb +261 -0
  48. data/lib/forestvpn_cloud_api/models/payment_profile.rb +313 -0
  49. data/lib/forestvpn_cloud_api/models/profile.rb +320 -0
  50. data/lib/forestvpn_cloud_api/models/profile_stats.rb +280 -0
  51. data/lib/forestvpn_cloud_api/models/project.rb +254 -0
  52. data/lib/forestvpn_cloud_api/models/resource_ref.rb +238 -0
  53. data/lib/forestvpn_cloud_api/models/user.rb +307 -0
  54. data/lib/forestvpn_cloud_api/version.rb +15 -0
  55. data/lib/forestvpn_cloud_api.rb +61 -0
  56. data/spec/api/geo_api_spec.rb +45 -0
  57. data/spec/api/limits_api_spec.rb +102 -0
  58. data/spec/api/profiles_api_spec.rb +195 -0
  59. data/spec/api_client_spec.rb +188 -0
  60. data/spec/configuration_spec.rb +42 -0
  61. data/spec/models/action_spec.rb +80 -0
  62. data/spec/models/activity_spec.rb +92 -0
  63. data/spec/models/address_spec.rb +64 -0
  64. data/spec/models/billing_spec.rb +52 -0
  65. data/spec/models/country_spec.rb +58 -0
  66. data/spec/models/create_billing_request_spec.rb +46 -0
  67. data/spec/models/create_or_update_data_usage_limit_request_spec.rb +40 -0
  68. data/spec/models/create_or_update_payment_profile_request_spec.rb +82 -0
  69. data/spec/models/create_or_update_profile_request_spec.rb +50 -0
  70. data/spec/models/data_usage_limit_spec.rb +56 -0
  71. data/spec/models/error_spec.rb +40 -0
  72. data/spec/models/location_spec.rb +64 -0
  73. data/spec/models/payment_method_spec.rb +52 -0
  74. data/spec/models/payment_profile_spec.rb +76 -0
  75. data/spec/models/profile_spec.rb +62 -0
  76. data/spec/models/profile_stats_spec.rb +58 -0
  77. data/spec/models/project_spec.rb +46 -0
  78. data/spec/models/resource_ref_spec.rb +40 -0
  79. data/spec/models/user_spec.rb +76 -0
  80. data/spec/spec_helper.rb +111 -0
  81. metadata +203 -0
@@ -0,0 +1,335 @@
1
+ =begin
2
+ #ForestVPN Cloud API
3
+
4
+ #ForestVPN Cloud - it's a Google Cloud but for VPN apps. Ready to use VPN Cloud Platform minimizes efforts to build fast, secure, and modern VPN apps.
5
+
6
+ The version of the OpenAPI document: 2.0
7
+ Contact: support@forestvpn.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.0
10
+
11
+ =end
12
+
13
+ module ForestVPNCloudAPI
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
+ # details will be logged with `logger.debug` (see the `logger` attribute).
67
+ # Default to false.
68
+ #
69
+ # @return [true, false]
70
+ attr_accessor :debugging
71
+
72
+ # Defines the logger used for debugging.
73
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
+ #
75
+ # @return [#debug]
76
+ attr_accessor :logger
77
+
78
+ # Defines the temporary folder to store downloaded files
79
+ # (for API endpoints that have file response).
80
+ # Default to use `Tempfile`.
81
+ #
82
+ # @return [String]
83
+ attr_accessor :temp_folder_path
84
+
85
+ # The time limit for HTTP request in seconds.
86
+ # Default to 0 (never times out).
87
+ attr_accessor :timeout
88
+
89
+ # Set this to false to skip client side validation in the operation.
90
+ # Default to true.
91
+ # @return [true, false]
92
+ attr_accessor :client_side_validation
93
+
94
+ ### TLS/SSL setting
95
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
96
+ # Default to true.
97
+ #
98
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
99
+ #
100
+ # @return [true, false]
101
+ attr_accessor :ssl_verify
102
+
103
+ ### TLS/SSL setting
104
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
105
+ #
106
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
107
+ #
108
+ attr_accessor :ssl_verify_mode
109
+
110
+ ### TLS/SSL setting
111
+ # Set this to customize the certificate file to verify the peer.
112
+ #
113
+ # @return [String] the path to the certificate file
114
+ attr_accessor :ssl_ca_file
115
+
116
+ ### TLS/SSL setting
117
+ # Client certificate file (for client certificate)
118
+ attr_accessor :ssl_client_cert
119
+
120
+ ### TLS/SSL setting
121
+ # Client private key file (for client certificate)
122
+ attr_accessor :ssl_client_key
123
+
124
+ ### Proxy setting
125
+ # HTTP Proxy settings
126
+ attr_accessor :proxy
127
+
128
+ # Set this to customize parameters encoder of array parameter.
129
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
130
+ #
131
+ # @see The params_encoder option of Faraday. Related source code:
132
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
133
+ attr_accessor :params_encoder
134
+
135
+
136
+ attr_accessor :inject_format
137
+
138
+ attr_accessor :force_ending_format
139
+
140
+ def initialize
141
+ @scheme = 'https'
142
+ @host = 'api.forestvpn.com'
143
+ @base_path = '/cloud/v1'
144
+ @server_index = 0
145
+ @server_operation_index = {}
146
+ @server_variables = {}
147
+ @server_operation_variables = {}
148
+ @api_key = {}
149
+ @api_key_prefix = {}
150
+ @client_side_validation = true
151
+ @ssl_verify = true
152
+ @ssl_verify_mode = nil
153
+ @ssl_ca_file = nil
154
+ @ssl_client_cert = nil
155
+ @ssl_client_key = nil
156
+ @middlewares = []
157
+ @request_middlewares = []
158
+ @response_middlewares = []
159
+ @timeout = 60
160
+ # return data as binary instead of file
161
+ @return_binary_data = false
162
+ @params_encoder = nil
163
+ @debugging = false
164
+ @inject_format = false
165
+ @force_ending_format = false
166
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
167
+
168
+ yield(self) if block_given?
169
+ end
170
+
171
+ # The default Configuration object.
172
+ def self.default
173
+ @@default ||= Configuration.new
174
+ end
175
+
176
+ def configure
177
+ yield(self) if block_given?
178
+ end
179
+
180
+ def scheme=(scheme)
181
+ # remove :// from scheme
182
+ @scheme = scheme.sub(/:\/\//, '')
183
+ end
184
+
185
+ def host=(host)
186
+ # remove http(s):// and anything after a slash
187
+ @host = host.sub(/https?:\/\//, '').split('/').first
188
+ end
189
+
190
+ def base_path=(base_path)
191
+ # Add leading and trailing slashes to base_path
192
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
193
+ @base_path = '' if @base_path == '/'
194
+ end
195
+
196
+ # Returns base URL for specified operation based on server settings
197
+ def base_url(operation = nil)
198
+ index = server_operation_index.fetch(operation, server_index)
199
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
200
+
201
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
202
+ end
203
+
204
+ # Gets API key (with prefix if set).
205
+ # @param [String] param_name the parameter name of API key auth
206
+ def api_key_with_prefix(param_name, param_alias = nil)
207
+ key = @api_key[param_name]
208
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
209
+ if @api_key_prefix[param_name]
210
+ "#{@api_key_prefix[param_name]} #{key}"
211
+ else
212
+ key
213
+ end
214
+ end
215
+
216
+ # Gets Basic Auth token string
217
+ def basic_auth_token
218
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
219
+ end
220
+
221
+ # Returns Auth Settings hash for api client.
222
+ def auth_settings
223
+ {
224
+ 'ApiTokenAuth' =>
225
+ {
226
+ type: 'api_key',
227
+ in: 'header',
228
+ key: 'X-API-TOKEN',
229
+ value: api_key_with_prefix('ApiTokenAuth')
230
+ },
231
+ 'BearerTokenAuth' =>
232
+ {
233
+ type: 'bearer',
234
+ in: 'header',
235
+ format: 'JWT',
236
+ key: 'Authorization',
237
+ value: "Bearer #{access_token}"
238
+ },
239
+ }
240
+ end
241
+
242
+ # Returns an array of Server setting
243
+ def server_settings
244
+ [
245
+ {
246
+ url: "{scheme}://{host}/cloud/v1",
247
+ description: "No description provided",
248
+ variables: {
249
+ host: {
250
+ description: "No description provided",
251
+ default_value: "api.forestvpn.com",
252
+ },
253
+ scheme: {
254
+ description: "No description provided",
255
+ default_value: "https",
256
+ enum_values: [
257
+ "https",
258
+ "http"
259
+ ]
260
+ }
261
+ }
262
+ }
263
+ ]
264
+ end
265
+
266
+ def operation_server_settings
267
+ {
268
+ }
269
+ end
270
+
271
+ # Returns URL based on server settings
272
+ #
273
+ # @param index array index of the server settings
274
+ # @param variables hash of variable and the corresponding value
275
+ def server_url(index, variables = {}, servers = nil)
276
+ servers = server_settings if servers == nil
277
+
278
+ # check array index out of bound
279
+ if (index < 0 || index >= servers.size)
280
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
281
+ end
282
+
283
+ server = servers[index]
284
+ url = server[:url]
285
+
286
+ return url unless server.key? :variables
287
+
288
+ # go through variable and assign a value
289
+ server[:variables].each do |name, variable|
290
+ if variables.key?(name)
291
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
292
+ url.gsub! "{" + name.to_s + "}", variables[name]
293
+ else
294
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
295
+ end
296
+ else
297
+ # use default value
298
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
299
+ end
300
+ end
301
+
302
+ url
303
+ end
304
+
305
+ # Adds middleware to the stack
306
+ def use(*middleware)
307
+ @middlewares << middleware
308
+ end
309
+
310
+ # Adds request middleware to the stack
311
+ def request(*middleware)
312
+ @request_middlewares << middleware
313
+ end
314
+
315
+ # Adds response middleware to the stack
316
+ def response(*middleware)
317
+ @response_middlewares << middleware
318
+ end
319
+
320
+ # Set up middleware on the connection
321
+ def configure_middleware(connection)
322
+ @middlewares.each do |middleware|
323
+ connection.use(*middleware)
324
+ end
325
+
326
+ @request_middlewares.each do |middleware|
327
+ connection.request(*middleware)
328
+ end
329
+
330
+ @response_middlewares.each do |middleware|
331
+ connection.response(*middleware)
332
+ end
333
+ end
334
+ end
335
+ end
@@ -0,0 +1,348 @@
1
+ =begin
2
+ #ForestVPN Cloud API
3
+
4
+ #ForestVPN Cloud - it's a Google Cloud but for VPN apps. Ready to use VPN Cloud Platform minimizes efforts to build fast, secure, and modern VPN apps.
5
+
6
+ The version of the OpenAPI document: 2.0
7
+ Contact: support@forestvpn.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module ForestVPNCloudAPI
17
+ class Action
18
+ attr_accessor :id
19
+
20
+ attr_accessor :command
21
+
22
+ attr_accessor :error
23
+
24
+ attr_accessor :status
25
+
26
+ attr_accessor :progress
27
+
28
+ attr_accessor :resources
29
+
30
+ attr_accessor :created_at
31
+
32
+ attr_accessor :finished_at
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
+ :'command' => :'command',
61
+ :'error' => :'error',
62
+ :'status' => :'status',
63
+ :'progress' => :'progress',
64
+ :'resources' => :'resources',
65
+ :'created_at' => :'created_at',
66
+ :'finished_at' => :'finished_at'
67
+ }
68
+ end
69
+
70
+ # Returns all the JSON keys this model knows about
71
+ def self.acceptable_attributes
72
+ attribute_map.values
73
+ end
74
+
75
+ # Attribute type mapping.
76
+ def self.openapi_types
77
+ {
78
+ :'id' => :'String',
79
+ :'command' => :'String',
80
+ :'error' => :'Error',
81
+ :'status' => :'String',
82
+ :'progress' => :'Float',
83
+ :'resources' => :'Array<ResourceRef>',
84
+ :'created_at' => :'Time',
85
+ :'finished_at' => :'Time'
86
+ }
87
+ end
88
+
89
+ # List of attributes with nullable: true
90
+ def self.openapi_nullable
91
+ Set.new([
92
+ ])
93
+ end
94
+
95
+ # Initializes the object
96
+ # @param [Hash] attributes Model attributes in the form of hash
97
+ def initialize(attributes = {})
98
+ if (!attributes.is_a?(Hash))
99
+ fail ArgumentError, "The input argument (attributes) must be a hash in `ForestVPNCloudAPI::Action` initialize method"
100
+ end
101
+
102
+ # check to see if the attribute exists and convert string to symbol for hash key
103
+ attributes = attributes.each_with_object({}) { |(k, v), h|
104
+ if (!self.class.attribute_map.key?(k.to_sym))
105
+ fail ArgumentError, "`#{k}` is not a valid attribute in `ForestVPNCloudAPI::Action`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
106
+ end
107
+ h[k.to_sym] = v
108
+ }
109
+
110
+ if attributes.key?(:'id')
111
+ self.id = attributes[:'id']
112
+ end
113
+
114
+ if attributes.key?(:'command')
115
+ self.command = attributes[:'command']
116
+ end
117
+
118
+ if attributes.key?(:'error')
119
+ self.error = attributes[:'error']
120
+ end
121
+
122
+ if attributes.key?(:'status')
123
+ self.status = attributes[:'status']
124
+ end
125
+
126
+ if attributes.key?(:'progress')
127
+ self.progress = attributes[:'progress']
128
+ end
129
+
130
+ if attributes.key?(:'resources')
131
+ if (value = attributes[:'resources']).is_a?(Array)
132
+ self.resources = value
133
+ end
134
+ end
135
+
136
+ if attributes.key?(:'created_at')
137
+ self.created_at = attributes[:'created_at']
138
+ end
139
+
140
+ if attributes.key?(:'finished_at')
141
+ self.finished_at = attributes[:'finished_at']
142
+ end
143
+ end
144
+
145
+ # Show invalid properties with the reasons. Usually used together with valid?
146
+ # @return Array for valid properties with the reasons
147
+ def list_invalid_properties
148
+ invalid_properties = Array.new
149
+ if @id.nil?
150
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
151
+ end
152
+
153
+ if @command.nil?
154
+ invalid_properties.push('invalid value for "command", command cannot be nil.')
155
+ end
156
+
157
+ if @status.nil?
158
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
159
+ end
160
+
161
+ if @progress.nil?
162
+ invalid_properties.push('invalid value for "progress", progress cannot be nil.')
163
+ end
164
+
165
+ if @resources.nil?
166
+ invalid_properties.push('invalid value for "resources", resources cannot be nil.')
167
+ end
168
+
169
+ if @created_at.nil?
170
+ invalid_properties.push('invalid value for "created_at", created_at cannot be nil.')
171
+ end
172
+
173
+ invalid_properties
174
+ end
175
+
176
+ # Check to see if the all the properties in the model are valid
177
+ # @return true if the model is valid
178
+ def valid?
179
+ return false if @id.nil?
180
+ return false if @command.nil?
181
+ return false if @status.nil?
182
+ status_validator = EnumAttributeValidator.new('String', ["running", "failed", "success"])
183
+ return false unless status_validator.valid?(@status)
184
+ return false if @progress.nil?
185
+ return false if @resources.nil?
186
+ return false if @created_at.nil?
187
+ true
188
+ end
189
+
190
+ # Custom attribute writer method checking allowed values (enum).
191
+ # @param [Object] status Object to be assigned
192
+ def status=(status)
193
+ validator = EnumAttributeValidator.new('String', ["running", "failed", "success"])
194
+ unless validator.valid?(status)
195
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
196
+ end
197
+ @status = status
198
+ end
199
+
200
+ # Checks equality by comparing each attribute.
201
+ # @param [Object] Object to be compared
202
+ def ==(o)
203
+ return true if self.equal?(o)
204
+ self.class == o.class &&
205
+ id == o.id &&
206
+ command == o.command &&
207
+ error == o.error &&
208
+ status == o.status &&
209
+ progress == o.progress &&
210
+ resources == o.resources &&
211
+ created_at == o.created_at &&
212
+ finished_at == o.finished_at
213
+ end
214
+
215
+ # @see the `==` method
216
+ # @param [Object] Object to be compared
217
+ def eql?(o)
218
+ self == o
219
+ end
220
+
221
+ # Calculates hash code according to all attributes.
222
+ # @return [Integer] Hash code
223
+ def hash
224
+ [id, command, error, status, progress, resources, created_at, finished_at].hash
225
+ end
226
+
227
+ # Builds the object from hash
228
+ # @param [Hash] attributes Model attributes in the form of hash
229
+ # @return [Object] Returns the model itself
230
+ def self.build_from_hash(attributes)
231
+ new.build_from_hash(attributes)
232
+ end
233
+
234
+ # Builds the object from hash
235
+ # @param [Hash] attributes Model attributes in the form of hash
236
+ # @return [Object] Returns the model itself
237
+ def build_from_hash(attributes)
238
+ return nil unless attributes.is_a?(Hash)
239
+ attributes = attributes.transform_keys(&:to_sym)
240
+ self.class.openapi_types.each_pair do |key, type|
241
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
242
+ self.send("#{key}=", nil)
243
+ elsif type =~ /\AArray<(.*)>/i
244
+ # check to ensure the input is an array given that the attribute
245
+ # is documented as an array but the input is not
246
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
247
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
248
+ end
249
+ elsif !attributes[self.class.attribute_map[key]].nil?
250
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
251
+ end
252
+ end
253
+
254
+ self
255
+ end
256
+
257
+ # Deserializes the data based on type
258
+ # @param string type Data type
259
+ # @param string value Value to be deserialized
260
+ # @return [Object] Deserialized data
261
+ def _deserialize(type, value)
262
+ case type.to_sym
263
+ when :Time
264
+ Time.parse(value)
265
+ when :Date
266
+ Date.parse(value)
267
+ when :String
268
+ value.to_s
269
+ when :Integer
270
+ value.to_i
271
+ when :Float
272
+ value.to_f
273
+ when :Boolean
274
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
275
+ true
276
+ else
277
+ false
278
+ end
279
+ when :Object
280
+ # generic object (usually a Hash), return directly
281
+ value
282
+ when /\AArray<(?<inner_type>.+)>\z/
283
+ inner_type = Regexp.last_match[:inner_type]
284
+ value.map { |v| _deserialize(inner_type, v) }
285
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
286
+ k_type = Regexp.last_match[:k_type]
287
+ v_type = Regexp.last_match[:v_type]
288
+ {}.tap do |hash|
289
+ value.each do |k, v|
290
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
291
+ end
292
+ end
293
+ else # model
294
+ # models (e.g. Pet) or oneOf
295
+ klass = ForestVPNCloudAPI.const_get(type)
296
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
297
+ end
298
+ end
299
+
300
+ # Returns the string representation of the object
301
+ # @return [String] String presentation of the object
302
+ def to_s
303
+ to_hash.to_s
304
+ end
305
+
306
+ # to_body is an alias to to_hash (backward compatibility)
307
+ # @return [Hash] Returns the object in the form of hash
308
+ def to_body
309
+ to_hash
310
+ end
311
+
312
+ # Returns the object in the form of hash
313
+ # @return [Hash] Returns the object in the form of hash
314
+ def to_hash
315
+ hash = {}
316
+ self.class.attribute_map.each_pair do |attr, param|
317
+ value = self.send(attr)
318
+ if value.nil?
319
+ is_nullable = self.class.openapi_nullable.include?(attr)
320
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
321
+ end
322
+
323
+ hash[param] = _to_hash(value)
324
+ end
325
+ hash
326
+ end
327
+
328
+ # Outputs non-array value in the form of hash
329
+ # For object, use to_hash. Otherwise, just return the value
330
+ # @param [Object] value Any valid value
331
+ # @return [Hash] Returns the value in the form of hash
332
+ def _to_hash(value)
333
+ if value.is_a?(Array)
334
+ value.compact.map { |v| _to_hash(v) }
335
+ elsif value.is_a?(Hash)
336
+ {}.tap do |hash|
337
+ value.each { |k, v| hash[k] = _to_hash(v) }
338
+ end
339
+ elsif value.respond_to? :to_hash
340
+ value.to_hash
341
+ else
342
+ value
343
+ end
344
+ end
345
+
346
+ end
347
+
348
+ end