pnap_billing_api 1.0.0 → 2.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.
- checksums.yaml +4 -4
- data/README.md +16 -5
- data/VERSION +1 -1
- data/docs/BandwidthRecord.md +4 -2
- data/docs/CreditDetails.md +49 -0
- data/docs/CreditDetailsBase.md +20 -0
- data/docs/CreditTypeEnum.md +15 -0
- data/docs/DiscountDetails.md +2 -2
- data/docs/DiscountTypeEnum.md +15 -0
- data/docs/GpuConfigurationMetadata.md +20 -0
- data/docs/OperatingSystemRecord.md +4 -2
- data/docs/PackageUnitEnum.md +15 -0
- data/docs/PricingPlan.md +3 -3
- data/docs/ProductAvailabilityApi.md +89 -0
- data/docs/ProductsApi.md +0 -82
- data/docs/PromoCreditDetails.md +24 -0
- data/docs/PublicSubnetRecord.md +4 -2
- data/docs/RatedUsageProductCategoryEnum.md +15 -0
- data/docs/RatedUsageRecord.md +5 -3
- data/docs/Reservation.md +2 -2
- data/docs/ReservationAutoRenewDisableRequest.md +1 -1
- data/docs/ReservationProductCategoryEnum.md +15 -0
- data/docs/ReservationsApi.md +30 -30
- data/docs/ServerProductMetadata.md +3 -1
- data/docs/ServerRecord.md +4 -2
- data/docs/StorageRecord.md +4 -2
- data/docs/SystemCreditCauseEnum.md +15 -0
- data/docs/SystemCreditDetails.md +22 -0
- data/lib/pnap_billing_api/api/product_availability_api.rb +105 -0
- data/lib/pnap_billing_api/api/products_api.rb +0 -83
- data/lib/pnap_billing_api/api/reservations_api.rb +38 -38
- data/lib/pnap_billing_api/api_client.rb +2 -2
- data/lib/pnap_billing_api/models/bandwidth_record.rb +13 -15
- data/lib/pnap_billing_api/models/credit_details.rb +105 -0
- data/lib/pnap_billing_api/models/credit_details_base.rb +261 -0
- data/lib/pnap_billing_api/models/credit_type_enum.rb +40 -0
- data/lib/pnap_billing_api/models/discount_details.rb +1 -14
- data/lib/pnap_billing_api/models/discount_type_enum.rb +41 -0
- data/lib/pnap_billing_api/models/gpu_configuration_metadata.rb +226 -0
- data/lib/pnap_billing_api/models/operating_system_record.rb +13 -15
- data/lib/pnap_billing_api/models/package_unit_enum.rb +40 -0
- data/lib/pnap_billing_api/models/pricing_plan.rb +1 -14
- data/lib/pnap_billing_api/models/promo_credit_details.rb +301 -0
- data/lib/pnap_billing_api/models/public_subnet_record.rb +13 -15
- data/lib/pnap_billing_api/models/rated_usage_product_category_enum.rb +43 -0
- data/lib/pnap_billing_api/models/rated_usage_record.rb +16 -18
- data/lib/pnap_billing_api/models/reservation.rb +1 -14
- data/lib/pnap_billing_api/models/reservation_product_category_enum.rb +40 -0
- data/lib/pnap_billing_api/models/server_product_metadata.rb +16 -4
- data/lib/pnap_billing_api/models/server_record.rb +13 -15
- data/lib/pnap_billing_api/models/storage_record.rb +13 -15
- data/lib/pnap_billing_api/models/system_credit_cause_enum.rb +39 -0
- data/lib/pnap_billing_api/models/system_credit_details.rb +283 -0
- data/lib/pnap_billing_api.rb +12 -0
- data/spec/api/product_availability_api_spec.rb +52 -0
- data/spec/api/products_api_spec.rb +0 -17
- data/spec/api/reservations_api_spec.rb +5 -5
- data/spec/models/bandwidth_record_spec.rb +6 -4
- data/spec/models/credit_details_base_spec.rb +42 -0
- data/spec/models/credit_details_spec.rb +32 -0
- data/spec/models/credit_type_enum_spec.rb +30 -0
- data/spec/models/discount_details_spec.rb +0 -4
- data/spec/models/discount_type_enum_spec.rb +30 -0
- data/spec/models/gpu_configuration_metadata_spec.rb +42 -0
- data/spec/models/operating_system_record_spec.rb +6 -4
- data/spec/models/package_unit_enum_spec.rb +30 -0
- data/spec/models/pricing_plan_spec.rb +0 -4
- data/spec/models/promo_credit_details_spec.rb +54 -0
- data/spec/models/public_subnet_record_spec.rb +6 -4
- data/spec/models/rated_usage_product_category_enum_spec.rb +30 -0
- data/spec/models/rated_usage_record_spec.rb +6 -4
- data/spec/models/reservation_product_category_enum_spec.rb +30 -0
- data/spec/models/reservation_spec.rb +0 -4
- data/spec/models/server_product_metadata_spec.rb +6 -0
- data/spec/models/server_record_spec.rb +6 -4
- data/spec/models/storage_record_spec.rb +6 -4
- data/spec/models/system_credit_cause_enum_spec.rb +30 -0
- data/spec/models/system_credit_details_spec.rb +48 -0
- metadata +77 -29
@@ -22,7 +22,7 @@ module BillingApi
|
|
22
22
|
# List all Reservations.
|
23
23
|
# Retrieves all reservations associated with the authenticated account. All date & times are in UTC.
|
24
24
|
# @param [Hash] opts the optional parameters
|
25
|
-
# @option opts [
|
25
|
+
# @option opts [ReservationProductCategoryEnum] :product_category The product category
|
26
26
|
# @return [Array<Reservation>]
|
27
27
|
def reservations_get(opts = {})
|
28
28
|
data, _status_code, _headers = reservations_get_with_http_info(opts)
|
@@ -32,7 +32,7 @@ module BillingApi
|
|
32
32
|
# List all Reservations.
|
33
33
|
# Retrieves all reservations associated with the authenticated account. All date & times are in UTC.
|
34
34
|
# @param [Hash] opts the optional parameters
|
35
|
-
# @option opts [
|
35
|
+
# @option opts [ReservationProductCategoryEnum] :product_category The product category
|
36
36
|
# @return [Array<(Array<Reservation>, Integer, Hash)>] Array<Reservation> data, response status code and response headers
|
37
37
|
def reservations_get_with_http_info(opts = {})
|
38
38
|
if @api_client.config.debugging
|
@@ -145,31 +145,31 @@ module BillingApi
|
|
145
145
|
|
146
146
|
# Disable auto-renewal for reservation by id.
|
147
147
|
# Disable auto-renewal for reservation by reservation id.
|
148
|
-
# @param
|
148
|
+
# @param id [String] Resource id.
|
149
149
|
# @param [Hash] opts the optional parameters
|
150
150
|
# @option opts [ReservationAutoRenewDisableRequest] :reservation_auto_renew_disable_request
|
151
151
|
# @return [Reservation]
|
152
|
-
def reservations_reservation_id_actions_auto_renew_disable_post(
|
153
|
-
data, _status_code, _headers = reservations_reservation_id_actions_auto_renew_disable_post_with_http_info(
|
152
|
+
def reservations_reservation_id_actions_auto_renew_disable_post(id, opts = {})
|
153
|
+
data, _status_code, _headers = reservations_reservation_id_actions_auto_renew_disable_post_with_http_info(id, opts)
|
154
154
|
data
|
155
155
|
end
|
156
156
|
|
157
157
|
# Disable auto-renewal for reservation by id.
|
158
158
|
# Disable auto-renewal for reservation by reservation id.
|
159
|
-
# @param
|
159
|
+
# @param id [String] Resource id.
|
160
160
|
# @param [Hash] opts the optional parameters
|
161
161
|
# @option opts [ReservationAutoRenewDisableRequest] :reservation_auto_renew_disable_request
|
162
162
|
# @return [Array<(Reservation, Integer, Hash)>] Reservation data, response status code and response headers
|
163
|
-
def reservations_reservation_id_actions_auto_renew_disable_post_with_http_info(
|
163
|
+
def reservations_reservation_id_actions_auto_renew_disable_post_with_http_info(id, opts = {})
|
164
164
|
if @api_client.config.debugging
|
165
165
|
@api_client.config.logger.debug 'Calling API: ReservationsApi.reservations_reservation_id_actions_auto_renew_disable_post ...'
|
166
166
|
end
|
167
|
-
# verify the required parameter '
|
168
|
-
if @api_client.config.client_side_validation &&
|
169
|
-
fail ArgumentError, "Missing the required parameter '
|
167
|
+
# verify the required parameter 'id' is set
|
168
|
+
if @api_client.config.client_side_validation && id.nil?
|
169
|
+
fail ArgumentError, "Missing the required parameter 'id' when calling ReservationsApi.reservations_reservation_id_actions_auto_renew_disable_post"
|
170
170
|
end
|
171
171
|
# resource path
|
172
|
-
local_var_path = '/reservations/{
|
172
|
+
local_var_path = '/reservations/{id}/actions/auto-renew/disable'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
|
173
173
|
|
174
174
|
# query parameters
|
175
175
|
query_params = opts[:query_params] || {}
|
@@ -215,29 +215,29 @@ module BillingApi
|
|
215
215
|
|
216
216
|
# Enable auto-renewal for unexpired reservation by reservation id.
|
217
217
|
# Enable auto-renewal for unexpired reservation by reservation id.
|
218
|
-
# @param
|
218
|
+
# @param id [String] Resource id.
|
219
219
|
# @param [Hash] opts the optional parameters
|
220
220
|
# @return [Reservation]
|
221
|
-
def reservations_reservation_id_actions_auto_renew_enable_post(
|
222
|
-
data, _status_code, _headers = reservations_reservation_id_actions_auto_renew_enable_post_with_http_info(
|
221
|
+
def reservations_reservation_id_actions_auto_renew_enable_post(id, opts = {})
|
222
|
+
data, _status_code, _headers = reservations_reservation_id_actions_auto_renew_enable_post_with_http_info(id, opts)
|
223
223
|
data
|
224
224
|
end
|
225
225
|
|
226
226
|
# Enable auto-renewal for unexpired reservation by reservation id.
|
227
227
|
# Enable auto-renewal for unexpired reservation by reservation id.
|
228
|
-
# @param
|
228
|
+
# @param id [String] Resource id.
|
229
229
|
# @param [Hash] opts the optional parameters
|
230
230
|
# @return [Array<(Reservation, Integer, Hash)>] Reservation data, response status code and response headers
|
231
|
-
def reservations_reservation_id_actions_auto_renew_enable_post_with_http_info(
|
231
|
+
def reservations_reservation_id_actions_auto_renew_enable_post_with_http_info(id, opts = {})
|
232
232
|
if @api_client.config.debugging
|
233
233
|
@api_client.config.logger.debug 'Calling API: ReservationsApi.reservations_reservation_id_actions_auto_renew_enable_post ...'
|
234
234
|
end
|
235
|
-
# verify the required parameter '
|
236
|
-
if @api_client.config.client_side_validation &&
|
237
|
-
fail ArgumentError, "Missing the required parameter '
|
235
|
+
# verify the required parameter 'id' is set
|
236
|
+
if @api_client.config.client_side_validation && id.nil?
|
237
|
+
fail ArgumentError, "Missing the required parameter 'id' when calling ReservationsApi.reservations_reservation_id_actions_auto_renew_enable_post"
|
238
238
|
end
|
239
239
|
# resource path
|
240
|
-
local_var_path = '/reservations/{
|
240
|
+
local_var_path = '/reservations/{id}/actions/auto-renew/enable'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
|
241
241
|
|
242
242
|
# query parameters
|
243
243
|
query_params = opts[:query_params] || {}
|
@@ -278,31 +278,31 @@ module BillingApi
|
|
278
278
|
|
279
279
|
# Convert reservation pricing model by reservation ID.
|
280
280
|
# Convert reservation pricing model by reservation id.
|
281
|
-
# @param
|
281
|
+
# @param id [String] Resource id.
|
282
282
|
# @param [Hash] opts the optional parameters
|
283
283
|
# @option opts [ReservationRequest] :reservation_request
|
284
284
|
# @return [Reservation]
|
285
|
-
def reservations_reservation_id_actions_convert_post(
|
286
|
-
data, _status_code, _headers = reservations_reservation_id_actions_convert_post_with_http_info(
|
285
|
+
def reservations_reservation_id_actions_convert_post(id, opts = {})
|
286
|
+
data, _status_code, _headers = reservations_reservation_id_actions_convert_post_with_http_info(id, opts)
|
287
287
|
data
|
288
288
|
end
|
289
289
|
|
290
290
|
# Convert reservation pricing model by reservation ID.
|
291
291
|
# Convert reservation pricing model by reservation id.
|
292
|
-
# @param
|
292
|
+
# @param id [String] Resource id.
|
293
293
|
# @param [Hash] opts the optional parameters
|
294
294
|
# @option opts [ReservationRequest] :reservation_request
|
295
295
|
# @return [Array<(Reservation, Integer, Hash)>] Reservation data, response status code and response headers
|
296
|
-
def reservations_reservation_id_actions_convert_post_with_http_info(
|
296
|
+
def reservations_reservation_id_actions_convert_post_with_http_info(id, opts = {})
|
297
297
|
if @api_client.config.debugging
|
298
298
|
@api_client.config.logger.debug 'Calling API: ReservationsApi.reservations_reservation_id_actions_convert_post ...'
|
299
299
|
end
|
300
|
-
# verify the required parameter '
|
301
|
-
if @api_client.config.client_side_validation &&
|
302
|
-
fail ArgumentError, "Missing the required parameter '
|
300
|
+
# verify the required parameter 'id' is set
|
301
|
+
if @api_client.config.client_side_validation && id.nil?
|
302
|
+
fail ArgumentError, "Missing the required parameter 'id' when calling ReservationsApi.reservations_reservation_id_actions_convert_post"
|
303
303
|
end
|
304
304
|
# resource path
|
305
|
-
local_var_path = '/reservations/{
|
305
|
+
local_var_path = '/reservations/{id}/actions/convert'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
|
306
306
|
|
307
307
|
# query parameters
|
308
308
|
query_params = opts[:query_params] || {}
|
@@ -348,29 +348,29 @@ module BillingApi
|
|
348
348
|
|
349
349
|
# Get a reservation.
|
350
350
|
# Retrieves the reservations with the specified identifier. All date & times are in UTC.
|
351
|
-
# @param
|
351
|
+
# @param id [String] Resource id.
|
352
352
|
# @param [Hash] opts the optional parameters
|
353
353
|
# @return [Reservation]
|
354
|
-
def reservations_reservation_id_get(
|
355
|
-
data, _status_code, _headers = reservations_reservation_id_get_with_http_info(
|
354
|
+
def reservations_reservation_id_get(id, opts = {})
|
355
|
+
data, _status_code, _headers = reservations_reservation_id_get_with_http_info(id, opts)
|
356
356
|
data
|
357
357
|
end
|
358
358
|
|
359
359
|
# Get a reservation.
|
360
360
|
# Retrieves the reservations with the specified identifier. All date & times are in UTC.
|
361
|
-
# @param
|
361
|
+
# @param id [String] Resource id.
|
362
362
|
# @param [Hash] opts the optional parameters
|
363
363
|
# @return [Array<(Reservation, Integer, Hash)>] Reservation data, response status code and response headers
|
364
|
-
def reservations_reservation_id_get_with_http_info(
|
364
|
+
def reservations_reservation_id_get_with_http_info(id, opts = {})
|
365
365
|
if @api_client.config.debugging
|
366
366
|
@api_client.config.logger.debug 'Calling API: ReservationsApi.reservations_reservation_id_get ...'
|
367
367
|
end
|
368
|
-
# verify the required parameter '
|
369
|
-
if @api_client.config.client_side_validation &&
|
370
|
-
fail ArgumentError, "Missing the required parameter '
|
368
|
+
# verify the required parameter 'id' is set
|
369
|
+
if @api_client.config.client_side_validation && id.nil?
|
370
|
+
fail ArgumentError, "Missing the required parameter 'id' when calling ReservationsApi.reservations_reservation_id_get"
|
371
371
|
end
|
372
372
|
# resource path
|
373
|
-
local_var_path = '/reservations/{
|
373
|
+
local_var_path = '/reservations/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
|
374
374
|
|
375
375
|
# query parameters
|
376
376
|
query_params = opts[:query_params] || {}
|
@@ -33,8 +33,8 @@ module BillingApi
|
|
33
33
|
def initialize(config = Configuration.default)
|
34
34
|
@config = config
|
35
35
|
@config.params_encoding = :multi
|
36
|
-
@user_agent = "PNAP-ruby-sdk-bmc/#{ BillingApi::VERSION }"
|
37
|
-
@powered_by = "PNAP-ruby-sdk-bmc/#{ BillingApi::VERSION }"
|
36
|
+
@user_agent = "PNAP-ruby-sdk-bmc/BillingApi/#{ BillingApi::VERSION }"
|
37
|
+
@powered_by = "PNAP-ruby-sdk-bmc/BillingApi/#{ BillingApi::VERSION }"
|
38
38
|
@default_headers = {
|
39
39
|
'Content-Type' => 'application/json',
|
40
40
|
'User-Agent' => @user_agent,
|
@@ -18,7 +18,6 @@ module BillingApi
|
|
18
18
|
# The unique identifier of the rated usage record.
|
19
19
|
attr_accessor :id
|
20
20
|
|
21
|
-
# The category of the product associated with this usage record.
|
22
21
|
attr_accessor :product_category
|
23
22
|
|
24
23
|
# The code identifying the product associated to this usage record.
|
@@ -70,6 +69,8 @@ module BillingApi
|
|
70
69
|
|
71
70
|
attr_accessor :discount_details
|
72
71
|
|
72
|
+
attr_accessor :credit_details
|
73
|
+
|
73
74
|
attr_accessor :metadata
|
74
75
|
|
75
76
|
class EnumAttributeValidator
|
@@ -116,6 +117,7 @@ module BillingApi
|
|
116
117
|
:'correlation_id' => :'correlationId',
|
117
118
|
:'reservation_id' => :'reservationId',
|
118
119
|
:'discount_details' => :'discountDetails',
|
120
|
+
:'credit_details' => :'creditDetails',
|
119
121
|
:'metadata' => :'metadata'
|
120
122
|
}
|
121
123
|
end
|
@@ -129,7 +131,7 @@ module BillingApi
|
|
129
131
|
def self.openapi_types
|
130
132
|
{
|
131
133
|
:'id' => :'String',
|
132
|
-
:'product_category' => :'
|
134
|
+
:'product_category' => :'RatedUsageProductCategoryEnum',
|
133
135
|
:'product_code' => :'String',
|
134
136
|
:'location' => :'LocationEnum',
|
135
137
|
:'year_month' => :'String',
|
@@ -147,6 +149,7 @@ module BillingApi
|
|
147
149
|
:'correlation_id' => :'String',
|
148
150
|
:'reservation_id' => :'String',
|
149
151
|
:'discount_details' => :'DiscountDetails',
|
152
|
+
:'credit_details' => :'Array<CreditDetails>',
|
150
153
|
:'metadata' => :'BandwidthDetails'
|
151
154
|
}
|
152
155
|
end
|
@@ -283,6 +286,12 @@ module BillingApi
|
|
283
286
|
self.discount_details = attributes[:'discount_details']
|
284
287
|
end
|
285
288
|
|
289
|
+
if attributes.key?(:'credit_details')
|
290
|
+
if (value = attributes[:'credit_details']).is_a?(Array)
|
291
|
+
self.credit_details = value
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
286
295
|
if attributes.key?(:'metadata')
|
287
296
|
self.metadata = attributes[:'metadata']
|
288
297
|
else
|
@@ -364,8 +373,6 @@ module BillingApi
|
|
364
373
|
warn '[DEPRECATED] the `valid?` method is obsolete'
|
365
374
|
return false if @id.nil?
|
366
375
|
return false if @product_category.nil?
|
367
|
-
product_category_validator = EnumAttributeValidator.new('String', ["bmc-server", "bandwidth", "operating-system", "public-ip", "storage"])
|
368
|
-
return false unless product_category_validator.valid?(@product_category)
|
369
376
|
return false if @product_code.nil?
|
370
377
|
return false if @location.nil?
|
371
378
|
return false if @start_date_time.nil?
|
@@ -382,16 +389,6 @@ module BillingApi
|
|
382
389
|
true
|
383
390
|
end
|
384
391
|
|
385
|
-
# Custom attribute writer method checking allowed values (enum).
|
386
|
-
# @param [Object] product_category Object to be assigned
|
387
|
-
def product_category=(product_category)
|
388
|
-
validator = EnumAttributeValidator.new('String', ["bmc-server", "bandwidth", "operating-system", "public-ip", "storage"])
|
389
|
-
unless validator.valid?(product_category)
|
390
|
-
fail ArgumentError, "invalid value for \"product_category\", must be one of #{validator.allowable_values}."
|
391
|
-
end
|
392
|
-
@product_category = product_category
|
393
|
-
end
|
394
|
-
|
395
392
|
# Checks equality by comparing each attribute.
|
396
393
|
# @param [Object] Object to be compared
|
397
394
|
def ==(o)
|
@@ -416,6 +413,7 @@ module BillingApi
|
|
416
413
|
correlation_id == o.correlation_id &&
|
417
414
|
reservation_id == o.reservation_id &&
|
418
415
|
discount_details == o.discount_details &&
|
416
|
+
credit_details == o.credit_details &&
|
419
417
|
metadata == o.metadata
|
420
418
|
end
|
421
419
|
|
@@ -428,7 +426,7 @@ module BillingApi
|
|
428
426
|
# Calculates hash code according to all attributes.
|
429
427
|
# @return [Integer] Hash code
|
430
428
|
def hash
|
431
|
-
[id, product_category, product_code, location, year_month, start_date_time, end_date_time, cost, cost_before_discount, cost_description, price_model, unit_price, unit_price_description, quantity, active, usage_session_id, correlation_id, reservation_id, discount_details, metadata].hash
|
429
|
+
[id, product_category, product_code, location, year_month, start_date_time, end_date_time, cost, cost_before_discount, cost_description, price_model, unit_price, unit_price_description, quantity, active, usage_session_id, correlation_id, reservation_id, discount_details, credit_details, metadata].hash
|
432
430
|
end
|
433
431
|
|
434
432
|
# Builds the object from hash
|
@@ -0,0 +1,105 @@
|
|
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 'time'
|
15
|
+
|
16
|
+
module BillingApi
|
17
|
+
module CreditDetails
|
18
|
+
class << self
|
19
|
+
# List of class defined in oneOf (OpenAPI v3)
|
20
|
+
def openapi_one_of
|
21
|
+
[
|
22
|
+
:'PromoCreditDetails',
|
23
|
+
:'SystemCreditDetails'
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Builds the object
|
28
|
+
# @param [Mixed] Data to be matched against the list of oneOf items
|
29
|
+
# @return [Object] Returns the model or the data itself
|
30
|
+
def build(data)
|
31
|
+
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
32
|
+
# Note:
|
33
|
+
# - We do not attempt to check whether exactly one item matches.
|
34
|
+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
35
|
+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
36
|
+
# - TODO: scalar values are de facto behaving as if they were nullable.
|
37
|
+
# - TODO: logging when debugging is set.
|
38
|
+
openapi_one_of.each do |klass|
|
39
|
+
begin
|
40
|
+
next if klass == :AnyType # "nullable: true"
|
41
|
+
typed_data = find_and_cast_into_type(klass, data)
|
42
|
+
return typed_data if typed_data
|
43
|
+
rescue # rescue all errors so we keep iterating even if the current item lookup raises
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
openapi_one_of.include?(:AnyType) ? data : nil
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
SchemaMismatchError = Class.new(StandardError)
|
53
|
+
|
54
|
+
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
|
55
|
+
def find_and_cast_into_type(klass, data)
|
56
|
+
return if data.nil?
|
57
|
+
|
58
|
+
case klass.to_s
|
59
|
+
when 'Boolean'
|
60
|
+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
61
|
+
when 'Float'
|
62
|
+
return data if data.instance_of?(Float)
|
63
|
+
when 'Integer'
|
64
|
+
return data if data.instance_of?(Integer)
|
65
|
+
when 'Time'
|
66
|
+
return Time.parse(data)
|
67
|
+
when 'Date'
|
68
|
+
return Date.parse(data)
|
69
|
+
when 'String'
|
70
|
+
return data if data.instance_of?(String)
|
71
|
+
when 'Object' # "type: object"
|
72
|
+
return data if data.instance_of?(Hash)
|
73
|
+
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
|
74
|
+
if data.instance_of?(Array)
|
75
|
+
sub_type = Regexp.last_match[:sub_type]
|
76
|
+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
77
|
+
end
|
78
|
+
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
|
79
|
+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
80
|
+
sub_type = Regexp.last_match[:sub_type]
|
81
|
+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
82
|
+
end
|
83
|
+
else # model
|
84
|
+
const = BillingApi.const_get(klass)
|
85
|
+
if const
|
86
|
+
if const.respond_to?(:openapi_one_of) # nested oneOf model
|
87
|
+
model = const.build(data)
|
88
|
+
return model if model
|
89
|
+
else
|
90
|
+
# raise if data contains keys that are not known to the model
|
91
|
+
raise unless (data.keys - const.acceptable_attributes).empty?
|
92
|
+
model = const.build_from_hash(data)
|
93
|
+
return model if model && model.valid?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
raise # if no match by now, raise
|
99
|
+
rescue
|
100
|
+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,261 @@
|
|
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 'time'
|
15
|
+
|
16
|
+
module BillingApi
|
17
|
+
# Base credit details value object.
|
18
|
+
class CreditDetailsBase
|
19
|
+
# Amount applied.
|
20
|
+
attr_accessor :applied_amount
|
21
|
+
|
22
|
+
attr_accessor :type
|
23
|
+
|
24
|
+
class EnumAttributeValidator
|
25
|
+
attr_reader :datatype
|
26
|
+
attr_reader :allowable_values
|
27
|
+
|
28
|
+
def initialize(datatype, allowable_values)
|
29
|
+
@allowable_values = allowable_values.map do |value|
|
30
|
+
case datatype.to_s
|
31
|
+
when /Integer/i
|
32
|
+
value.to_i
|
33
|
+
when /Float/i
|
34
|
+
value.to_f
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid?(value)
|
42
|
+
!value || allowable_values.include?(value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
47
|
+
def self.attribute_map
|
48
|
+
{
|
49
|
+
:'applied_amount' => :'appliedAmount',
|
50
|
+
:'type' => :'type'
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns all the JSON keys this model knows about
|
55
|
+
def self.acceptable_attributes
|
56
|
+
attribute_map.values
|
57
|
+
end
|
58
|
+
|
59
|
+
# Attribute type mapping.
|
60
|
+
def self.openapi_types
|
61
|
+
{
|
62
|
+
:'applied_amount' => :'Float',
|
63
|
+
:'type' => :'CreditTypeEnum'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
# List of attributes with nullable: true
|
68
|
+
def self.openapi_nullable
|
69
|
+
Set.new([
|
70
|
+
])
|
71
|
+
end
|
72
|
+
|
73
|
+
# Initializes the object
|
74
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
75
|
+
def initialize(attributes = {})
|
76
|
+
if (!attributes.is_a?(Hash))
|
77
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `BillingApi::CreditDetailsBase` initialize method"
|
78
|
+
end
|
79
|
+
|
80
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
81
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
82
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
83
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `BillingApi::CreditDetailsBase`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
84
|
+
end
|
85
|
+
h[k.to_sym] = v
|
86
|
+
}
|
87
|
+
|
88
|
+
if attributes.key?(:'applied_amount')
|
89
|
+
self.applied_amount = attributes[:'applied_amount']
|
90
|
+
else
|
91
|
+
self.applied_amount = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
if attributes.key?(:'type')
|
95
|
+
self.type = attributes[:'type']
|
96
|
+
else
|
97
|
+
self.type = nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
102
|
+
# @return Array for valid properties with the reasons
|
103
|
+
def list_invalid_properties
|
104
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
105
|
+
invalid_properties = Array.new
|
106
|
+
if @applied_amount.nil?
|
107
|
+
invalid_properties.push('invalid value for "applied_amount", applied_amount cannot be nil.')
|
108
|
+
end
|
109
|
+
|
110
|
+
if @type.nil?
|
111
|
+
invalid_properties.push('invalid value for "type", type cannot be nil.')
|
112
|
+
end
|
113
|
+
|
114
|
+
invalid_properties
|
115
|
+
end
|
116
|
+
|
117
|
+
# Check to see if the all the properties in the model are valid
|
118
|
+
# @return true if the model is valid
|
119
|
+
def valid?
|
120
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
121
|
+
return false if @applied_amount.nil?
|
122
|
+
return false if @type.nil?
|
123
|
+
true
|
124
|
+
end
|
125
|
+
|
126
|
+
# Checks equality by comparing each attribute.
|
127
|
+
# @param [Object] Object to be compared
|
128
|
+
def ==(o)
|
129
|
+
return true if self.equal?(o)
|
130
|
+
self.class == o.class &&
|
131
|
+
applied_amount == o.applied_amount &&
|
132
|
+
type == o.type
|
133
|
+
end
|
134
|
+
|
135
|
+
# @see the `==` method
|
136
|
+
# @param [Object] Object to be compared
|
137
|
+
def eql?(o)
|
138
|
+
self == o
|
139
|
+
end
|
140
|
+
|
141
|
+
# Calculates hash code according to all attributes.
|
142
|
+
# @return [Integer] Hash code
|
143
|
+
def hash
|
144
|
+
[applied_amount, type].hash
|
145
|
+
end
|
146
|
+
|
147
|
+
# Builds the object from hash
|
148
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
149
|
+
# @return [Object] Returns the model itself
|
150
|
+
def self.build_from_hash(attributes)
|
151
|
+
return nil unless attributes.is_a?(Hash)
|
152
|
+
attributes = attributes.transform_keys(&:to_sym)
|
153
|
+
transformed_hash = {}
|
154
|
+
openapi_types.each_pair do |key, type|
|
155
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
156
|
+
transformed_hash["#{key}"] = nil
|
157
|
+
elsif type =~ /\AArray<(.*)>/i
|
158
|
+
# check to ensure the input is an array given that the attribute
|
159
|
+
# is documented as an array but the input is not
|
160
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
161
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
162
|
+
end
|
163
|
+
elsif !attributes[attribute_map[key]].nil?
|
164
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
165
|
+
end
|
166
|
+
end
|
167
|
+
new(transformed_hash)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Deserializes the data based on type
|
171
|
+
# @param string type Data type
|
172
|
+
# @param string value Value to be deserialized
|
173
|
+
# @return [Object] Deserialized data
|
174
|
+
def self._deserialize(type, value)
|
175
|
+
case type.to_sym
|
176
|
+
when :Time
|
177
|
+
Time.parse(value)
|
178
|
+
when :Date
|
179
|
+
Date.parse(value)
|
180
|
+
when :String
|
181
|
+
value.to_s
|
182
|
+
when :Integer
|
183
|
+
value.to_i
|
184
|
+
when :Float
|
185
|
+
value.to_f
|
186
|
+
when :Boolean
|
187
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
188
|
+
true
|
189
|
+
else
|
190
|
+
false
|
191
|
+
end
|
192
|
+
when :Object
|
193
|
+
# generic object (usually a Hash), return directly
|
194
|
+
value
|
195
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
196
|
+
inner_type = Regexp.last_match[:inner_type]
|
197
|
+
value.map { |v| _deserialize(inner_type, v) }
|
198
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
199
|
+
k_type = Regexp.last_match[:k_type]
|
200
|
+
v_type = Regexp.last_match[:v_type]
|
201
|
+
{}.tap do |hash|
|
202
|
+
value.each do |k, v|
|
203
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
else # model
|
207
|
+
# models (e.g. Pet) or oneOf
|
208
|
+
klass = BillingApi.const_get(type)
|
209
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# Returns the string representation of the object
|
214
|
+
# @return [String] String presentation of the object
|
215
|
+
def to_s
|
216
|
+
to_hash.to_s
|
217
|
+
end
|
218
|
+
|
219
|
+
# to_body is an alias to to_hash (backward compatibility)
|
220
|
+
# @return [Hash] Returns the object in the form of hash
|
221
|
+
def to_body
|
222
|
+
to_hash
|
223
|
+
end
|
224
|
+
|
225
|
+
# Returns the object in the form of hash
|
226
|
+
# @return [Hash] Returns the object in the form of hash
|
227
|
+
def to_hash
|
228
|
+
hash = {}
|
229
|
+
self.class.attribute_map.each_pair do |attr, param|
|
230
|
+
value = self.send(attr)
|
231
|
+
if value.nil?
|
232
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
233
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
234
|
+
end
|
235
|
+
|
236
|
+
hash[param] = _to_hash(value)
|
237
|
+
end
|
238
|
+
hash
|
239
|
+
end
|
240
|
+
|
241
|
+
# Outputs non-array value in the form of hash
|
242
|
+
# For object, use to_hash. Otherwise, just return the value
|
243
|
+
# @param [Object] value Any valid value
|
244
|
+
# @return [Hash] Returns the value in the form of hash
|
245
|
+
def _to_hash(value)
|
246
|
+
if value.is_a?(Array)
|
247
|
+
value.compact.map { |v| _to_hash(v) }
|
248
|
+
elsif value.is_a?(Hash)
|
249
|
+
{}.tap do |hash|
|
250
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
251
|
+
end
|
252
|
+
elsif value.respond_to? :to_hash
|
253
|
+
value.to_hash
|
254
|
+
else
|
255
|
+
value
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|