Class: ApiReference::Event

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

Overview

The Event resource represents a usage event that has been created for a customer. Events are the core of Orb's usage-based billing model, and are used to calculate the usage charges for a given billing period.

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(id:, customer_id:, external_customer_id:, event_name:, properties:, timestamp:, deprecated:, additional_properties: nil) ⇒ Event

Returns a new instance of Event.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/api_reference/models/event.rb', line 76

def initialize(id:, customer_id:, external_customer_id:, event_name:,
               properties:, timestamp:, deprecated:,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id
  @customer_id = customer_id
  @external_customer_id = external_customer_id
  @event_name = event_name
  @properties = properties
  @timestamp = timestamp
  @deprecated = deprecated
  @additional_properties = additional_properties
end

Instance Attribute Details

#customer_idString

The Orb Customer identifier

Returns:

  • (String)


24
25
26
# File 'lib/api_reference/models/event.rb', line 24

def customer_id
  @customer_id
end

#deprecatedTrueClass | FalseClass

A boolean indicating whether the event is currently deprecated.

Returns:

  • (TrueClass | FalseClass)


48
49
50
# File 'lib/api_reference/models/event.rb', line 48

def deprecated
  @deprecated
end

#event_nameString

A name to meaningfully identify the action or event type.

Returns:

  • (String)


33
34
35
# File 'lib/api_reference/models/event.rb', line 33

def event_name
  @event_name
end

#external_customer_idString

An alias for the Orb customer, whose mapping is specified when creating the customer

Returns:

  • (String)


29
30
31
# File 'lib/api_reference/models/event.rb', line 29

def external_customer_id
  @external_customer_id
end

#idString

A unique value, generated by the client, that is used to de-duplicate events. Exactly one event with a given idempotency key will be ingested, which allows for safe request retries.

Returns:

  • (String)


20
21
22
# File 'lib/api_reference/models/event.rb', line 20

def id
  @id
end

#propertiesObject

A dictionary of custom properties. Values in this dictionary must be numeric, boolean, or strings. Nested dictionaries are disallowed.

Returns:

  • (Object)


38
39
40
# File 'lib/api_reference/models/event.rb', line 38

def properties
  @properties
end

#timestampDateTime

An ISO 8601 format date with no timezone offset (i.e. UTC). This should represent the time that usage was recorded, and is particularly important to attribute usage to a given billing period.

Returns:

  • (DateTime)


44
45
46
# File 'lib/api_reference/models/event.rb', line 44

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/api_reference/models/event.rb', line 93

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : nil
  external_customer_id =
    hash.key?('external_customer_id') ? hash['external_customer_id'] : nil
  event_name = hash.key?('event_name') ? hash['event_name'] : nil
  properties = hash.key?('properties') ? hash['properties'] : nil
  timestamp = if hash.key?('timestamp')
                (DateTimeHelper.from_rfc3339(hash['timestamp']) if hash['timestamp'])
              end
  deprecated = hash.key?('deprecated') ? hash['deprecated'] : nil

  # 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.
  Event.new(id: id,
            customer_id: customer_id,
            external_customer_id: external_customer_id,
            event_name: event_name,
            properties: properties,
            timestamp: timestamp,
            deprecated: deprecated,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/api_reference/models/event.rb', line 51

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['customer_id'] = 'customer_id'
  @_hash['external_customer_id'] = 'external_customer_id'
  @_hash['event_name'] = 'event_name'
  @_hash['properties'] = 'properties'
  @_hash['timestamp'] = 'timestamp'
  @_hash['deprecated'] = 'deprecated'
  @_hash
end

.nullablesObject

An array for nullable fields



69
70
71
72
73
74
# File 'lib/api_reference/models/event.rb', line 69

def self.nullables
  %w[
    customer_id
    external_customer_id
  ]
end

.optionalsObject

An array for optional fields



64
65
66
# File 'lib/api_reference/models/event.rb', line 64

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



140
141
142
143
144
145
146
147
# File 'lib/api_reference/models/event.rb', line 140

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, customer_id: #{@customer_id.inspect},"\
  " external_customer_id: #{@external_customer_id.inspect}, event_name:"\
  " #{@event_name.inspect}, properties: #{@properties.inspect}, timestamp:"\
  " #{@timestamp.inspect}, deprecated: #{@deprecated.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_timestampObject



126
127
128
# File 'lib/api_reference/models/event.rb', line 126

def to_custom_timestamp
  DateTimeHelper.to_rfc3339(timestamp)
end

#to_sObject

Provides a human-readable string representation of the object.



131
132
133
134
135
136
137
# File 'lib/api_reference/models/event.rb', line 131

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, customer_id: #{@customer_id}, external_customer_id:"\
  " #{@external_customer_id}, event_name: #{@event_name}, properties: #{@properties},"\
  " timestamp: #{@timestamp}, deprecated: #{@deprecated}, additional_properties:"\
  " #{@additional_properties}>"
end