Class: SecureNative::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

._flushObject



68
69
70
# File 'lib/securenative/client.rb', line 68

def self._flush
  @securenative = nil
end

.initObject



49
50
51
52
# 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



20
21
22
23
24
25
26
27
28
# 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

.instanceObject



54
55
56
57
58
# File 'lib/securenative/client.rb', line 54

def self.instance
  raise SecureNativeSDKIllegalStateError if @securenative.nil?

  @securenative
end

Instance Method Details

#from_http_request(request) ⇒ Object



45
46
47
# File 'lib/securenative/client.rb', line 45

def from_http_request(request)
  SecureNative::Context.from_http_request(request, @options)
end

#track(event_options) ⇒ Object



60
61
62
# File 'lib/securenative/client.rb', line 60

def track(event_options)
  @api_manager.track(event_options)
end

#verify(event_options) ⇒ Object



64
65
66
# File 'lib/securenative/client.rb', line 64

def verify(event_options)
  @api_manager.verify(event_options)
end

#verify_request_payload(request) ⇒ Object



72
73
74
75
76
77
# 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