Class: ApiReference::DailyCreditAllowanceConfig

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

Overview

Pricing model that gives a daily credit budget across one or more dimensional rates. Each event is rated in credits at a per-dimension unit_amount. Events are bucketed into days via an event_day_property set on the event (e.g. an ISO date string in the customer's timezone, supplied at ingest by the customer). Within each day the first daily_allowance credits are free; usage beyond that is charged in full. The allowance does not roll over. Use cases: shared daily AI-token budgets where different models have different credit costs.

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(event_day_property:, dimensions:, default_unit_amount:, daily_allowance:, matrix_values:) ⇒ DailyCreditAllowanceConfig

Returns a new instance of DailyCreditAllowanceConfig.



63
64
65
66
67
68
69
70
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 63

def initialize(event_day_property:, dimensions:, default_unit_amount:,
               daily_allowance:, matrix_values:)
  @event_day_property = event_day_property
  @dimensions = dimensions
  @default_unit_amount = default_unit_amount
  @daily_allowance = daily_allowance
  @matrix_values = matrix_values
end

Instance Attribute Details

#daily_allowanceString

Credits granted per day. Lose-it-or-use-it; does not roll over.

Returns:

  • (String)


36
37
38
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 36

def daily_allowance
  @daily_allowance
end

#default_unit_amountString

Default per-unit credit rate for any usage not bucketed into a specified matrix_value

Returns:

  • (String)


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

def default_unit_amount
  @default_unit_amount
end

#dimensionsArray[String]

One or two event property values to evaluate matrix groups by

Returns:

  • (Array[String])


27
28
29
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 27

def dimensions
  @dimensions
end

#event_day_propertyString

Event property whose value identifies the day bucket the event belongs to (e.g. 'event_day' set to an ISO date string in the customer's timezone). The allowance resets per distinct value of this property.

Returns:

  • (String)


23
24
25
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 23

def event_day_property
  @event_day_property
end

#matrix_valuesArray[DailyCreditAllowanceMatrixValue]

Per-dimension credit rates



40
41
42
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 40

def matrix_values
  @matrix_values
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



73
74
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/api_reference/models/daily_credit_allowance_config.rb', line 73

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  event_day_property =
    hash.key?('event_day_property') ? hash['event_day_property'] : nil
  dimensions = hash.key?('dimensions') ? hash['dimensions'] : nil
  default_unit_amount =
    hash.key?('default_unit_amount') ? hash['default_unit_amount'] : nil
  daily_allowance =
    hash.key?('daily_allowance') ? hash['daily_allowance'] : nil
  # Parameter is an array, so we need to iterate through it
  matrix_values = nil
  unless hash['matrix_values'].nil?
    matrix_values = []
    hash['matrix_values'].each do |structure|
      matrix_values << (DailyCreditAllowanceMatrixValue.from_hash(structure) if structure)
    end
  end

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

  # Create object from extracted values.
  DailyCreditAllowanceConfig.new(event_day_property: event_day_property,
                                 dimensions: dimensions,
                                 default_unit_amount: default_unit_amount,
                                 daily_allowance: daily_allowance,
                                 matrix_values: matrix_values)
end

.namesObject

A mapping from model property names to API property names.



43
44
45
46
47
48
49
50
51
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 43

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['event_day_property'] = 'event_day_property'
  @_hash['dimensions'] = 'dimensions'
  @_hash['default_unit_amount'] = 'default_unit_amount'
  @_hash['daily_allowance'] = 'daily_allowance'
  @_hash['matrix_values'] = 'matrix_values'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 59

def self.nullables
  []
end

.optionalsObject

An array for optional fields



54
55
56
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 54

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



112
113
114
115
116
117
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 112

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} event_day_property: #{@event_day_property.inspect}, dimensions:"\
  " #{@dimensions.inspect}, default_unit_amount: #{@default_unit_amount.inspect},"\
  " daily_allowance: #{@daily_allowance.inspect}, matrix_values: #{@matrix_values.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



104
105
106
107
108
109
# File 'lib/api_reference/models/daily_credit_allowance_config.rb', line 104

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} event_day_property: #{@event_day_property}, dimensions: #{@dimensions},"\
  " default_unit_amount: #{@default_unit_amount}, daily_allowance: #{@daily_allowance},"\
  " matrix_values: #{@matrix_values}>"
end