Class: ApiReference::PreviewEvent

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

Overview

PreviewEvent 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:, customer_id: SKIP, external_customer_id: SKIP) ⇒ PreviewEvent

Returns a new instance of PreviewEvent.



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

def initialize(event_name:, timestamp:, properties:, 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
end

Instance Attribute Details

#customer_idString

The Orb Customer identifier

Returns:

  • (String)


15
16
17
# File 'lib/api_reference/models/preview_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/preview_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/preview_event.rb', line 20

def external_customer_id
  @external_customer_id
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/preview_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/preview_event.rb', line 30

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/api_reference/models/preview_event.rb', line 74

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
  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.
  PreviewEvent.new(event_name: event_name,
                   timestamp: timestamp,
                   properties: properties,
                   customer_id: customer_id,
                   external_customer_id: external_customer_id)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
# File 'lib/api_reference/models/preview_event.rb', line 38

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
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    customer_id
    external_customer_id
  ]
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
# File 'lib/api_reference/models/preview_event.rb', line 49

def self.optionals
  %w[
    customer_id
    external_customer_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



108
109
110
111
112
113
# File 'lib/api_reference/models/preview_event.rb', line 108

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}>"
end

#to_custom_timestampObject



95
96
97
# File 'lib/api_reference/models/preview_event.rb', line 95

def to_custom_timestamp
  DateTimeHelper.to_rfc3339(timestamp)
end

#to_sObject

Provides a human-readable string representation of the object.



100
101
102
103
104
105
# File 'lib/api_reference/models/preview_event.rb', line 100

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}>"
end