Class: AdvancedBilling::PrepaidUsage

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

Overview

PrepaidUsage 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:, previous_overage_unit_balance:, new_unit_balance:, new_overage_unit_balance:, usage_quantity:, overage_usage_quantity:, component_id:, component_handle:, memo:, allocation_details:, additional_properties: {}) ⇒ PrepaidUsage

Returns a new instance of PrepaidUsage.



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

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

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

Instance Attribute Details

#allocation_detailsArray[PrepaidUsageAllocationDetail]

TODO: Write general description for this method

Returns:



50
51
52
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 50

def allocation_details
  @allocation_details
end

#component_handleString

TODO: Write general description for this method

Returns:

  • (String)


42
43
44
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 42

def component_handle
  @component_handle
end

#component_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


38
39
40
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 38

def component_id
  @component_id
end

#memoString

TODO: Write general description for this method

Returns:

  • (String)


46
47
48
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 46

def memo
  @memo
end

#new_overage_unit_balanceInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def new_overage_unit_balance
  @new_overage_unit_balance
end

#new_unit_balanceInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def new_unit_balance
  @new_unit_balance
end

#overage_usage_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def overage_usage_quantity
  @overage_usage_quantity
end

#previous_overage_unit_balanceString

TODO: Write general description for this method

Returns:

  • (String)


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

def previous_overage_unit_balance
  @previous_overage_unit_balance
end

#previous_unit_balanceString

TODO: Write general description for this method

Returns:

  • (String)


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

def previous_unit_balance
  @previous_unit_balance
end

#usage_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def usage_quantity
  @usage_quantity
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



102
103
104
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
140
141
142
143
144
145
146
147
148
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 102

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
  previous_overage_unit_balance =
    hash.key?('previous_overage_unit_balance') ? hash['previous_overage_unit_balance'] : nil
  new_unit_balance =
    hash.key?('new_unit_balance') ? hash['new_unit_balance'] : nil
  new_overage_unit_balance =
    hash.key?('new_overage_unit_balance') ? hash['new_overage_unit_balance'] : nil
  usage_quantity =
    hash.key?('usage_quantity') ? hash['usage_quantity'] : nil
  overage_usage_quantity =
    hash.key?('overage_usage_quantity') ? hash['overage_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
  # Parameter is an array, so we need to iterate through it
  allocation_details = nil
  unless hash['allocation_details'].nil?
    allocation_details = []
    hash['allocation_details'].each do |structure|
      allocation_details << (PrepaidUsageAllocationDetail.from_hash(structure) if structure)
    end
  end

  allocation_details = nil unless hash.key?('allocation_details')

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

  # Create object from extracted values.
  PrepaidUsage.new(previous_unit_balance: previous_unit_balance,
                   previous_overage_unit_balance: previous_overage_unit_balance,
                   new_unit_balance: new_unit_balance,
                   new_overage_unit_balance: new_overage_unit_balance,
                   usage_quantity: usage_quantity,
                   overage_usage_quantity: overage_usage_quantity,
                   component_id: component_id,
                   component_handle: component_handle,
                   memo: memo,
                   allocation_details: allocation_details,
                   additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 53

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

.nullablesObject

An array for nullable fields



75
76
77
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 75

def self.nullables
  []
end

.optionalsObject

An array for optional fields



70
71
72
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 70

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (PrepaidUsage | Hash)

    value against the validation is performed.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/advanced_billing/models/prepaid_usage.rb', line 152

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.previous_overage_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.new_overage_unit_balance,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.usage_quantity,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.overage_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 }) and
        APIHelper.valid_type?(value.allocation_details,
                              ->(val) { PrepaidUsageAllocationDetail.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  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['previous_overage_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['new_overage_unit_balance'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['usage_quantity'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['overage_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 }) and
      APIHelper.valid_type?(value['allocation_details'],
                            ->(val) { PrepaidUsageAllocationDetail.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end