pnap_billing_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +187 -0
  4. data/Rakefile +10 -0
  5. data/VERSION +1 -0
  6. data/docs/ApplicableDiscounts.md +20 -0
  7. data/docs/BandwidthDetails.md +24 -0
  8. data/docs/BandwidthRecord.md +56 -0
  9. data/docs/BillingConfigurationsApi.md +74 -0
  10. data/docs/ConfigurationDetails.md +18 -0
  11. data/docs/DiscountDetails.md +22 -0
  12. data/docs/Error.md +20 -0
  13. data/docs/LocationAvailabilityDetail.md +26 -0
  14. data/docs/LocationEnum.md +15 -0
  15. data/docs/OperatingSystemDetails.md +20 -0
  16. data/docs/OperatingSystemRecord.md +56 -0
  17. data/docs/PriceUnitEnum.md +15 -0
  18. data/docs/PricingPlan.md +36 -0
  19. data/docs/Product.md +22 -0
  20. data/docs/ProductAvailability.md +22 -0
  21. data/docs/ProductCategoryEnum.md +15 -0
  22. data/docs/ProductsApi.md +167 -0
  23. data/docs/ProductsGet200ResponseInner.md +82 -0
  24. data/docs/PublicSubnetDetails.md +22 -0
  25. data/docs/PublicSubnetRecord.md +56 -0
  26. data/docs/RatedUsageApi.md +155 -0
  27. data/docs/RatedUsageGet200ResponseInner.md +88 -0
  28. data/docs/RatedUsageRecord.md +54 -0
  29. data/docs/Reservation.md +48 -0
  30. data/docs/ReservationAutoRenewDisableRequest.md +18 -0
  31. data/docs/ReservationInvoicingModelEnum.md +15 -0
  32. data/docs/ReservationModelEnum.md +15 -0
  33. data/docs/ReservationRequest.md +18 -0
  34. data/docs/ReservationsApi.md +439 -0
  35. data/docs/ServerDetails.md +20 -0
  36. data/docs/ServerProduct.md +24 -0
  37. data/docs/ServerProductMetadata.md +30 -0
  38. data/docs/ServerRecord.md +56 -0
  39. data/docs/StorageDetails.md +28 -0
  40. data/docs/StorageRecord.md +56 -0
  41. data/docs/ThresholdConfigurationDetails.md +18 -0
  42. data/lib/pnap_billing_api/api/billing_configurations_api.rb +79 -0
  43. data/lib/pnap_billing_api/api/products_api.rb +174 -0
  44. data/lib/pnap_billing_api/api/rated_usage_api.rb +156 -0
  45. data/lib/pnap_billing_api/api/reservations_api.rb +412 -0
  46. data/lib/pnap_billing_api/api_client.rb +397 -0
  47. data/lib/pnap_billing_api/api_error.rb +58 -0
  48. data/lib/pnap_billing_api/configuration.rb +298 -0
  49. data/lib/pnap_billing_api/models/applicable_discounts.rb +227 -0
  50. data/lib/pnap_billing_api/models/bandwidth_details.rb +294 -0
  51. data/lib/pnap_billing_api/models/bandwidth_record.rb +548 -0
  52. data/lib/pnap_billing_api/models/configuration_details.rb +215 -0
  53. data/lib/pnap_billing_api/models/discount_details.rb +291 -0
  54. data/lib/pnap_billing_api/models/error.rb +234 -0
  55. data/lib/pnap_billing_api/models/location_availability_detail.rb +314 -0
  56. data/lib/pnap_billing_api/models/location_enum.rb +45 -0
  57. data/lib/pnap_billing_api/models/operating_system_details.rb +240 -0
  58. data/lib/pnap_billing_api/models/operating_system_record.rb +548 -0
  59. data/lib/pnap_billing_api/models/price_unit_enum.rb +44 -0
  60. data/lib/pnap_billing_api/models/pricing_plan.rb +397 -0
  61. data/lib/pnap_billing_api/models/product.rb +252 -0
  62. data/lib/pnap_billing_api/models/product_availability.rb +258 -0
  63. data/lib/pnap_billing_api/models/product_category_enum.rb +43 -0
  64. data/lib/pnap_billing_api/models/products_get200_response_inner.rb +61 -0
  65. data/lib/pnap_billing_api/models/public_subnet_details.rb +250 -0
  66. data/lib/pnap_billing_api/models/public_subnet_record.rb +548 -0
  67. data/lib/pnap_billing_api/models/rated_usage_get200_response_inner.rb +64 -0
  68. data/lib/pnap_billing_api/models/rated_usage_record.rb +526 -0
  69. data/lib/pnap_billing_api/models/reservation.rb +466 -0
  70. data/lib/pnap_billing_api/models/reservation_auto_renew_disable_request.rb +215 -0
  71. data/lib/pnap_billing_api/models/reservation_invoicing_model_enum.rb +40 -0
  72. data/lib/pnap_billing_api/models/reservation_model_enum.rb +43 -0
  73. data/lib/pnap_billing_api/models/reservation_request.rb +223 -0
  74. data/lib/pnap_billing_api/models/server_details.rb +240 -0
  75. data/lib/pnap_billing_api/models/server_product.rb +274 -0
  76. data/lib/pnap_billing_api/models/server_product_metadata.rb +325 -0
  77. data/lib/pnap_billing_api/models/server_record.rb +548 -0
  78. data/lib/pnap_billing_api/models/storage_details.rb +308 -0
  79. data/lib/pnap_billing_api/models/storage_record.rb +548 -0
  80. data/lib/pnap_billing_api/models/threshold_configuration_details.rb +223 -0
  81. data/lib/pnap_billing_api/version.rb +19 -0
  82. data/lib/pnap_billing_api.rb +75 -0
  83. data/pnap_billing_api.gemspec +39 -0
  84. data/spec/api/billing_configurations_api_spec.rb +46 -0
  85. data/spec/api/products_api_spec.rb +67 -0
  86. data/spec/api/rated_usage_api_spec.rb +61 -0
  87. data/spec/api/reservations_api_spec.rb +109 -0
  88. data/spec/models/applicable_discounts_spec.rb +42 -0
  89. data/spec/models/bandwidth_details_spec.rb +58 -0
  90. data/spec/models/bandwidth_record_spec.rb +154 -0
  91. data/spec/models/configuration_details_spec.rb +36 -0
  92. data/spec/models/discount_details_spec.rb +52 -0
  93. data/spec/models/error_spec.rb +42 -0
  94. data/spec/models/location_availability_detail_spec.rb +64 -0
  95. data/spec/models/location_enum_spec.rb +30 -0
  96. data/spec/models/operating_system_details_spec.rb +42 -0
  97. data/spec/models/operating_system_record_spec.rb +154 -0
  98. data/spec/models/price_unit_enum_spec.rb +30 -0
  99. data/spec/models/pricing_plan_spec.rb +102 -0
  100. data/spec/models/product_availability_spec.rb +48 -0
  101. data/spec/models/product_category_enum_spec.rb +30 -0
  102. data/spec/models/product_spec.rb +48 -0
  103. data/spec/models/products_get200_response_inner_spec.rb +44 -0
  104. data/spec/models/public_subnet_details_spec.rb +48 -0
  105. data/spec/models/public_subnet_record_spec.rb +154 -0
  106. data/spec/models/rated_usage_get200_response_inner_spec.rb +44 -0
  107. data/spec/models/rated_usage_record_spec.rb +148 -0
  108. data/spec/models/reservation_auto_renew_disable_request_spec.rb +36 -0
  109. data/spec/models/reservation_invoicing_model_enum_spec.rb +30 -0
  110. data/spec/models/reservation_model_enum_spec.rb +30 -0
  111. data/spec/models/reservation_request_spec.rb +36 -0
  112. data/spec/models/reservation_spec.rb +130 -0
  113. data/spec/models/server_details_spec.rb +42 -0
  114. data/spec/models/server_product_metadata_spec.rb +72 -0
  115. data/spec/models/server_product_spec.rb +54 -0
  116. data/spec/models/server_record_spec.rb +154 -0
  117. data/spec/models/storage_details_spec.rb +66 -0
  118. data/spec/models/storage_record_spec.rb +154 -0
  119. data/spec/models/threshold_configuration_details_spec.rb +36 -0
  120. data/spec/spec_helper.rb +111 -0
  121. metadata +240 -0
