securenative 0.1.17 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -2
- data/.github/workflows/test.yml +5 -2
- data/.gitignore +3 -1
- data/Gemfile +6 -4
- data/Gemfile.lock +234 -25
- data/README.md +37 -32
- data/lib/api_manager.rb +39 -0
- data/lib/config/configuration_builder.rb +27 -0
- data/lib/config/configuration_manager.rb +56 -0
- data/lib/config/securenative_options.rb +23 -0
- data/lib/context/hanami_context.rb +42 -0
- data/lib/context/rails_context.rb +44 -0
- data/lib/context/securenative_context.rb +67 -0
- data/lib/context/sinatra_context.rb +42 -0
- data/lib/enums/api_route.rb +6 -0
- data/lib/enums/event_types.rb +23 -0
- data/lib/enums/failover_strategy.rb +6 -0
- data/lib/enums/risk_level.rb +7 -0
- data/lib/errors/securenative_config_error.rb +4 -0
- data/lib/errors/securenative_http_error.rb +4 -0
- data/lib/errors/securenative_invalid_options_error.rb +4 -0
- data/lib/errors/securenative_invalid_uri_error.rb +4 -0
- data/lib/errors/securenative_parse_error.rb +4 -0
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/lib/errors/securenative_sdk_error.rb +4 -0
- data/lib/event_manager.rb +157 -0
- data/lib/{securenative/http/http_response.rb → http/secure_native_http_response.rb} +4 -2
- data/lib/http/securenative_http_client.rb +50 -0
- data/lib/{securenative/models → models}/client_token.rb +2 -0
- data/lib/{securenative/models → models}/device.rb +3 -1
- data/lib/models/event_options.rb +37 -0
- data/lib/{securenative/models → models}/request_context.rb +7 -4
- data/lib/models/request_options.rb +12 -0
- data/lib/models/sdk_event.rb +49 -0
- data/lib/{securenative/models → models}/user_traits.rb +4 -2
- data/lib/{securenative/models → models}/verify_result.rb +8 -2
- data/lib/securenative.rb +83 -0
- data/lib/utils/date_utils.rb +9 -0
- data/lib/utils/encryption_utils.rb +49 -0
- data/lib/{securenative/utils → utils}/ip_utils.rb +7 -6
- data/lib/utils/request_utils.rb +69 -0
- data/lib/{securenative/logger.rb → utils/secure_native_logger.rb} +5 -3
- data/lib/{securenative/utils → utils}/signature_utils.rb +4 -2
- data/lib/utils/utils.rb +9 -0
- data/lib/utils/version_utils.rb +11 -0
- data/out/production/securenative-ruby/api_manager.rb +39 -0
- data/out/production/securenative-ruby/config/configuration_builder.rb +27 -0
- data/out/production/securenative-ruby/config/configuration_manager.rb +56 -0
- data/out/production/securenative-ruby/config/securenative_options.rb +23 -0
- data/out/production/securenative-ruby/context/hanami_context.rb +42 -0
- data/out/production/securenative-ruby/context/rails_context.rb +44 -0
- data/out/production/securenative-ruby/context/securenative_context.rb +67 -0
- data/out/production/securenative-ruby/context/sinatra_context.rb +42 -0
- data/out/production/securenative-ruby/enums/api_route.rb +6 -0
- data/out/production/securenative-ruby/enums/event_types.rb +23 -0
- data/out/production/securenative-ruby/enums/failover_strategy.rb +6 -0
- data/out/production/securenative-ruby/enums/risk_level.rb +7 -0
- data/out/production/securenative-ruby/errors/securenative_config_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +4 -0
- data/out/production/securenative-ruby/event_manager.rb +157 -0
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +12 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +50 -0
- data/out/production/securenative-ruby/models/client_token.rb +12 -0
- data/out/production/securenative-ruby/models/device.rb +10 -0
- data/out/production/securenative-ruby/models/event_options.rb +37 -0
- data/out/production/securenative-ruby/models/request_context.rb +18 -0
- data/out/production/securenative-ruby/models/request_options.rb +12 -0
- data/out/production/securenative-ruby/models/sdk_event.rb +49 -0
- data/out/production/securenative-ruby/models/user_traits.rb +13 -0
- data/out/production/securenative-ruby/models/verify_result.rb +16 -0
- data/out/production/securenative-ruby/securenative.rb +83 -0
- data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
- data/out/production/securenative-ruby/utils/encryption_utils.rb +49 -0
- data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
- data/out/production/securenative-ruby/utils/request_utils.rb +69 -0
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +44 -0
- data/out/production/securenative-ruby/utils/signature_utils.rb +16 -0
- data/out/production/securenative-ruby/utils/utils.rb +9 -0
- data/out/production/securenative-ruby/utils/version_utils.rb +11 -0
- data/out/test/securenative-ruby/spec_api_manager.rb +87 -0
- data/out/test/securenative-ruby/spec_context_builder.rb +87 -0
- data/out/test/securenative-ruby/spec_date_utils.rb +13 -0
- data/out/test/securenative-ruby/spec_encryption_utils.rb +26 -0
- data/out/test/securenative-ruby/spec_event_manager.rb +93 -0
- data/out/test/securenative-ruby/spec_helper.rb +28 -0
- data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
- data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
- data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
- data/out/test/securenative-ruby/spec_securenative.rb +61 -0
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +31 -0
- data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +2 -2
- metadata +93 -43
- data/.travis.yml +0 -6
- data/VERSION +0 -1
- data/lib/securenative/api_manager.rb +0 -30
- data/lib/securenative/config/configuration_builder.rb +0 -26
- data/lib/securenative/config/configuration_manager.rb +0 -53
- data/lib/securenative/config/securenative_options.rb +0 -18
- data/lib/securenative/context/context_builder.rb +0 -59
- data/lib/securenative/context/securenative_context.rb +0 -14
- data/lib/securenative/enums/api_route.rb +0 -4
- data/lib/securenative/enums/event_types.rb +0 -21
- data/lib/securenative/enums/failover_strategy.rb +0 -4
- data/lib/securenative/enums/risk_level.rb +0 -5
- data/lib/securenative/event_manager.rb +0 -150
- data/lib/securenative/event_options_builder.rb +0 -30
- data/lib/securenative/exceptions/securenative_config_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_http_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_options_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_uri_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_parse_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_exception.rb +0 -2
- data/lib/securenative/http/securenative_http_client.rb +0 -30
- data/lib/securenative/models/event_options.rb +0 -13
- data/lib/securenative/models/request_options.rb +0 -10
- data/lib/securenative/models/sdk_event.rb +0 -25
- data/lib/securenative/securenative.iml +0 -9
- data/lib/securenative/securenative.rb +0 -82
- data/lib/securenative/utils/date_utils.rb +0 -7
- data/lib/securenative/utils/encryption_utils.rb +0 -38
- data/lib/securenative/utils/request_utils.rb +0 -21
- data/lib/securenative/utils/utils.rb +0 -9
- data/lib/securenative/utils/version_utils.rb +0 -10
data/.travis.yml
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.17
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require_relative 'logger'
|
3
|
-
|
4
|
-
class ApiManager
|
5
|
-
def initialize(event_manager, securenative_options)
|
6
|
-
@event_manager = event_manager
|
7
|
-
@options = securenative_options
|
8
|
-
end
|
9
|
-
|
10
|
-
def track(event_options)
|
11
|
-
Logger.debug('Track event call')
|
12
|
-
event = SDKEvent.new(event_options, @options)
|
13
|
-
@event_manager.send_async(event, ApiRoute::TRACK)
|
14
|
-
end
|
15
|
-
|
16
|
-
def verify(event_options)
|
17
|
-
Logger.debug('Verify event call')
|
18
|
-
event = SDKEvent.new(event_options, @options)
|
19
|
-
|
20
|
-
begin
|
21
|
-
res = JSON.parse(@event_manager.send_sync(event, ApiRoute::VERIFY, false))
|
22
|
-
return VerifyResult.new(res['riskLevel'], res['score'], res['triggers'])
|
23
|
-
rescue StandardError => e
|
24
|
-
Logger.debug('Failed to call verify; {}'.format(e))
|
25
|
-
end
|
26
|
-
return VerifyResult.new(RiskLevel::LOW, 0, nil) if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
|
27
|
-
|
28
|
-
VerifyResult.new(RiskLevel::HIGH, 1, nil)
|
29
|
-
end
|
30
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class ConfigurationBuilder
|
2
|
-
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
|
3
|
-
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
|
4
|
-
|
5
|
-
def initialize(api_key = nil, api_url = 'https://api.securenative.com/collector/api/v1', interval = 1000,
|
6
|
-
max_events = 1000, timeout = 1500, auto_send = true, disable = false, log_level = 'FATAL',
|
7
|
-
fail_over_strategy = FailOverStrategy::FAIL_OPEN)
|
8
|
-
@api_key = api_key
|
9
|
-
@api_url = api_url
|
10
|
-
@interval = interval
|
11
|
-
@max_events = max_events
|
12
|
-
@timeout = timeout
|
13
|
-
@auto_send = auto_send
|
14
|
-
@disable = disable
|
15
|
-
@log_level = log_level
|
16
|
-
@fail_over_strategy = fail_over_strategy
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.default_config_builder
|
20
|
-
ConfigurationBuilder()
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.default_securenative_options
|
24
|
-
SecureNativeOptions()
|
25
|
-
end
|
26
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'parseconfig'
|
2
|
-
|
3
|
-
class ConfigurationManager
|
4
|
-
DEFAULT_CONFIG_FILE = 'securenative.cfg'.freeze
|
5
|
-
CUSTOM_CONFIG_FILE_ENV_NAME = 'SECURENATIVE_COMFIG_FILE'.freeze
|
6
|
-
@config = nil
|
7
|
-
|
8
|
-
def self.read_resource_file(resource_path)
|
9
|
-
@config = ParseConfig.new(resource_path)
|
10
|
-
|
11
|
-
properties = {}
|
12
|
-
@config.get_groups.each { |group|
|
13
|
-
group.each do |key, value|
|
14
|
-
properties[key.upcase] = value
|
15
|
-
end
|
16
|
-
}
|
17
|
-
properties
|
18
|
-
end
|
19
|
-
|
20
|
-
def self._get_resource_path(env_name)
|
21
|
-
Env.fetch(env_name, ENV[DEFAULT_CONFIG_FILE])
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.config_builder
|
25
|
-
ConfigurationBuilder.default_config_builder
|
26
|
-
end
|
27
|
-
|
28
|
-
def self._get_env_or_default(properties, key, default)
|
29
|
-
return Env[key] if Env[key]
|
30
|
-
return properties[key] if properties[key]
|
31
|
-
|
32
|
-
default
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.load_config
|
36
|
-
options = ConfigurationBuilder().default_securenative_options
|
37
|
-
|
38
|
-
resource_path = DEFAULT_CONFIG_FILE
|
39
|
-
resource_path = Env[CUSTOM_CONFIG_FILE_ENV_NAME] if Env[CUSTOM_CONFIG_FILE_ENV_NAME]
|
40
|
-
|
41
|
-
properties = read_resource_file(resource_path)
|
42
|
-
|
43
|
-
ConfigurationBuilder(_get_env_or_default(properties, 'SECURENATIVE_API_KEY', options.api_key),
|
44
|
-
_get_env_or_default(properties, 'SECURENATIVE_API_URL', options.api_url),
|
45
|
-
_get_env_or_default(properties, 'SECURENATIVE_INTERVAL', options.interval),
|
46
|
-
_get_env_or_default(properties, 'SECURENATIVE_MAX_EVENTS', options.max_events),
|
47
|
-
_get_env_or_default(properties, 'SECURENATIVE_TIMEOUT', options.timeout),
|
48
|
-
_get_env_or_default(properties, 'SECURENATIVE_AUTO_SEND', options.auto_send),
|
49
|
-
_get_env_or_default(properties, 'SECURENATIVE_DISABLE', options.disable),
|
50
|
-
_get_env_or_default(properties, 'SECURENATIVE_LOG_LEVEL', options.log_level),
|
51
|
-
_get_env_or_default(properties, 'SECURENATIVE_FAILOVER_STRATEGY', options.fail_over_strategy))
|
52
|
-
end
|
53
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class SecureNativeOptions
|
2
|
-
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
|
3
|
-
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
|
4
|
-
|
5
|
-
def initialize(api_key = nil, api_url = "https://api.securenative.com/collector/api/v1", interval = 1000,
|
6
|
-
max_events = 1000, timeout = 1500, auto_send = true, disable = false, log_level = "FATAL",
|
7
|
-
fail_over_strategy = FailOverStrategy::FAIL_OPEN)
|
8
|
-
@api_key = api_key
|
9
|
-
@api_url = api_url
|
10
|
-
@interval = interval
|
11
|
-
@max_events = max_events
|
12
|
-
@timeout = timeout
|
13
|
-
@auto_send = auto_send
|
14
|
-
@disable = disable
|
15
|
-
@log_level = log_level
|
16
|
-
@fail_over_strategy = fail_over_strategy
|
17
|
-
end
|
18
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
class ContextBuilder
|
2
|
-
attr_reader :context
|
3
|
-
|
4
|
-
def initialize(client_token = nil, ip = nil, remote_ip = nil, headers = nil, url = nil, method = nil, body = nil)
|
5
|
-
@context = SecureNativeContext(client_token, ip, remote_ip, headers, url, method, body)
|
6
|
-
end
|
7
|
-
|
8
|
-
def client_token(client_token)
|
9
|
-
@context.client_token = client_token
|
10
|
-
end
|
11
|
-
|
12
|
-
def ip(ip)
|
13
|
-
@context.ip = ip
|
14
|
-
end
|
15
|
-
|
16
|
-
def remote_ip(remote_ip)
|
17
|
-
@context.remote_ip = remote_ip
|
18
|
-
end
|
19
|
-
|
20
|
-
def headers(headers)
|
21
|
-
@context.headers = headers
|
22
|
-
end
|
23
|
-
|
24
|
-
def url(url)
|
25
|
-
@context.url = url
|
26
|
-
end
|
27
|
-
|
28
|
-
def method(method)
|
29
|
-
@context.method = method
|
30
|
-
end
|
31
|
-
|
32
|
-
def body(body)
|
33
|
-
@context.body = body
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.default_context_builder
|
37
|
-
ContextBuilder()
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.from_http_request(request)
|
41
|
-
begin
|
42
|
-
client_token = request.cookies[RequestUtils.SECURENATIVE_COOKIE]
|
43
|
-
rescue StandardError
|
44
|
-
client_token = nil
|
45
|
-
end
|
46
|
-
|
47
|
-
begin
|
48
|
-
headers = request.headers
|
49
|
-
rescue StandardError
|
50
|
-
headers = nil
|
51
|
-
end
|
52
|
-
|
53
|
-
client_token = RequestUtils.get_secure_header_from_request(headers) if Utils.null_or_empty?(client_token)
|
54
|
-
|
55
|
-
ContextBuilder(url = request.url, method = request.method, header = headers, client_token = client_token,
|
56
|
-
client_ip = RequestUtils.get_client_ip_from_request(request),
|
57
|
-
remote_ip = RequestUtils.get_remote_ip_from_request(request), nil)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class SecureNativeContext
|
2
|
-
attr_reader :client_token, :ip, :remote_ip, :headers, :url, :method, :body
|
3
|
-
attr_writer :client_token, :ip, :remote_ip, :headers, :url, :method, :body
|
4
|
-
|
5
|
-
def initialize(client_token = nil, ip = nil, remote_ip = nil, headers = nil, url = nil, method = nil, body = nil)
|
6
|
-
@client_token = client_token
|
7
|
-
@ip = ip
|
8
|
-
@remote_ip = remote_ip
|
9
|
-
@headers = headers
|
10
|
-
@url = url
|
11
|
-
@method = method
|
12
|
-
@body = body
|
13
|
-
end
|
14
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module EventTypes
|
2
|
-
LOG_IN = 'sn.user.login'.freeze
|
3
|
-
LOG_IN_CHALLENGE = 'sn.user.login.challenge'.freeze
|
4
|
-
LOG_IN_FAILURE = 'sn.user.login.failure'.freeze
|
5
|
-
LOG_OUT = 'sn.user.logout'.freeze
|
6
|
-
SIGN_UP = 'sn.user.signup'.freeze
|
7
|
-
AUTH_CHALLENGE = 'sn.user.auth.challenge'.freeze
|
8
|
-
AUTH_CHALLENGE_SUCCESS = 'sn.user.auth.challenge.success'.freeze
|
9
|
-
AUTH_CHALLENGE_FAILURE = 'sn.user.auth.challenge.failure'.freeze
|
10
|
-
TWO_FACTOR_DISABLE = 'sn.user.2fa.disable'.freeze
|
11
|
-
EMAIL_UPDATE = 'sn.user.email.update'.freeze
|
12
|
-
PASSWORD_REST = 'sn.user.password.reset'.freeze
|
13
|
-
PASSWORD_REST_SUCCESS = 'sn.user.password.reset.success'.freeze
|
14
|
-
PASSWORD_UPDATE = 'sn.user.password.update'.freeze
|
15
|
-
PASSWORD_REST_FAILURE = 'sn.user.password.reset.failure'.freeze
|
16
|
-
USER_INVITE = 'sn.user.invite'.freeze
|
17
|
-
ROLE_UPDATE = 'sn.user.role.update'.freeze
|
18
|
-
PROFILE_UPDATE = 'sn.user.profile.update'.freeze
|
19
|
-
PAGE_VIEW = 'sn.user.page.view'.freeze
|
20
|
-
VERIFY = 'sn.verify'.freeze
|
21
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
require_relative 'logger'
|
2
|
-
|
3
|
-
class QueueItem
|
4
|
-
attr_reader :url, :body, :retry
|
5
|
-
attr_writer :url, :body, :retry
|
6
|
-
|
7
|
-
def initialize(url, body, _retry)
|
8
|
-
@url = url
|
9
|
-
@body = body
|
10
|
-
@retry = _retry
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class EventManager
|
15
|
-
def initialize(options = SecureNativeOptions(), http_client = nil)
|
16
|
-
if options.api_key.nil?
|
17
|
-
raise SecureNativeSDKException('API key cannot be None, please get your API key from SecureNative console.')
|
18
|
-
end
|
19
|
-
|
20
|
-
@http_client = if http_client.nil?
|
21
|
-
SecureNativeHttpClient(options)
|
22
|
-
else
|
23
|
-
http_client
|
24
|
-
end
|
25
|
-
|
26
|
-
@queue = []
|
27
|
-
@thread = Thread.new(run)
|
28
|
-
@thread.start
|
29
|
-
|
30
|
-
@options = options
|
31
|
-
@send_enabled = false
|
32
|
-
@attempt = 0
|
33
|
-
@coefficients = [1, 1, 2, 3, 5, 8, 13]
|
34
|
-
@thread = nil
|
35
|
-
@interval = options.interval
|
36
|
-
end
|
37
|
-
|
38
|
-
def send_async(event, resource_path)
|
39
|
-
if @options.disable
|
40
|
-
Logger.warning('SDK is disabled. no operation will be performed')
|
41
|
-
return
|
42
|
-
end
|
43
|
-
|
44
|
-
item = QueueItem(resource_path, JSON.parse(EventManager.serialize(event)), false)
|
45
|
-
@queue.append(item)
|
46
|
-
end
|
47
|
-
|
48
|
-
def flush
|
49
|
-
@queue.each do |item|
|
50
|
-
@http_client.post(item.url, item.body)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def send_sync(event, resource_path, _retry)
|
55
|
-
if @options.disable
|
56
|
-
Logger.warning('SDK is disabled. no operation will be performed')
|
57
|
-
return
|
58
|
-
end
|
59
|
-
|
60
|
-
Logger.debug('Attempting to send event {}'.format(event))
|
61
|
-
res = @http_client.post(resource_path, JSON.parse(EventManager.serialize(event)))
|
62
|
-
|
63
|
-
if res.status_code != 200
|
64
|
-
Logger.info('SecureNative failed to call endpoint {} with event {}. adding back to queue'.format(resource_path, event))
|
65
|
-
item = QueueItem(resource_path, JSON.parse(EventManager.serialize(event)), _retry)
|
66
|
-
@queue.append(item)
|
67
|
-
end
|
68
|
-
|
69
|
-
res
|
70
|
-
end
|
71
|
-
|
72
|
-
def run
|
73
|
-
loop do
|
74
|
-
next unless !@queue.empty? && @send_enabled
|
75
|
-
|
76
|
-
@queue.each do |item|
|
77
|
-
begin
|
78
|
-
res = @http_client.post(item.url, item.body)
|
79
|
-
if res.status_code == 401
|
80
|
-
item.retry = false
|
81
|
-
elsif res.status_code != 200
|
82
|
-
raise SecureNativeHttpException(res.status_code)
|
83
|
-
end
|
84
|
-
Logger.debug('Event successfully sent; {}'.format(item.body))
|
85
|
-
return res
|
86
|
-
rescue StandardError => e
|
87
|
-
Logger.error('Failed to send event; {}'.format(e))
|
88
|
-
if item.retry
|
89
|
-
@attempt = 0 if @coefficients.length == @attempt + 1
|
90
|
-
|
91
|
-
back_off = @coefficients[@attempt] * @options.interval
|
92
|
-
Logger.debug('Automatic back-off of {}'.format(back_off))
|
93
|
-
@send_enabled = false
|
94
|
-
sleep back_off
|
95
|
-
@send_enabled = true
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
sleep @interval / 1000
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def start_event_persist
|
104
|
-
Logger.debug('Starting automatic event persistence')
|
105
|
-
if @options.auto_send || @send_enabled
|
106
|
-
@send_enabled = true
|
107
|
-
else
|
108
|
-
Logger.debug('Automatic event persistence is disabled, you should persist events manually')
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def stop_event_persist
|
113
|
-
if @send_enabled
|
114
|
-
Logger.debug('Attempting to stop automatic event persistence')
|
115
|
-
begin
|
116
|
-
flush
|
117
|
-
@thread&.stop
|
118
|
-
Logger.debug('Stopped event persistence')
|
119
|
-
rescue StandardError => e
|
120
|
-
Logger.error('Could not stop event scheduler; {}'.format(e))
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.serialize(obj)
|
126
|
-
{
|
127
|
-
rid: obj.rid,
|
128
|
-
eventType: obj.event_type,
|
129
|
-
userId: obj.user_id,
|
130
|
-
userTraits: {
|
131
|
-
name: obj.user_traits.name,
|
132
|
-
email: obj.user_traits.email,
|
133
|
-
phone: obj.user_traits.phone,
|
134
|
-
createdAt: obj.user_traits.created_at
|
135
|
-
},
|
136
|
-
request: {
|
137
|
-
cid: obj.request.cid,
|
138
|
-
vid: obj.request.vid,
|
139
|
-
fp: obj.request.fp,
|
140
|
-
ip: obj.request.ip,
|
141
|
-
remoteIp: obj.request.remote_ip,
|
142
|
-
method: obj.request.method,
|
143
|
-
url: obj.request.url,
|
144
|
-
headers: obj.request.headers
|
145
|
-
},
|
146
|
-
timestamp: obj.timestamp,
|
147
|
-
properties: obj.properties
|
148
|
-
}
|
149
|
-
end
|
150
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
class EventOptionsBuilder
|
2
|
-
MAX_PROPERTIES_SIZE = 10
|
3
|
-
|
4
|
-
def initialize(event_type, user_id, user_traits, user_name, email, phone, created_at, context, properties, timestamp)
|
5
|
-
traits = UserTraits(user_name)
|
6
|
-
if user_name && email && phone && created_at
|
7
|
-
traits = UserTraits(user_name, email, phone, created_at)
|
8
|
-
elsif user_name && email && phone
|
9
|
-
traits = UserTraits(user_name, email, phone)
|
10
|
-
elsif user_name && email
|
11
|
-
traits = UserTraits(user_name, email)
|
12
|
-
end
|
13
|
-
|
14
|
-
@event_options = EventOptions(event_type)
|
15
|
-
@event_options.user_id = user_id
|
16
|
-
@event_options.user_traits = user_traits if user_traits
|
17
|
-
@event_options.user_traits = traits
|
18
|
-
@event_options.context = context
|
19
|
-
@event_options.properties = properties
|
20
|
-
@event_options.timestamp = timestamp
|
21
|
-
end
|
22
|
-
|
23
|
-
def build
|
24
|
-
if !@event_options.properties.nil? && @event_options.properties.length > MAX_PROPERTIES_SIZE
|
25
|
-
raise SecureNativeInvalidOptionsException('You can have only up to {} custom properties', MAX_PROPERTIES_SIZE)
|
26
|
-
end
|
27
|
-
|
28
|
-
@event_options
|
29
|
-
end
|
30
|
-
end
|