securenative 0.1.5 → 0.1.21

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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +49 -0
  3. data/.github/workflows/publish.yml +60 -0
  4. data/.github/workflows/test.yml +48 -0
  5. data/.gitignore +3 -1
  6. data/.rakeTasks +7 -0
  7. data/.rspec +3 -0
  8. data/Gemfile +6 -1
  9. data/Gemfile.lock +254 -17
  10. data/README.md +140 -67
  11. data/Rakefile +5 -1
  12. data/lib/api_manager.rb +39 -0
  13. data/lib/config/configuration_builder.rb +26 -0
  14. data/lib/config/configuration_manager.rb +55 -0
  15. data/lib/config/securenative_options.rb +22 -0
  16. data/lib/context/hanami_context.rb +42 -0
  17. data/lib/context/rails_context.rb +44 -0
  18. data/lib/context/securenative_context.rb +67 -0
  19. data/lib/context/sinatra_context.rb +42 -0
  20. data/lib/enums/api_route.rb +6 -0
  21. data/lib/enums/event_types.rb +23 -0
  22. data/lib/enums/failover_strategy.rb +6 -0
  23. data/lib/enums/risk_level.rb +7 -0
  24. data/lib/errors/securenative_config_error.rb +4 -0
  25. data/lib/errors/securenative_http_error.rb +4 -0
  26. data/lib/errors/securenative_invalid_options_error.rb +4 -0
  27. data/lib/errors/securenative_invalid_uri_error.rb +4 -0
  28. data/lib/errors/securenative_parse_error.rb +4 -0
  29. data/lib/errors/securenative_sdk_Illegal_state_error.rb +4 -0
  30. data/lib/errors/securenative_sdk_error.rb +4 -0
  31. data/lib/event_manager.rb +157 -0
  32. data/lib/http/secure_native_http_response.rb +12 -0
  33. data/lib/http/securenative_http_client.rb +50 -0
  34. data/lib/models/client_token.rb +12 -0
  35. data/lib/models/device.rb +10 -0
  36. data/lib/models/event_options.rb +37 -0
  37. data/lib/models/request_context.rb +18 -0
  38. data/lib/models/request_options.rb +12 -0
  39. data/lib/models/sdk_event.rb +40 -0
  40. data/lib/models/user_traits.rb +13 -0
  41. data/lib/models/verify_result.rb +16 -0
  42. data/lib/securenative.rb +69 -25
  43. data/lib/utils/date_utils.rb +9 -0
  44. data/lib/utils/encryption_utils.rb +49 -0
  45. data/lib/utils/ip_utils.rb +23 -0
  46. data/lib/utils/request_utils.rb +54 -0
  47. data/lib/utils/secure_native_logger.rb +44 -0
  48. data/lib/utils/signature_utils.rb +16 -0
  49. data/lib/utils/utils.rb +9 -0
  50. data/lib/utils/version_utils.rb +11 -0
  51. data/out/production/securenative-ruby/api_manager.rb +31 -0
  52. data/out/production/securenative-ruby/config/configuration_builder.rb +30 -0
  53. data/out/production/securenative-ruby/config/configuration_manager.rb +55 -0
  54. data/out/production/securenative-ruby/config/securenative_options.rb +20 -0
  55. data/out/production/securenative-ruby/context/securenative_context.rb +40 -0
  56. data/out/production/securenative-ruby/enums/api_route.rb +6 -0
  57. data/out/production/securenative-ruby/enums/event_types.rb +23 -0
  58. data/out/production/securenative-ruby/enums/failover_strategy.rb +6 -0
  59. data/out/production/securenative-ruby/enums/risk_level.rb +7 -0
  60. data/out/production/securenative-ruby/errors/securenative_config_error.rb +4 -0
  61. data/out/production/securenative-ruby/errors/securenative_http_error.rb +4 -0
  62. data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +4 -0
  63. data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +4 -0
  64. data/out/production/securenative-ruby/errors/securenative_parse_error.rb +4 -0
  65. data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +4 -0
  66. data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +4 -0
  67. data/out/production/securenative-ruby/event_manager.rb +156 -0
  68. data/out/production/securenative-ruby/event_options.rb +32 -0
  69. data/out/production/securenative-ruby/http/http_response.rb +12 -0
  70. data/out/production/securenative-ruby/http/securenative_http_client.rb +32 -0
  71. data/out/production/securenative-ruby/models/client_token.rb +12 -0
  72. data/out/production/securenative-ruby/models/device.rb +10 -0
  73. data/out/production/securenative-ruby/models/event_options.rb +15 -0
  74. data/out/production/securenative-ruby/models/request_context.rb +18 -0
  75. data/out/production/securenative-ruby/models/request_options.rb +12 -0
  76. data/out/production/securenative-ruby/models/sdk_event.rb +33 -0
  77. data/out/production/securenative-ruby/models/user_traits.rb +13 -0
  78. data/out/production/securenative-ruby/models/verify_result.rb +12 -0
  79. data/out/production/securenative-ruby/securenative.rb +91 -0
  80. data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
  81. data/out/production/securenative-ruby/utils/encryption_utils.rb +35 -0
  82. data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
  83. data/out/production/securenative-ruby/utils/request_utils.rb +23 -0
  84. data/out/production/securenative-ruby/utils/secure_native_logger.rb +44 -0
  85. data/out/production/securenative-ruby/utils/signature_utils.rb +16 -0
  86. data/out/production/securenative-ruby/utils/utils.rb +9 -0
  87. data/out/production/securenative-ruby/utils/version_utils.rb +12 -0
  88. data/out/test/securenative-ruby/spec_api_manager.rb +81 -0
  89. data/out/test/securenative-ruby/spec_context_builder.rb +69 -0
  90. data/out/test/securenative-ruby/spec_date_utils.rb +13 -0
  91. data/out/test/securenative-ruby/spec_encryption_utils.rb +26 -0
  92. data/out/test/securenative-ruby/spec_event_manager.rb +59 -0
  93. data/out/test/securenative-ruby/spec_helper.rb +20 -0
  94. data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
  95. data/out/test/securenative-ruby/spec_securenative.rb +65 -0
  96. data/out/test/securenative-ruby/spec_securenative_http_client.rb +23 -0
  97. data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
  98. data/securenative.gemspec +4 -4
  99. metadata +96 -15
  100. data/lib/securenative/config.rb +0 -9
  101. data/lib/securenative/event_manager.rb +0 -88
  102. data/lib/securenative/event_options.rb +0 -86
  103. data/lib/securenative/event_type.rb +0 -21
  104. data/lib/securenative/http_client.rb +0 -20
  105. data/lib/securenative/secure_native_sdk.rb +0 -62
  106. data/lib/securenative/securenative_options.rb +0 -17
  107. data/lib/securenative/sn_exception.rb +0 -5
  108. data/lib/securenative/utils.rb +0 -41
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'utils/signature_utils'
4
+ require 'rspec'
5
+
6
+ RSpec.describe SignatureUtils do
7
+ it 'verifies request payload' do
8
+ signature = 'c4574c1748064735513697750c6223ff36b03ae3b85b160ce8788557d01e1d9d1c9cd942074323ee0061d3dcc8c94359c5acfa6eee8e2da095b3967b1a88ab73'
9
+ payload = '{"id":"4a9157ffbd18cfbd73a57298","type":"security-action","flow":{"id":"62298c73a9bb433fbd1f75984a9157fd","name":"Block user that violates geo velocity"},"userId":"73a9bb433fbd1f75984a9157","userTraits":{"name":"John Doe","email":"john.doe@gmail.com"},"request":{"ip":"10.0.0.0","fp":"9bb433fb984a9157d1f7598"},"action":"block","properties":{"type":"customer"},"timestamp":"2020-02-23T22:28:55.387Z"}'
10
+ secret_key = 'B00C42DAD33EAC6F6572DA756EA4915349C0A4F6'
11
+
12
+ expect(SignatureUtils.valid_signature?(secret_key, payload, signature)).to be_truthy
13
+ end
14
+
15
+ it 'verifies request empty signature' do
16
+ expect(SignatureUtils.valid_signature?('', '', 'B00C42DAD33EAC6F6572DA756EA4915349C0A4F6')).to be_falsey
17
+ end
18
+ end
@@ -1,14 +1,14 @@
1
1
  lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "securenative/config"