@@ -0,0 +1,397 @@
1
+ =begin
2
+ #Billing API
3
+
4
+ #Automate your infrastructure billing with the Bare Metal Cloud Billing API. Reserve your server instances to ensure guaranteed resource availability for 12, 24, and 36 months. Retrieve your server’s rated usage for a given period and enable or disable auto-renewals.<br> <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/phoenixnap-bare-metal-cloud-billing-models' target='_blank'>here</a> </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/billing/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: 7.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+
21
+ module BillingApi
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @config.params_encoding = :multi
36
+ @user_agent = "PNAP-ruby-sdk-bmc/#{ BillingApi::VERSION }"
37
+ @powered_by = "PNAP-ruby-sdk-bmc/#{ BillingApi::VERSION }"
38
+ @default_headers = {
39
+ 'Content-Type' => 'application/json',
40
+ 'User-Agent' => @user_agent,
41
+ 'X-Powered-By' => @powered_by
42
+ }
43
+ end
44
+
45
+ def self.default
46
+ @@default ||= ApiClient.new
47
+ end
48
+
49
+ # Call an API with given options.
50
+ #
51
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
52
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
53
+ def call_api(http_method, path, opts = {})
54
+ request = build_request(http_method, path, opts)
55
+ tempfile = download_file(request) if opts[:return_type] == 'File'
56
+ response = request.run
57
+
58
+ if @config.debugging
59
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
60
+ end
61
+
62
+ unless response.success?
63
+ if response.timed_out?
64
+ fail ApiError.new('Connection timed out')
65
+ elsif response.code == 0
66
+ # Errors from libcurl will be made visible here
67
+ fail ApiError.new(:code => 0,
68
+ :message => response.return_message)
69
+ else
70
+ fail ApiError.new(:code => response.code,
71
+ :response_headers => response.headers,
72
+ :response_body => response.body),
73
+ response.status_message
74
+ end
75
+ end
76
+
77
+ if opts[:return_type] == 'File'
78
+ data = tempfile
79
+ elsif opts[:return_type]
80
+ data = deserialize(response, opts[:return_type])
81
+ else
82
+ data = nil
83
+ end
84
+ return data, response.code, response.headers
85
+ end
86
+
87
+ # Builds the HTTP request
88
+ #
89
+ # @param [String] http_method HTTP method/verb (e.g. POST)
90
+ # @param [String] path URL path (e.g. /account/new)
91
+ # @option opts [Hash] :header_params Header parameters
92
+ # @option opts [Hash] :query_params Query parameters
93
+ # @option opts [Hash] :form_params Query parameters
94
+ # @option opts [Object] :body HTTP body (JSON/XML)
95
+ # @return [Typhoeus::Request] A Typhoeus Request
96
+ def build_request(http_method, path, opts = {})
97
+ url = build_request_url(path, opts)
98
+ http_method = http_method.to_sym.downcase
99
+
100
+ header_params = @default_headers.merge(opts[:header_params] || {})
101
+ query_params = opts[:query_params] || {}
102
+ form_params = opts[:form_params] || {}
103
+ follow_location = opts[:follow_location] || true
104
+
105
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
106
+
107
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
108
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
109
+
110
+ req_opts = {
111
+ :method => http_method,
112
+ :headers => header_params,
113
+ :params => query_params,
114
+ :params_encoding => @config.params_encoding,
115
+ :timeout => @config.timeout,
116
+ :ssl_verifypeer => @config.verify_ssl,
117
+ :ssl_verifyhost => _verify_ssl_host,
118
+ :sslcert => @config.cert_file,
119
+ :sslkey => @config.key_file,
120
+ :verbose => @config.debugging,
121
+ :followlocation => follow_location
122
+ }
123
+
124
+ # set custom cert, if provided
125
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
126
+
127
+ if [:post, :patch, :put, :delete].include?(http_method)
128
+ req_body = build_request_body(header_params, form_params, opts[:body])
129
+ req_opts.update :body => req_body
130
+ if @config.debugging
131
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
132
+ end
133
+ end
134
+
135
+ Typhoeus::Request.new(url, req_opts)
136
+ end
137
+
138
+ # Builds the HTTP request body
139
+ #
140
+ # @param [Hash] header_params Header parameters
141
+ # @param [Hash] form_params Query parameters
142
+ # @param [Object] body HTTP body (JSON/XML)
143
+ # @return [String] HTTP body data in the form of string
144
+ def build_request_body(header_params, form_params, body)
145
+ # http form
146
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
147
+ header_params['Content-Type'] == 'multipart/form-data'
148
+ data = {}
149
+ form_params.each do |key, value|
150
+ case value
151
+ when ::File, ::Array, nil
152
+ # let typhoeus handle File, Array and nil parameters
153
+ data[key] = value
154
+ else
155
+ data[key] = value.to_s
156
+ end
157
+ end
158
+ elsif body
159
+ data = body.is_a?(String) ? body : body.to_json
160
+ else
161
+ data = nil
162
+ end
163
+ data
164
+ end
165
+
166
+ # Save response body into a file in (the defined) temporary folder, using the filename
167
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
168
+ # The response body is written to the file in chunks in order to handle files which
169
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
170
+ # process can use.
171
+ #
172
+ # @see Configuration#temp_folder_path
173
+ #
174
+ # @return [Tempfile] the tempfile generated
175
+ def download_file(request)
176
+ tempfile = nil
177
+ encoding = nil
178
+ request.on_headers do |response|
179
+ content_disposition = response.headers['Content-Disposition']
180
+ if content_disposition && content_disposition =~ /filename=/i
181
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
182
+ prefix = sanitize_filename(filename)
183
+ else
184
+ prefix = 'download-'
185
+ end
186
+ prefix = prefix + '-' unless prefix.end_with?('-')
187
+ encoding = response.body.encoding
188
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
189
+ end
190
+ request.on_body do |chunk|
191
+ chunk.force_encoding(encoding)
192
+ tempfile.write(chunk)
193
+ end
194
+ # run the request to ensure the tempfile is created successfully before returning it
195
+ request.run
196
+ if tempfile
197
+ tempfile.close
198
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
199
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
200
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
201
+ "explicitly with `tempfile.delete`"
202
+ else
203
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
204
+ end
205
+
206
+ tempfile
207
+ end
208
+
209
+ # Check if the given MIME is a JSON MIME.
210
+ # JSON MIME examples:
211
+ # application/json
212
+ # application/json; charset=UTF8
213
+ # APPLICATION/JSON
214
+ # */*
215
+ # @param [String] mime MIME
216
+ # @return [Boolean] True if the MIME is application/json
217
+ def json_mime?(mime)
218
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
219
+ end
220
+
221
+ # Deserialize the response to the given return type.
222
+ #
223
+ # @param [Response] response HTTP response
224
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
225
+ def deserialize(response, return_type)
226
+ body = response.body
227
+ return nil if body.nil? || body.empty?
228
+
229
+ # return response body directly for String return type
230
+ return body.to_s if return_type == 'String'
231
+
232
+ # ensuring a default content type
233
+ content_type = response.headers['Content-Type'] || 'application/json'
234
+
235
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
236
+
237
+ begin
238
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
239
+ rescue JSON::ParserError => e
240
+ if %w(String Date Time).include?(return_type)
241
+ data = body
242
+ else
243
+ raise e
244
+ end
245
+ end
246
+
247
+ convert_to_type data, return_type
248
+ end
249
+
250
+ # Convert data to the given return type.
251
+ # @param [Object] data Data to be converted
252
+ # @param [String] return_type Return type
253
+ # @return [Mixed] Data in a particular type
254
+ def convert_to_type(data, return_type)
255
+ return nil if data.nil?
256
+ case return_type
257
+ when 'String'
258
+ data.to_s
259
+ when 'Integer'
260
+ data.to_i
261
+ when 'Float'
262
+ data.to_f
263
+ when 'Boolean'
264
+ data == true
265
+ when 'Time'
266
+ # parse date time (expecting ISO 8601 format)
267
+ Time.parse data
268
+ when 'Date'
269
+ # parse date time (expecting ISO 8601 format)
270
+ Date.parse data
271
+ when 'Object'
272
+ # generic object (usually a Hash), return directly
273
+ data
274
+ when /\AArray<(.+)>\z/
275
+ # e.g. Array<Pet>
276
+ sub_type = $1
277
+ data.map { |item| convert_to_type(item, sub_type) }
278
+ when /\AHash\<String, (.+)\>\z/
279
+ # e.g. Hash<String, Integer>
280
+ sub_type = $1
281
+ {}.tap do |hash|
282
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
283
+ end
284
+ else
285
+ # models (e.g. Pet) or oneOf
286
+ klass = BillingApi.const_get(return_type)
287
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
288
+ end
289
+ end
290
+
291
+ # Sanitize filename by removing path.
292
+ # e.g. ../../sun.gif becomes sun.gif
293
+ #
294
+ # @param [String] filename the filename to be sanitized
295
+ # @return [String] the sanitized filename
296
+ def sanitize_filename(filename)
297
+ filename.gsub(/.*[\/\\]/, '')
298
+ end
299
+
300
+ def build_request_url(path, opts = {})
301
+ # Add leading and trailing slashes to path
302
+ path = "/#{path}".gsub(/\/+/, '/')
303
+ @config.base_url(opts[:operation]) + path
304
+ end
305
+
306
+ # Update header and query params based on authentication settings.
307
+ #
308
+ # @param [Hash] header_params Header parameters
309
+ # @param [Hash] query_params Query parameters
310
+ # @param [String] auth_names Authentication scheme name
311
+ def update_params_for_auth!(header_params, query_params, auth_names)
312
+ Array(auth_names).each do |auth_name|
313
+ auth_setting = @config.auth_settings[auth_name]
314
+ next unless auth_setting
315
+ case auth_setting[:in]
316
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
317
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
318
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
319
+ end
320
+ end
321
+ end
322
+
323
+ # Sets user agent in HTTP header
324
+ #
325
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
326
+ def user_agent=(user_agent)
327
+ @user_agent = user_agent
328
+ @default_headers['User-Agent'] = @user_agent
329
+ end
330
+
331
+ # Return Accept header based on an array of accepts provided.
332
+ # @param [Array] accepts array for Accept
333
+ # @return [String] the Accept header (e.g. application/json)
334
+ def select_header_accept(accepts)
335
+ return nil if accepts.nil? || accepts.empty?
336
+ # use JSON when present, otherwise use all of the provided
337
+ json_accept = accepts.find { |s| json_mime?(s) }
338
+ json_accept || accepts.join(',')
339
+ end
340
+
341
+ # Return Content-Type header based on an array of content types provided.
342
+ # @param [Array] content_types array for Content-Type
343
+ # @return [String] the Content-Type header (e.g. application/json)
344
+ def select_header_content_type(content_types)
345
+ # return nil by default
346
+ return if content_types.nil? || content_types.empty?
347
+ # use JSON when present, otherwise use the first one
348
+ json_content_type = content_types.find { |s| json_mime?(s) }
349
+ json_content_type || content_types.first
350
+ end
351
+
352
+ # Convert object (array, hash, object, etc) to JSON string.
353
+ # @param [Object] model object to be converted into JSON string
354
+ # @return [String] JSON string representation of the object
355
+ def object_to_http_body(model)
356
+ return model if model.nil? || model.is_a?(String)
357
+ local_body = nil
358
+ if model.is_a?(Array)
359
+ local_body = model.map { |m| object_to_hash(m) }
360
+ else
361
+ local_body = object_to_hash(model)
362
+ end
363
+ local_body.to_json
364
+ end
365
+
366
+ # Convert object(non-array) to hash.
367
+ # @param [Object] obj object to be converted into JSON string
368
+ # @return [String] JSON string representation of the object
369
+ def object_to_hash(obj)
370
+ if obj.respond_to?(:to_hash)
371
+ obj.to_hash
372
+ else
373
+ obj
374
+ end
375
+ end
376
+
377
+ # Build parameter value according to the given collection format.
378
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
379
+ def build_collection_param(param, collection_format)
380
+ case collection_format
381
+ when :csv
382
+ param.join(',')
383
+ when :ssv
384
+ param.join(' ')
385
+ when :tsv
386
+ param.join("\t")
387
+ when :pipes
388
+ param.join('|')
389
+ when :multi
390
+ # return the array directly as typhoeus will handle it as expected
391
+ param
392
+ else
393
+ fail "unknown collection format: #{collection_format.inspect}"
394
+ end
395
+ end
396
+ end
397
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ #Billing API
3
+
4
+ #Automate your infrastructure billing with the Bare Metal Cloud Billing API. Reserve your server instances to ensure guaranteed resource availability for 12, 24, and 36 months. Retrieve your server’s rated usage for a given period and enable or disable auto-renewals.<br> <br> <span class='pnap-api-knowledge-base-link'> Knowledge base articles to help you can be found <a href='https://phoenixnap.com/kb/phoenixnap-bare-metal-cloud-billing-models' target='_blank'>here</a> </span><br> <br> <b>All URLs are relative to (https://api.phoenixnap.com/billing/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: 7.2.0
10
+
11
+ =end
12
+
13
+ module BillingApi
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ @message = arg
36
+ end
37
+ end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
57
+ end
58
+ end