Class: ApiReference::CreditBlock

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/credit_block.rb

Overview

The Credit Block resource models prepaid credits within Orb.

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(metadata:, id:, balance:, effective_date:, expiry_date:, per_unit_cost_basis:, status:, maximum_initial_balance:, filters:, credit_block_source:, credit_allocation: SKIP, additional_properties: nil) ⇒ CreditBlock

Returns a new instance of CreditBlock.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/api_reference/models/credit_block.rb', line 123

def initialize(metadata:, id:, balance:, effective_date:, expiry_date:,
               per_unit_cost_basis:, status:, maximum_initial_balance:,
               filters:, credit_block_source:, credit_allocation: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @metadata = 
  @id = id
  @balance = balance
  @effective_date = effective_date
  @expiry_date = expiry_date
  @per_unit_cost_basis = per_unit_cost_basis
  @status = status
  @maximum_initial_balance = maximum_initial_balance
  @filters = filters
  @credit_block_source = credit_block_source
  @credit_allocation = credit_allocation unless credit_allocation == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#balanceFloat

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Float)


32
33
34
# File 'lib/api_reference/models/credit_block.rb', line 32

def balance
  @balance
end

#credit_allocationCreditBlockAllocation

The credit allocation this block was created from, including the catalog item it was allocated for. Null for blocks not created via an allocation.



86
87
88
# File 'lib/api_reference/models/credit_block.rb', line 86

def credit_allocation
  @credit_allocation
end

#credit_block_sourceCreditBlockSource

How this credit block was created: allocation (a subscription's recurring credit allocation), top_up (an automatic balance-threshold top-up), or manual (a manual credit ledger increment, including credits voided or expired off another block).

Returns:



81
82
83
# File 'lib/api_reference/models/credit_block.rb', line 81

def credit_block_source
  @credit_block_source
end

#effective_dateDateTime

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (DateTime)


39
40
41
# File 'lib/api_reference/models/credit_block.rb', line 39

def effective_date
  @effective_date
end

#expiry_dateDateTime

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (DateTime)


46
47
48
# File 'lib/api_reference/models/credit_block.rb', line 46

def expiry_date
  @expiry_date
end

#filtersArray[PriceFilter]

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



74
75
76
# File 'lib/api_reference/models/credit_block.rb', line 74

def filters
  @filters
end

#idString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


25
26
27
# File 'lib/api_reference/models/credit_block.rb', line 25

def id
  @id
end

#maximum_initial_balanceFloat

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Float)


67
68
69
# File 'lib/api_reference/models/credit_block.rb', line 67

def maximum_initial_balance
  @maximum_initial_balance
end

#metadataHash[String, String]

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Hash[String, String])


18
19
20
# File 'lib/api_reference/models/credit_block.rb', line 18

def 
  @metadata
end

#per_unit_cost_basisString

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (String)


53
54
55
# File 'lib/api_reference/models/credit_block.rb', line 53

def per_unit_cost_basis
  @per_unit_cost_basis
end

#statusStatus3

User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:



60
61
62
# File 'lib/api_reference/models/credit_block.rb', line 60

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



