Class: SecureNative::SDKEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/securenative/sdk_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_options, securenative_options) ⇒ SDKEvent

Returns a new instance of SDKEvent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/securenative/sdk_event.rb', line 8

def initialize(event_options, securenative_options)
  if event_options.user_id.nil? || event_options.user_id.length <= 0 || event_options.user_id == ''
    raise SecureNativeInvalidOptionsError.new, 'Invalid event structure; User Id is missing'
  end

  if event_options.event.nil? || event_options.event.length <= 0 || event_options.event == ''
    raise SecureNativeInvalidOptionsError.new, 'Invalid event structure; Event Type is missing'
  end

  @context = if !event_options.context.nil?
               event_options.context
             else
               Context.default_context_builder
             end

  client_token = SecureNative::Utils::EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)

  @rid = SecureRandom.uuid.to_str
  @event_type = event_options.event
  @user_id = event_options.user_id
  @user_traits = event_options.user_traits
  @request = RequestContext.new(cid: client_token ? client_token.cid : '', vid: client_token ? client_token.vid : '',
                                fp: client_token ? client_token.fp : '', ip: @context.ip,
                                remote_ip: @context.remote_ip, headers: @context.headers,
                                url: @context.url, http_method: @context.http_method)


  @timestamp = SecureNative::Utils::DateUtils.to_timestamp(event_options.timestamp)
  @properties = event_options.properties
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def context
  @context
end

#event_typeObject

Returns the value of attribute event_type.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def event_type
  @event_type
end

#propertiesObject

Returns the value of attribute properties.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def properties
  @properties
end

#requestObject

Returns the value of attribute request.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def request
  @request
end

#ridObject

Returns the value of attribute rid.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def rid
  @rid
end

#timestampObject

Returns the value of attribute timestamp.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def timestamp
  @timestamp
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def user_id
  @user_id
end

#user_traitsObject

Returns the value of attribute user_traits.



5
6
7
# File 'lib/securenative/sdk_event.rb', line 5

def user_traits
  @user_traits
end

Instance Method Details

#to_sObject



39
40
41
42
# File 'lib/securenative/sdk_event.rb', line 39

def to_s
  "context: #{@context}, rid: #{@rid}, event_type: #{@event_type}, user_id: #{@user_id},
user_traits: #{@user_traits}, request: #{@request}, timestamp: #{@timestamp}, properties: #{@properties}"
end