3
+ require_relative "lib/utils/version_utils"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "securenative"
7
- spec.version = Config::SDK_VERSION
7
+ spec.version = "0.1.21"
8
8
  spec.authors = ["SecureNative"]
9
9
  spec.email = ["support@securenative.com"]
10
10
 
11
- spec.summary = %q{SecureNative SDK for ruby}
11
+ spec.summary = %q{SecureNative SDK for Ruby}
12
12
  spec.homepage = "https://www.securenative.com"
13
13
  spec.license = "MIT"
14
14
 
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 2.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rake", "~> 12.3.3"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securenative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - SecureNative
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-14 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  description:
42
42
  email:
43
43
  - support@securenative.com
@@ -45,7 +45,12 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".github/workflows/ci.yml"
49
+ - ".github/workflows/publish.yml"
50
+ - ".github/workflows/test.yml"
48
51
  - ".gitignore"
52
+ - ".rakeTasks"
53
+ - ".rspec"
49
54
  - Gemfile
50
55
  - Gemfile.lock
51
56
  - LICENSE
@@ -53,16 +58,92 @@ files:
53
58
  - Rakefile
54
59
  - bin/console
55
60
  - bin/setup
61
+ - lib/api_manager.rb
62
+ - lib/config/configuration_builder.rb
63
+ - lib/config/configuration_manager.rb
64
+ - lib/config/securenative_options.rb
65
+ - lib/context/hanami_context.rb
66
+ - lib/context/rails_context.rb
67
+ - lib/context/securenative_context.rb
68
+ - lib/context/sinatra_context.rb
69
+ - lib/enums/api_route.rb
70
+ - lib/enums/event_types.rb
71
+ - lib/enums/failover_strategy.rb
72
+ - lib/enums/risk_level.rb
73
+ - lib/errors/securenative_config_error.rb
74
+ - lib/errors/securenative_http_error.rb
75
+ - lib/errors/securenative_invalid_options_error.rb
76
+ - lib/errors/securenative_invalid_uri_error.rb
77
+ - lib/errors/securenative_parse_error.rb
78
+ - lib/errors/securenative_sdk_Illegal_state_error.rb
79
+ - lib/errors/securenative_sdk_error.rb
80
+ - lib/event_manager.rb
81
+ - lib/http/secure_native_http_response.rb
82
+ - lib/http/securenative_http_client.rb
83
+ - lib/models/client_token.rb
84
+ - lib/models/device.rb
85
+ - lib/models/event_options.rb
86
+ - lib/models/request_context.rb
87
+ - lib/models/request_options.rb
88
+ - lib/models/sdk_event.rb
89
+ - lib/models/user_traits.rb
90
+ - lib/models/verify_result.rb
56
91
  - lib/securenative.rb