145
146
147
148
149
150
151
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
# File 'lib/api_reference/models/credit_block.rb', line 145

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
   = hash.key?('metadata') ? hash['metadata'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  balance = hash.key?('balance') ? hash['balance'] : nil
  effective_date = if hash.key?('effective_date')
                     (DateTimeHelper.from_rfc3339(hash['effective_date']) if hash['effective_date'])
                   end
  expiry_date = if hash.key?('expiry_date')
                  (DateTimeHelper.from_rfc3339(hash['expiry_date']) if hash['expiry_date'])
                end
  per_unit_cost_basis =
    hash.key?('per_unit_cost_basis') ? hash['per_unit_cost_basis'] : nil
  status = hash.key?('status') ? hash['status'] : nil
  maximum_initial_balance =
    hash.key?('maximum_initial_balance') ? hash['maximum_initial_balance'] : nil
  # Parameter is an array, so we need to iterate through it
  filters = nil
  unless hash['filters'].nil?
    filters = []
    hash['filters'].each do |structure|
      filters << (PriceFilter.from_hash(structure) if structure)
    end
  end

  filters = nil unless hash.key?('filters')
  credit_block_source =
    hash.key?('credit_block_source') ? hash['credit_block_source'] : nil
  credit_allocation = CreditBlockAllocation.from_hash(hash['credit_allocation']) if
    hash['credit_allocation']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  CreditBlock.new(metadata: ,
                  id: id,
                  balance: balance,
                  effective_date: effective_date,
                  expiry_date: expiry_date,
                  per_unit_cost_basis: per_unit_cost_basis,
                  status: status,
                  maximum_initial_balance: maximum_initial_balance,
                  filters: filters,
                  credit_block_source: credit_block_source,
                  credit_allocation: credit_allocation,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/api_reference/models/credit_block.rb', line 89

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['metadata'] = 'metadata'
  @_hash['id'] = 'id'
  @_hash['balance'] = 'balance'
  @_hash['effective_date'] = 'effective_date'
  @_hash['expiry_date'] = 'expiry_date'
  @_hash['per_unit_cost_basis'] = 'per_unit_cost_basis'
  @_hash['status'] = 'status'
  @_hash['maximum_initial_balance'] = 'maximum_initial_balance'
  @_hash['filters'] = 'filters'
  @_hash['credit_block_source'] = 'credit_block_source'
  @_hash['credit_allocation'] = 'credit_allocation'
  @_hash
end

.nullablesObject

An array for nullable fields



113
114
115
116
117
118
119
120
121
# File 'lib/api_reference/models/credit_block.rb', line 113

def self.nullables
  %w[
    effective_date
    expiry_date
    per_unit_cost_basis
    maximum_initial_balance
    credit_allocation
  ]
end

.optionalsObject

An array for optional fields



106
107
108
109
110
# File 'lib/api_reference/models/credit_block.rb', line 106

def self.optionals
  %w[
    credit_allocation
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



220
221
222
223
224
225
226
227
228
229
# File 'lib/api_reference/models/credit_block.rb', line 220

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata.inspect}, id: #{@id.inspect}, balance:"\
  " #{@balance.inspect}, effective_date: #{@effective_date.inspect}, expiry_date:"\
  " #{@expiry_date.inspect}, per_unit_cost_basis: #{@per_unit_cost_basis.inspect}, status:"\
  " #{@status.inspect}, maximum_initial_balance: #{@maximum_initial_balance.inspect}, filters:"\
  " #{@filters.inspect}, credit_block_source: #{@credit_block_source.inspect},"\
  " credit_allocation: #{@credit_allocation.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_effective_dateObject



200
201
202
# File 'lib/api_reference/models/credit_block.rb', line 200

def to_custom_effective_date
  DateTimeHelper.to_rfc3339(effective_date)
end

#to_custom_expiry_dateObject



204
205
206
# File 'lib/api_reference/models/credit_block.rb', line 204

def to_custom_expiry_date
  DateTimeHelper.to_rfc3339(expiry_date)
end

#to_sObject

Provides a human-readable string representation of the object.



209
210
211
212
213
214
215
216
217
# File 'lib/api_reference/models/credit_block.rb', line 209

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata}, id: #{@id}, balance: #{@balance}, effective_date:"\
  " #{@effective_date}, expiry_date: #{@expiry_date}, per_unit_cost_basis:"\
  " #{@per_unit_cost_basis}, status: #{@status}, maximum_initial_balance:"\
  " #{@maximum_initial_balance}, filters: #{@filters}, credit_block_source:"\
  " #{@credit_block_source}, credit_allocation: #{@credit_allocation}, additional_properties:"\
  " #{@additional_properties}>"
end