Class: Itly::Plugin::Iteratively::TrackModel

Inherits:
Object
  • Object
show all
Defined in:
lib/itly/plugin/iteratively/track_model.rb

Overview

Data model for HTTP client buffering

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, event:, properties:, validation: nil, omit_values: false) ⇒ TrackModel

Returns a new instance of TrackModel.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/itly/plugin/iteratively/track_model.rb', line 17

def initialize(type:, event:, properties:, validation: nil, omit_values: false)
  @omit_values = omit_values
  @type = type
  @date_sent = Time.now.utc.iso8601
  @event_id = event&.id
  @event_schema_version = event&.version
  @event_name = event&.name
  @properties = event&.properties || properties
  @valid = validation ? validation.valid : true
  @validation = { details: validation ? validation.message : '' }

  @properties = @properties.transform_values { |_| '' } if @omit_values
end

Instance Attribute Details

#date_sentObject (readonly)

Returns the value of attribute date_sent.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def date_sent
  @date_sent
end

#event_idObject (readonly)

Returns the value of attribute event_id.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def event_id
  @event_id
end

#event_nameObject (readonly)

Returns the value of attribute event_name.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def event_name
  @event_name
end

#event_schema_versionObject (readonly)

Returns the value of attribute event_schema_version.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def event_schema_version
  @event_schema_version
end

#propertiesObject (readonly)

Returns the value of attribute properties.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def properties
  @properties
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def type
  @type
end

#validObject (readonly)

Returns the value of attribute valid.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def valid
  @valid
end

#validationObject (readonly)

Returns the value of attribute validation.



14
15
16
# File 'lib/itly/plugin/iteratively/track_model.rb', line 14

def validation
  @validation
end

Instance Method Details

#to_json(*_) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/itly/plugin/iteratively/track_model.rb', line 31

def to_json(*_)
  {
    type: @type,
    dateSent: @date_sent,
    eventId: @event_id,
    eventSchemaVersion: @event_schema_version,
    eventName: @event_name,
    properties: @properties,
    valid: @valid,
    validation: @validation
  }.to_json
end

#to_sObject



44
45
46
47
48
# File 'lib/itly/plugin/iteratively/track_model.rb', line 44

def to_s
  "#<#{self.class.name}: type: #{@type} date_sent: #{@date_sent} event_id: #{@event_id} "\
    "event_schema_version: #{@event_schema_version} event_name: #{@event_name} "\
    "properties: #{@properties} valid: #{@valid} validation: #{@validation}>"
end