57
- - lib/securenative/config.rb
58
- - lib/securenative/event_manager.rb
59
- - lib/securenative/event_options.rb
60
- - lib/securenative/event_type.rb
61
- - lib/securenative/http_client.rb
62
- - lib/securenative/secure_native_sdk.rb
63
- - lib/securenative/securenative_options.rb
64
- - lib/securenative/sn_exception.rb
65
- - lib/securenative/utils.rb
92
+ - lib/utils/date_utils.rb
93
+ - lib/utils/encryption_utils.rb
94
+ - lib/utils/ip_utils.rb
95
+ - lib/utils/request_utils.rb
96
+ - lib/utils/secure_native_logger.rb
97
+ - lib/utils/signature_utils.rb
98
+ - lib/utils/utils.rb
99
+ - lib/utils/version_utils.rb
100
+ - out/production/securenative-ruby/api_manager.rb
101
+ - out/production/securenative-ruby/config/configuration_builder.rb
102
+ - out/production/securenative-ruby/config/configuration_manager.rb
103
+ - out/production/securenative-ruby/config/securenative_options.rb
104
+ - out/production/securenative-ruby/context/securenative_context.rb
105
+ - out/production/securenative-ruby/enums/api_route.rb
106
+ - out/production/securenative-ruby/enums/event_types.rb
107
+ - out/production/securenative-ruby/enums/failover_strategy.rb
108
+ - out/production/securenative-ruby/enums/risk_level.rb
109
+ - out/production/securenative-ruby/errors/securenative_config_error.rb
110
+ - out/production/securenative-ruby/errors/securenative_http_error.rb
111
+ - out/production/securenative-ruby/errors/securenative_invalid_options_error.rb
112
+ - out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb
113
+ - out/production/securenative-ruby/errors/securenative_parse_error.rb
114
+ - out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb
115
+ - out/production/securenative-ruby/errors/securenative_sdk_error.rb
116
+ - out/production/securenative-ruby/event_manager.rb
117
+ - out/production/securenative-ruby/event_options.rb
118
+ - out/production/securenative-ruby/http/http_response.rb
119
+ - out/production/securenative-ruby/http/securenative_http_client.rb
120
+ - out/production/securenative-ruby/models/client_token.rb
121
+ - out/production/securenative-ruby/models/device.rb
122
+ - out/production/securenative-ruby/models/event_options.rb
123
+ - out/production/securenative-ruby/models/request_context.rb
124
+ - out/production/securenative-ruby/models/request_options.rb
125
+ - out/production/securenative-ruby/models/sdk_event.rb
126
+ - out/production/securenative-ruby/models/user_traits.rb
127
+ - out/production/securenative-ruby/models/verify_result.rb
128
+ - out/production/securenative-ruby/securenative.rb
129
+ - out/production/securenative-ruby/utils/date_utils.rb
130
+ - out/production/securenative-ruby/utils/encryption_utils.rb
131
+ - out/production/securenative-ruby/utils/ip_utils.rb
132
+ - out/production/securenative-ruby/utils/request_utils.rb
133
+ - out/production/securenative-ruby/utils/secure_native_logger.rb
134
+ - out/production/securenative-ruby/utils/signature_utils.rb
135
+ - out/production/securenative-ruby/utils/utils.rb
136
+ - out/production/securenative-ruby/utils/version_utils.rb
137
+ - out/test/securenative-ruby/spec_api_manager.rb
138
+ - out/test/securenative-ruby/spec_context_builder.rb
139
+ - out/test/securenative-ruby/spec_date_utils.rb
140
+ - out/test/securenative-ruby/spec_encryption_utils.rb
141
+ - out/test/securenative-ruby/spec_event_manager.rb
142
+ - out/test/securenative-ruby/spec_helper.rb
143
+ - out/test/securenative-ruby/spec_ip_utils.rb
144
+ - out/test/securenative-ruby/spec_securenative.rb
145
+ - out/test/securenative-ruby/spec_securenative_http_client.rb
146
+ - out/test/securenative-ruby/spec_signature_utils.rb
66
147
  - securenative.gemspec
