class SecureNative::Client

Attributes

options[R]

Public Class Methods

_flush() click to toggle source
# File lib/securenative/client.rb, line 68
def self._flush
  @securenative = nil
end
init() click to toggle source
# File lib/securenative/client.rb, line 49
def self.init
  options = SecureNative::Config::ConfigurationManager.load_config
  init_with_options(options)
end
init_with_api_key(api_key) click to toggle source
# File lib/securenative/client.rb, line 30
def self.init_with_api_key(api_key)
  if SecureNative::Utils::Utils.null_or_empty?(api_key)
    raise SecureNativeConfigError, 'You must pass your SecureNative api key'
  end

  if @securenative.nil?
    options = SecureNative::Config::ConfigurationBuilder.new(api_key: api_key)
    @securenative = SecureNative::Client.new(options)
    @securenative
  else
    SecureNative::Log.debug('This SDK was already initialized.')
    raise SecureNativeSDKError, 'This SDK was already initialized.'
  end
end
init_with_options(options) click to toggle source
# File lib/securenative/client.rb, line 20
def self.init_with_options(options)
  if @securenative.nil?
    @securenative = SecureNative::Client.new(options)
    @securenative
  else
    SecureNative::Log.debug('This SDK was already initialized.')
    raise SecureNativeSDKError, 'This SDK was already initialized.'
  end
end
instance() click to toggle source
# File lib/securenative/client.rb, line 54
def self.instance
  raise SecureNativeSDKIllegalStateError if @securenative.nil?

  @securenative
end
new(options) click to toggle source
# File lib/securenative/client.rb, line 7
def initialize(options)
  @securenative = nil
  if SecureNative::Utils::Utils.null_or_empty?(options.api_key)
    raise SecureNativeSDKError, 'You must pass your SecureNative api key'
  end

  @options = options
  @event_manager = EventManager.new(@options)

  @api_manager = SecureNative::ApiManager.new(@event_manager, @options)
  SecureNative::Log.init_logger(@options.log_level)
end

Public Instance Methods

from_http_request(request) click to toggle source
# File lib/securenative/client.rb, line 45
def from_http_request(request)
  SecureNative::Context.from_http_request(request, @options)
end
track(event_options) click to toggle source
# File lib/securenative/client.rb, line 60
def track(event_options)
  @api_manager.track(event_options)
end
verify(event_options) click to toggle source
# File lib/securenative/client.rb, line 64
def verify(event_options)
  @api_manager.verify(event_options)
end
verify_request_payload(request) click to toggle source
# File lib/securenative/client.rb, line 72
def verify_request_payload(request)
  request_signature = request.header[SignatureUtils.SIGNATURE_HEADER]
  body = request.body

  SignatureUtils.valid_signature?(@options.api_key, body, request_signature)
end