Class: AdvancedBilling::HistoricUsage

Inherits:
BaseModel
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

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: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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
end

Instance Attribute Details

#billing_period_ends_atDateTime

End date of billing period

Returns:

  • (DateTime)


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_atDateTime

Start date of billing period

Returns:

  • (DateTime)


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_quantityFloat

Total usage of a component for billing period

Returns:

  • (Float)


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.
  additional_properties = hash.reject { |k, _| names.value?(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: additional_properties)
end

.namesObject

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

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/advanced_billing/models/historic_usage.rb', line 45

def self.nullables
  []
end

.optionalsObject

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.

Parameters:

  • The (HistoricUsage | Hash)

    value against the validation is performed.



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_atObject



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_atObject



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