Sha256: 5f343428182f5512de17dfdde69343d054d50c055f95a3e588719397417e5e51

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module SecureNative
  class ApiManager
    def initialize(event_manager, securenative_options)
      @event_manager = event_manager
      @options = securenative_options
    end

    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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
securenative-0.1.40 lib/securenative/api_manager.rb
securenative-0.1.39 lib/securenative/api_manager.rb
securenative-0.1.38 lib/securenative/api_manager.rb
securenative-0.1.37 lib/securenative/api_manager.rb
securenative-0.1.36 lib/securenative/api_manager.rb
securenative-0.1.35 lib/securenative/api_manager.rb