Class: AdvancedBilling::MeteredUsage

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/metered_usage.rb

Overview

MeteredUsage Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(previous_unit_balance:, new_unit_balance:, usage_quantity:, component_id:, component_handle:, memo:, additional_properties: {}) ⇒ MeteredUsage

Returns a new instance of MeteredUsage.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/advanced_billing/models/metered_usage.rb', line 58

def initialize(previous_unit_balance:, new_unit_balance:, usage_quantity:,
               component_id:, component_handle:, memo:,
               additional_properties: {})
  @previous_unit_balance = previous_unit_balance
  @new_unit_balance = new_unit_balance
  @usage_quantity = usage_quantity
  @component_id = component_id
  @component_handle = component_handle
  @memo = memo

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#component_handleString

TODO: Write general description for this method

Returns:

  • (String)


30
31
32
# File 'lib/advanced_billing/models/metered_usage.rb', line 30

def component_handle
  @component_handle
end

#component_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


26
27
28
# File 'lib/advanced_billing/models/metered_usage.rb', line 26

def component_id
  @component_id
end

#memoString

TODO: Write general description for this method

Returns:

  • (String)


34
35
36
# File 'lib/advanced_billing/models/metered_usage.rb', line 34

def memo
  @memo
end

#new_unit_balanceInteger

TODO: Write general description for this method

Returns:

  • (Integer)


18
19
20
# File 'lib/advanced_billing/models/metered_usage.rb', line 18

def new_unit_balance
  @new_unit_balance
end

#previous_unit_balanceString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/advanced_billing/models/metered_usage.rb', line 14

def previous_unit_balance
  @previous_unit_balance
end

#usage_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


22
23
24
# File 'lib/advanced_billing/models/metered_usage.rb', line 22

def usage_quantity
  @usage_quantity
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/advanced_billing/models/metered_usage.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  previous_unit_balance =
    hash.key?('previous_unit_balance') ? hash['previous_unit_balance'] : nil
  new_unit_balance =
    hash.key?('new_unit_balance') ? hash['new_unit_balance'] : nil
  usage_quantity =
    hash.key?('usage_quantity') ? hash['usage_quantity'] : nil
  component_id = hash.key?('component_id') ? hash['component_id'] : nil
  component_handle =
    hash.key?('component_handle') ? hash['component_handle'] : nil
  memo = hash.key?('memo') ? hash['memo'] : nil

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  MeteredUsage.new(previous_unit_balance: previous_unit_balance,
                   new_unit_balance: new_unit_balance,
                   usage_quantity: usage_quantity,
                   component_id: component_id,
                   component_handle: component_handle,
                   memo: memo,
                   additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/advanced_billing/models/metered_usage.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['previous_unit_balance'] = 'previous_unit_balance'
  @_hash['new_unit_balance'] = 'new_unit_balance'
  @_hash['usage_quantity'] = 'usage_quantity'
  @_hash['component_id'] = 'component_id'
  @_hash['component_handle'] = 'component_handle'
  @_hash['memo'] = 'memo'
  @_hash
end

.nullablesObject

An array for nullable fields



54
55
56
# File 'lib/advanced_billing/models/metered_usage.rb', line 54

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
# File 'lib/advanced_billing/models/metered_usage.rb', line 49

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (MeteredUsage | Hash)

    value against the validation is performed.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/metered_usage.rb', line 105

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.previous_unit_balance,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.new_unit_balance,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.usage_quantity,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.component_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.component_handle,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.memo,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['previous_unit_balance'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['new_unit_balance'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['usage_quantity'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['component_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['component_handle'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['memo'],
                            ->(val) { val.instance_of? String })
  )
end