Class: AdvancedBilling::HistoricUsage
- Defined in:
- lib/advanced_billing/models/historic_usage.rb
Overview
Optional for Event Based Components. If the ‘include=historic_usages` query param is provided, the last ten billing periods will be returned.
Instance Attribute Summary collapse
-
#billing_period_ends_at ⇒ DateTime
End date of billing period.
-
#billing_period_starts_at ⇒ DateTime
Start date of billing period.
-
#total_usage_quantity ⇒ Float
Total usage of a component for billing period.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(total_usage_quantity: SKIP, billing_period_starts_at: SKIP, billing_period_ends_at: SKIP, additional_properties: {}) ⇒ HistoricUsage
constructor
A new instance of HistoricUsage.
- #to_custom_billing_period_ends_at ⇒ Object
- #to_custom_billing_period_starts_at ⇒ Object
Methods inherited from BaseModel
Constructor Details
#initialize(total_usage_quantity: SKIP, billing_period_starts_at: SKIP, billing_period_ends_at: SKIP, additional_properties: {}) ⇒ HistoricUsage
Returns a new instance of HistoricUsage.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 49 def initialize(total_usage_quantity: SKIP, billing_period_starts_at: SKIP, billing_period_ends_at: SKIP, additional_properties: {}) @total_usage_quantity = total_usage_quantity unless total_usage_quantity == SKIP @billing_period_starts_at = billing_period_starts_at unless billing_period_starts_at == SKIP @billing_period_ends_at = billing_period_ends_at unless billing_period_ends_at == SKIP # Add additional model properties to the instance. additional_properties.each do |_name, _value| instance_variable_set("@#{_name}", _value) end end |
Instance Attribute Details
#billing_period_ends_at ⇒ DateTime
End date of billing period
24 25 26 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 24 def billing_period_ends_at @billing_period_ends_at end |
#billing_period_starts_at ⇒ DateTime
Start date of billing period
20 21 22 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 20 def billing_period_starts_at @billing_period_starts_at end |
#total_usage_quantity ⇒ Float
Total usage of a component for billing period
16 17 18 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 16 def total_usage_quantity @total_usage_quantity end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 62 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. total_usage_quantity = hash.key?('total_usage_quantity') ? hash['total_usage_quantity'] : SKIP billing_period_starts_at = if hash.key?('billing_period_starts_at') (DateTimeHelper.from_rfc3339(hash['billing_period_starts_at']) if hash['billing_period_starts_at']) else SKIP end billing_period_ends_at = if hash.key?('billing_period_ends_at') (DateTimeHelper.from_rfc3339(hash['billing_period_ends_at']) if hash['billing_period_ends_at']) else SKIP end # Clean out expected properties from Hash. names.each_value { |k| hash.delete(k) } # Create object from extracted values. HistoricUsage.new(total_usage_quantity: total_usage_quantity, billing_period_starts_at: billing_period_starts_at, billing_period_ends_at: billing_period_ends_at, additional_properties: hash) end |
.names ⇒ Object
A mapping from model property names to API property names.
27 28 29 30 31 32 33 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 27 def self.names @_hash = {} if @_hash.nil? @_hash['total_usage_quantity'] = 'total_usage_quantity' @_hash['billing_period_starts_at'] = 'billing_period_starts_at' @_hash['billing_period_ends_at'] = 'billing_period_ends_at' @_hash end |
.nullables ⇒ Object
An array for nullable fields
45 46 47 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 45 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
36 37 38 39 40 41 42 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 36 def self.optionals %w[ total_usage_quantity billing_period_starts_at billing_period_ends_at ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
99 100 101 102 103 104 105 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 99 def self.validate(value) return true if value.instance_of? self return false unless value.instance_of? Hash true end |
Instance Method Details
#to_custom_billing_period_ends_at ⇒ Object
93 94 95 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 93 def to_custom_billing_period_ends_at DateTimeHelper.to_rfc3339(billing_period_ends_at) end |
#to_custom_billing_period_starts_at ⇒ Object
89 90 91 |
# File 'lib/advanced_billing/models/historic_usage.rb', line 89 def to_custom_billing_period_starts_at DateTimeHelper.to_rfc3339(billing_period_starts_at) end |