Class: SecureNative::ApiManager

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

Instance Method Summary collapse

Constructor Details

#initialize(event_manager, securenative_options) ⇒ ApiManager

Returns a new instance of ApiManager.



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

def initialize(event_manager, securenative_options)
  @event_manager = event_manager
  @options = securenative_options
end

Instance Method Details

#track(event_options) ⇒ Object



10
11
12
13
14
# File 'lib/securenative/api_manager.rb', line 10

def track(event_options)
  SecureNative::Log.debug('Track event call')
  event = SecureNative::SDKEvent.new(event_options, @options)
  @event_manager.send_async(event, SecureNative::Enums::ApiRoute::TRACK)
end

#verify(event_options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/securenative/api_manager.rb', line 16

def verify(event_options)
  SecureNative::Log.debug('Verify event call')
  event = SecureNative::SDKEvent.new(event_options, @options)

  begin
    res = @event_manager.send_sync(event, SecureNative::Enums::ApiRoute::VERIFY)
    ver_result = JSON.parse(res.body)
    if res.code != "200"
      if @options.fail_over_strategy == SecureNative::FailOverStrategy::FAIL_OPEN
        return SecureNative::VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::LOW, score: 0, triggers: [])
      end
      return VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::HIGH, score: 1, triggers: [])
    end
    return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
  rescue StandardError => e
    SecureNative::Log.debug("Failed to call verify; #{e}")
  end
  if @options.fail_over_strategy == SecureNative::FailOverStrategy::FAIL_OPEN
    return SecureNative::VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::LOW, score: 0, triggers: [])
  end

  VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::HIGH, score: 1, triggers: [])
end