Class: ApiReference::IngestEvent

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

Overview

IngestEvent Model.

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_name:, timestamp:, properties:, idempotency_key:, customer_id: SKIP, external_customer_id: SKIP) ⇒ IngestEvent

Returns a new instance of IngestEvent.



71
72
73
74
75
76
77
78
79
# File 'lib/api_reference/models/ingest_event.rb', line 71

def initialize(event_name:, timestamp:, properties:, idempotency_key:,
               customer_id: SKIP, external_customer_id: SKIP)
  @customer_id = customer_id unless customer_id == SKIP
  @external_customer_id = external_customer_id unless external_customer_id == SKIP
  @event_name = event_name
  @timestamp = timestamp
  @properties = properties
  @idempotency_key = idempotency_key
end

Instance Attribute Details

#customer_idString

The Orb Customer identifier

Returns:

  • (String)


15
16
17
# File 'lib/api_reference/models/ingest_event.rb', line 15

def customer_id
  @customer_id
end

#event_nameString

A name to meaningfully identify the action or event type.

Returns:

  • (String)


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

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)


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

def external_customer_id
  @external_customer_id
end

#idempotency_keyString

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)


41
42
43
# File 'lib/api_reference/models/ingest_event.rb', line 41

def idempotency_key
  @idempotency_key
end

#propertiesObject

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

Returns:

  • (Object)


35
36
37
# File 'lib/api_reference/models/ingest_event.rb', line 35

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)


30
31
32
# File 'lib/api_reference/models/ingest_event.rb', line 30

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/api_reference/models/ingest_event.rb', line 82

def self.from_hash(hash)
  return nil unless hash

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

  # Create object from extracted values.
  IngestEvent.new(event_name: event_name,
                  timestamp: timestamp,
                  properties: properties,
                  idempotency_key: idempotency_key,
                  customer_id: customer_id,
                  external_customer_id: external_customer_id)
end

.namesObject

A mapping from model property names to API property names.



44
45
46
47
48
49
50
51
52
53
# File 'lib/api_reference/models/ingest_event.rb', line 44

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

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    customer_id
    external_customer_id
  ]
end

.optionalsObject

An array for optional fields



56
57
58
59
60
61
# File 'lib/api_reference/models/ingest_event.rb', line 56

def self.optionals
  %w[
    customer_id
    external_customer_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



119
120
121
122
123
124
125
# File 'lib/api_reference/models/ingest_event.rb', line 119

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

#to_custom_timestampObject



106
107
108
# File 'lib/api_reference/models/ingest_event.rb', line 106

def to_custom_timestamp
  DateTimeHelper.to_rfc3339(timestamp)
end

#to_sObject

Provides a human-readable string representation of the object.



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

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