67
148
  homepage: https://www.securenative.com
68
149
  licenses:
@@ -84,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
165
  - !ruby/object:Gem::Version
85
166
  version: '0'
86
167
  requirements: []
87
- rubygems_version: 3.0.4
168
+ rubygems_version: 3.0.3
88
169
  signing_key:
89
170
  specification_version: 4
90
- summary: SecureNative SDK for ruby
171
+ summary: SecureNative SDK for Ruby
91
172
  test_files: []
@@ -1,9 +0,0 @@
1
- module Config
2
- SDK_VERSION = '0.1.5'
3
- MAX_ALLOWED_PARAMS = 6
4
- API_URL_PROD = "https://api.securenative.com/collector/api/v1"
5
- API_URL_STG = "https://api.securenative-stg.com/collector/api/v1"
6
- TRACK_EVENT = "/track"
7
- VERIFY_EVENT = "/verify"
8
- FLOW_EVENT = "/flow"
9
- end
@@ -1,88 +0,0 @@
1
- require_relative 'securenative_options'
2
- require_relative 'http_client'
3
- require_relative 'sn_exception'
4
- require 'json'
5
- require 'thread'
6
-
7
- class QueueItem
8
- def initialize(url, body)
9
- @url = url
10
- @body = body
11
- end
12
-
13
- attr_reader :url
14
- attr_reader :body
15
- end
16
-
17
- class EventManager
18
- def initialize(api_key, options: SecureNativeOptions.new, http_client: HttpClient.new)
19
- if api_key == nil
20
- raise SecureNativeSDKException.new
21
- end
22
-
23
- @api_key = api_key
24
- @options = options
25
- @http_client = http_client
26
- @queue = Queue.new
27
-
28
- if @options.auto_send
29
- interval_seconds = [(@options.interval / 1000).floor, 1].max
30
- Thread.new do
31
- loop do
32
- flush
33
- sleep(interval_seconds)
34
- end
35
- end
36
- end
37
- end
38
-
39
- def send_async(event, path)
40
- q_item = QueueItem.new(build_url(path), event)
41
- @queue.push(q_item)
42
- end
43
-
44
- def send_sync(event, path)
45
- @http_client.post(
46
- build_url(path),
47
- @api_key,
48
- event.to_hash.to_json
49
- )
50
- end
51
-
52
- def flush
53
- if is_queue_full
54
- i = @options.max_events - 1
55
- while i >= 0
56
- item = @queue.pop
57
- @http_client.post(
58
- build_url(item.url),
59
- @api_key,
60
- item.body.to_hash.to_json
61
- )
62
- end
63
- else
64
- q = Array.new(@queue.size) {@queue.pop}
65
- q.each do |item|
66
- @http_client.post(
67
- build_url(item.url),
68
- @api_key,
69
- item.body
70
- )
71
- @queue = Queue.new
72
- end
73
- end
74
- end
75
-
76
- private
77
-
78
- def build_url(path)
79
- @options.api_url + path
80
- end
81
-
82
- private
83
-
84
- def is_queue_full
85
- @queue.length > @options.max_events
86
- end
87
-
88
- end
@@ -1,86 +0,0 @@
1
- require 'securerandom'
2
-
3
- class User
4
- def initialize(user_id: "", user_email: "", user_name: "")
5
- @user_id = user_id
6
- @user_email = user_email
7
- @user_name = user_name
8
- end
9
-
10
- attr_reader :user_id
11
- attr_reader :user_email
12
- attr_reader :user_name
13
- end
14
-
15
- class Event
16
- def initialize(event_type, user: User(), ip: "127.0.0.1", remote_ip: "127.0.0.1", user_agent: "unknown", sn_cookie: nil, params: nil)
17
- @event_type = event_type
18
- @user = user
19
- @ip = ip
20
- @remote_ip = remote_ip
21
- @user_agent = user_agent
22
- @cid = ""
23
- @fp = ""
24
-
25
- if params
26
- unless params.length > 0 && params[0].instance_of?(CustomParam)
27
- raise ArgumentError("custom params should be a list of CustomParams")
28
- end
29
- end
30
- @params = params
31
-
32
- if sn_cookie
33
- @cid, @cid = Utils.parse_cookie(sn_cookie)
34
- end
35
- @vid = SecureRandom.uuid
36
- @ts = Time.now.getutc.to_i
37
- end
38
-
39
- def to_hash
40
- p = Array.new
41
- if @params
42
- @params.each do |param|
43
- p << {:key => param.key, :value => param.value}
44
- end
45
- end
46
-
47
- {
48
- :eventType => @event_type,
49
- :user => {
50
- :id => @user.user_id,
51
- :email => @user.user_email,
52
- :name => @user.user_name
53
- },
54
- :remoteIP => @remote_ip,
55
- :ip => @ip,
56
- :cid => @cid,
57
- :fp => @fp,
58
- :ts => @ts,
59
- :vid => @vid,
60
- :userAgent => @user_agent,
61
- :device => Hash.new,
62
- :params => p
63
- }
64
- end
65
-
66
- attr_reader :cid
67
- attr_reader :params
68
- attr_reader :user_agent
69
- attr_reader :user
70
- attr_reader :remote_ip
71
- attr_reader :event_type
72
- attr_reader :fp
73
- attr_reader :ip
74
- attr_reader :ts
75
- attr_reader :vid
76
- end
77
-
78
- class CustomParam
79
- def initialize(key, value)
80
- @key = key
81
- @value = value
82
- end
83
-
84
- attr_reader :key
85
- attr_reader :value
86
- end
@@ -1,21 +0,0 @@
1
- module EventType
2
- LOG_IN = "sn.user.login"
3
- LOG_IN_CHALLENGE = "sn.user.login.challenge"
4
- LOG_IN_FAILURE = "sn.user.login.failure"
5
- LOG_OUT = "sn.user.logout"
6
- SIGN_UP = "sn.user.signup"
7
- AUTH_CHALLENGE = "sn.user.auth.challenge"
8
- AUTH_CHALLENGE_SUCCESS = "sn.user.auth.challenge.success"
9
- AUTH_CHALLENGE_FAILURE = "sn.user.auth.challenge.failure"
10
- TWO_FACTOR_DISABLE = "sn.user.2fa.disable"
11
- EMAIL_UPDATE = "sn.user.email.update"
12
- PASSWORD_RESET = "sn.user.password.reset"
13
- PASSWORD_RESET_SUCCESS = "sn.user.password.reset.success"
14
- PASSWORD_UPDATE = "sn.user.password.update"
15
- PASSWORD_RESET_FAILURE = "sn.user.password.reset.failure"
16
- USER_INVITE = "sn.user.invite"
17
- ROLE_UPDATE = "sn.user.role.update"
18
- PROFILE_UPDATE = "sn.user.profile.update"
19
- PAGE_VIEW = "sn.user.page.view"
20
- VERIFY = "sn.verify"
21
- end
@@ -1,20 +0,0 @@
1
- require 'httpclient'
2
-
3
- class HttpClient
4
- def initialize
5
- @client = HTTPClient.new
6
- end
7
-
8
- def headers(api_key)
9
- {
10
- "Content-Type" => 'application/json',
11
- "User-Agent" => 'SecureNative-ruby',
12
- "Sn-Version" => Config::SDK_VERSION,
13
- "Authorization" => api_key
14
- }
15
- end
16
-
17
- def post(url, api_key, body)
18
- @client.post(url, body, self.headers(api_key))
19
- end
20
- end
@@ -1,62 +0,0 @@
1
- require_relative 'event_manager'
2
- require_relative 'config'
3
- require_relative 'sn_exception'
4
- require_relative 'utils'
5
- require 'json'
6
-
7
- class SecureNativeSDK
8
- def initialize(api_key, options: SecureNativeOptions.new)
9
- if api_key == nil
10
- raise SecureNativeSDKException.new
11
- end
12
-
13
- @api_key = api_key
14
- @options = options
15
- @event_manager = EventManager.new(@api_key, options: @options)
16
- end
17
-
18
- def api_key
19
- @api_key
20
- end
21
-
22
- def version
23
- Config::SDK_VERSION
24
- end
25
-
26
- def track(event)
27
- validate_event(event)
28
- @event_manager.send_async(event, Config::TRACK_EVENT)
29
- end
30
-
31
- def verify(event)
32
- validate_event(event)
33
- res = @event_manager.send_sync(event, Config::VERIFY_EVENT)
34
- if res.status_code == 200
35
- return JSON.parse(res.body)
36
- end
37
- nil
38
- end
39
-
40
- def flow(event) # Note: For future purposes
41
- validate_event(event)
42
- @event_manager.send_async(event, Config::FLOW_EVENT)
43
- end
44
-
45
- def verify_webhook(hmac_header, body)
46
- Utils.verify_signature(@api_key, body, hmac_header)
47
- end
48
-
49
- def flush
50
- @event_manager.flush
51
- end
52
-
53
- private
54
-
55
- def validate_event(event)
56
- unless event.params.nil?
57
- if event.params.length > Config::MAX_ALLOWED_PARAMS
58
- event.params = event.params[0, Config::MAX_ALLOWED_PARAMS]
59
- end
60
- end
61
- end
62
- end