securenative 0.1.18 → 0.1.24
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/Gemfile +1 -2
- data/Gemfile.lock +80 -81
- data/README.md +46 -41
- data/lib/securenative/api_manager.rb +41 -0
- data/lib/securenative/config/configuration_builder.rb +29 -0
- data/lib/securenative/config/configuration_manager.rb +58 -0
- data/lib/securenative/config/securenative_options.rb +25 -0
- data/lib/securenative/context/hanami_context.rb +44 -0
- data/lib/securenative/context/rails_context.rb +46 -0
- data/lib/securenative/context/securenative_context.rb +69 -0
- data/lib/securenative/context/sinatra_context.rb +44 -0
- data/lib/securenative/enums/api_route.rb +8 -0
- data/lib/securenative/enums/event_types.rb +25 -0
- data/lib/securenative/enums/failover_strategy.rb +8 -0
- data/lib/securenative/enums/risk_level.rb +9 -0
- data/lib/securenative/errors/securenative_config_error.rb +6 -0
- data/lib/securenative/errors/securenative_http_error.rb +6 -0
- data/lib/securenative/errors/securenative_invalid_options_error.rb +6 -0
- data/lib/securenative/errors/securenative_invalid_uri_error.rb +6 -0
- data/lib/securenative/errors/securenative_parse_error.rb +6 -0
- data/lib/securenative/errors/securenative_sdk_Illegal_state_error.rb +6 -0
- data/lib/securenative/errors/securenative_sdk_error.rb +6 -0
- data/lib/securenative/event_manager.rb +159 -0
- data/lib/securenative/http/secure_native_http_response.rb +14 -0
- data/lib/securenative/http/securenative_http_client.rb +52 -0
- data/lib/securenative/models/client_token.rb +14 -0
- data/lib/securenative/models/device.rb +12 -0
- data/lib/securenative/models/event_options.rb +39 -0
- data/lib/securenative/models/request_context.rb +20 -0
- data/lib/securenative/models/request_options.rb +14 -0
- data/lib/securenative/models/sdk_event.rb +51 -0
- data/lib/securenative/models/user_traits.rb +15 -0
- data/lib/securenative/models/verify_result.rb +18 -0
- data/lib/securenative/sdk.rb +85 -0
- data/lib/securenative/utils/date_utils.rb +11 -0
- data/lib/securenative/utils/encryption_utils.rb +51 -0
- data/lib/securenative/utils/ip_utils.rb +25 -0
- data/lib/securenative/utils/request_utils.rb +71 -0
- data/lib/securenative/utils/secure_native_logger.rb +46 -0
- data/lib/securenative/utils/signature_utils.rb +18 -0
- data/lib/securenative/utils/utils.rb +11 -0
- data/lib/securenative/utils/version_utils.rb +13 -0
- data/out/production/securenative-ruby/api_manager.rb +13 -5
- data/out/production/securenative-ruby/config/configuration_builder.rb +6 -9
- data/out/production/securenative-ruby/config/configuration_manager.rb +24 -23
- data/out/production/securenative-ruby/config/securenative_options.rb +8 -5
- data/{lib → out/production/securenative-ruby}/context/hanami_context.rb +9 -2
- data/{lib → out/production/securenative-ruby}/context/rails_context.rb +4 -1
- data/out/production/securenative-ruby/context/securenative_context.rb +35 -8
- data/{lib → out/production/securenative-ruby}/context/sinatra_context.rb +11 -4
- data/out/production/securenative-ruby/event_manager.rb +15 -14
- data/{lib → out/production/securenative-ruby}/http/secure_native_http_response.rb +0 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +23 -5
- data/out/production/securenative-ruby/models/event_options.rb +23 -1
- data/out/production/securenative-ruby/models/request_context.rb +2 -2
- data/out/production/securenative-ruby/models/sdk_event.rb +22 -6
- data/out/production/securenative-ruby/models/user_traits.rb +1 -1
- data/out/production/securenative-ruby/models/verify_result.rb +5 -1
- data/out/production/securenative-ruby/securenative.rb +2 -10
- data/out/production/securenative-ruby/utils/date_utils.rb +1 -1
- data/out/production/securenative-ruby/utils/encryption_utils.rb +38 -24
- data/out/production/securenative-ruby/utils/request_utils.rb +53 -7
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +6 -6
- data/out/production/securenative-ruby/utils/version_utils.rb +5 -6
- data/out/test/securenative-ruby/spec_api_manager.rb +37 -31
- data/out/test/securenative-ruby/spec_context_builder.rb +52 -34
- data/out/test/securenative-ruby/spec_encryption_utils.rb +13 -13
- data/out/test/securenative-ruby/spec_event_manager.rb +49 -15
- data/out/test/securenative-ruby/spec_helper.rb +8 -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 +35 -39
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +13 -5
- data/out/test/securenative-ruby/spec_signature_utils.rb +1 -1
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +16 -14
- metadata +48 -45
- data/VERSION +0 -1
- data/lib/api_manager.rb +0 -35
- data/lib/config/configuration_builder.rb +0 -30
- data/lib/config/configuration_manager.rb +0 -55
- data/lib/config/securenative_options.rb +0 -22
- data/lib/context/securenative_context.rb +0 -67
- data/lib/enums/api_route.rb +0 -6
- data/lib/enums/event_types.rb +0 -23
- data/lib/enums/failover_strategy.rb +0 -6
- data/lib/enums/risk_level.rb +0 -7
- data/lib/errors/securenative_config_error.rb +0 -4
- data/lib/errors/securenative_http_error.rb +0 -4
- data/lib/errors/securenative_invalid_options_error.rb +0 -4
- data/lib/errors/securenative_invalid_uri_error.rb +0 -4
- data/lib/errors/securenative_parse_error.rb +0 -4
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/lib/errors/securenative_sdk_error.rb +0 -4
- data/lib/event_manager.rb +0 -156
- data/lib/event_options.rb +0 -32
- data/lib/http/securenative_http_client.rb +0 -32
- data/lib/models/client_token.rb +0 -12
- data/lib/models/device.rb +0 -10
- data/lib/models/event_options.rb +0 -15
- data/lib/models/request_context.rb +0 -18
- data/lib/models/request_options.rb +0 -12
- data/lib/models/sdk_event.rb +0 -35
- data/lib/models/user_traits.rb +0 -13
- data/lib/models/verify_result.rb +0 -12
- data/lib/securenative.rb +0 -95
- data/lib/utils/date_utils.rb +0 -9
- data/lib/utils/encryption_utils.rb +0 -35
- data/lib/utils/ip_utils.rb +0 -23
- data/lib/utils/request_utils.rb +0 -54
- data/lib/utils/secure_native_logger.rb +0 -44
- data/lib/utils/signature_utils.rb +0 -16
- data/lib/utils/utils.rb +0 -9
- data/lib/utils/version_utils.rb +0 -12
- data/out/production/securenative-ruby/event_options.rb +0 -32
- data/out/production/securenative-ruby/http/http_response.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d106e0702046e45250d4005ee93dc1baa17d5fa31cf393f3993a5667e3d14703
|
4
|
+
data.tar.gz: caba785bb61b1c517d98669d59f9ef1ae6e357f49ef2dbfbd6f41eeb0c96f0da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab405d8068d865533569350a378853d5b864ad3933f7d394c8fb81e3d08365bfffff6f1fdf9bd5da6e8ca25adb9355ca1cd473ce68aed723318fa86171834d9c
|
7
|
+
data.tar.gz: 2b0f71f461ac6c9ec58f9c7d3cc75ac6cde418ee70da7f2df73102e56ddf4a3a0d22d883f124efe95e807c2cd07ba969f860561eccc8d460a45e775aab324bf0
|
data/Gemfile
CHANGED
@@ -3,9 +3,8 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
gem "rspec"
|
5
5
|
gem "rake"
|
6
|
-
gem "httpclient"
|
7
|
-
gem "parseconfig"
|
8
6
|
gem "simplecov", :require => false, :group => :test
|
7
|
+
gem "codecov", :require => false, :group => :test
|
9
8
|
gem "webmock", :require => false, :group => :test
|
10
9
|
gem "rails", :require => false, :group => :test
|
11
10
|
gem "hanami", :require => false, :group => :test
|
data/Gemfile.lock
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
securenative (0.1.
|
4
|
+
securenative (0.1.24)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actioncable (6.0.3.
|
10
|
-
actionpack (= 6.0.3.
|
9
|
+
actioncable (6.0.3.3)
|
10
|
+
actionpack (= 6.0.3.3)
|
11
11
|
nio4r (~> 2.0)
|
12
12
|
websocket-driver (>= 0.6.1)
|
13
|
-
actionmailbox (6.0.3.
|
14
|
-
actionpack (= 6.0.3.
|
15
|
-
activejob (= 6.0.3.
|
16
|
-
activerecord (= 6.0.3.
|
17
|
-
activestorage (= 6.0.3.
|
18
|
-
activesupport (= 6.0.3.
|
13
|
+
actionmailbox (6.0.3.3)
|
14
|
+
actionpack (= 6.0.3.3)
|
15
|
+
activejob (= 6.0.3.3)
|
16
|
+
activerecord (= 6.0.3.3)
|
17
|
+
activestorage (= 6.0.3.3)
|
18
|
+
activesupport (= 6.0.3.3)
|
19
19
|
mail (>= 2.7.1)
|
20
|
-
actionmailer (6.0.3.
|
21
|
-
actionpack (= 6.0.3.
|
22
|
-
actionview (= 6.0.3.
|
23
|
-
activejob (= 6.0.3.
|
20
|
+
actionmailer (6.0.3.3)
|
21
|
+
actionpack (= 6.0.3.3)
|
22
|
+
actionview (= 6.0.3.3)
|
23
|
+
activejob (= 6.0.3.3)
|
24
24
|
mail (~> 2.5, >= 2.5.4)
|
25
25
|
rails-dom-testing (~> 2.0)
|
26
|
-
actionpack (6.0.3.
|
27
|
-
actionview (= 6.0.3.
|
28
|
-
activesupport (= 6.0.3.
|
26
|
+
actionpack (6.0.3.3)
|
27
|
+
actionview (= 6.0.3.3)
|
28
|
+
activesupport (= 6.0.3.3)
|
29
29
|
rack (~> 2.0, >= 2.0.8)
|
30
30
|
rack-test (>= 0.6.3)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
33
|
-
actiontext (6.0.3.
|
34
|
-
actionpack (= 6.0.3.
|
35
|
-
activerecord (= 6.0.3.
|
36
|
-
activestorage (= 6.0.3.
|
37
|
-
activesupport (= 6.0.3.
|
33
|
+
actiontext (6.0.3.3)
|
34
|
+
actionpack (= 6.0.3.3)
|
35
|
+
activerecord (= 6.0.3.3)
|
36
|
+
activestorage (= 6.0.3.3)
|
37
|
+
activesupport (= 6.0.3.3)
|
38
38
|
nokogiri (>= 1.8.5)
|
39
|
-
actionview (6.0.3.
|
40
|
-
activesupport (= 6.0.3.
|
39
|
+
actionview (6.0.3.3)
|
40
|
+
activesupport (= 6.0.3.3)
|
41
41
|
builder (~> 3.1)
|
42
42
|
erubi (~> 1.4)
|
43
43
|
rails-dom-testing (~> 2.0)
|
44
44
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
45
|
-
activejob (6.0.3.
|
46
|
-
activesupport (= 6.0.3.
|
45
|
+
activejob (6.0.3.3)
|
46
|
+
activesupport (= 6.0.3.3)
|
47
47
|
globalid (>= 0.3.6)
|
48
|
-
activemodel (6.0.3.
|
49
|
-
activesupport (= 6.0.3.
|
50
|
-
activerecord (6.0.3.
|
51
|
-
activemodel (= 6.0.3.
|
52
|
-
activesupport (= 6.0.3.
|
53
|
-
activestorage (6.0.3.
|
54
|
-
actionpack (= 6.0.3.
|
55
|
-
activejob (= 6.0.3.
|
56
|
-
activerecord (= 6.0.3.
|
48
|
+
activemodel (6.0.3.3)
|
49
|
+
activesupport (= 6.0.3.3)
|
50
|
+
activerecord (6.0.3.3)
|
51
|
+
activemodel (= 6.0.3.3)
|
52
|
+
activesupport (= 6.0.3.3)
|
53
|
+
activestorage (6.0.3.3)
|
54
|
+
actionpack (= 6.0.3.3)
|
55
|
+
activejob (= 6.0.3.3)
|
56
|
+
activerecord (= 6.0.3.3)
|
57
57
|
marcel (~> 0.3.1)
|
58
|
-
activesupport (6.0.3.
|
58
|
+
activesupport (6.0.3.3)
|
59
59
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
60
60
|
i18n (>= 0.7, < 2)
|
61
61
|
minitest (~> 5.1)
|
@@ -64,11 +64,13 @@ GEM
|
|
64
64
|
addressable (2.7.0)
|
65
65
|
public_suffix (>= 2.0.2, < 5.0)
|
66
66
|
builder (3.2.4)
|
67
|
+
codecov (0.2.11)
|
68
|
+
json
|
69
|
+
simplecov
|
67
70
|
concurrent-ruby (1.1.7)
|
68
|
-
crack (0.4.
|
69
|
-
safe_yaml (~> 1.0.0)
|
71
|
+
crack (0.4.4)
|
70
72
|
crass (1.0.6)
|
71
|
-
diff-lcs (1.
|
73
|
+
diff-lcs (1.4.4)
|
72
74
|
docile (1.3.2)
|
73
75
|
dry-configurable (0.11.6)
|
74
76
|
concurrent-ruby (~> 1.0)
|
@@ -148,11 +150,11 @@ GEM
|
|
148
150
|
http_router (0.11.2)
|
149
151
|
rack (>= 1.0.0)
|
150
152
|
url_mount (~> 0.2.1)
|
151
|
-
httpclient (2.8.3)
|
152
153
|
i18n (1.8.5)
|
153
154
|
concurrent-ruby (~> 1.0)
|
154
155
|
inflecto (0.0.2)
|
155
|
-
|
156
|
+
json (2.3.1)
|
157
|
+
loofah (2.7.0)
|
156
158
|
crass (~> 1.0.2)
|
157
159
|
nokogiri (>= 1.5.9)
|
158
160
|
mail (2.7.1)
|
@@ -163,74 +165,72 @@ GEM
|
|
163
165
|
mimemagic (0.3.5)
|
164
166
|
mini_mime (1.0.2)
|
165
167
|
mini_portile2 (2.4.0)
|
166
|
-
minitest (5.14.
|
168
|
+
minitest (5.14.2)
|
167
169
|
mustermann (1.1.1)
|
168
170
|
ruby2_keywords (~> 0.0.1)
|
169
|
-
nio4r (2.5.
|
171
|
+
nio4r (2.5.4)
|
170
172
|
nokogiri (1.10.10)
|
171
173
|
mini_portile2 (~> 2.4.0)
|
172
|
-
|
173
|
-
public_suffix (4.0.5)
|
174
|
+
public_suffix (4.0.6)
|
174
175
|
rack (2.2.3)
|
175
|
-
rack-protection (2.0
|
176
|
+
rack-protection (2.1.0)
|
176
177
|
rack
|
177
178
|
rack-test (1.1.0)
|
178
179
|
rack (>= 1.0, < 3)
|
179
|
-
rails (6.0.3.
|
180
|
-
actioncable (= 6.0.3.
|
181
|
-
actionmailbox (= 6.0.3.
|
182
|
-
actionmailer (= 6.0.3.
|
183
|
-
actionpack (= 6.0.3.
|
184
|
-
actiontext (= 6.0.3.
|
185
|
-
actionview (= 6.0.3.
|
186
|
-
activejob (= 6.0.3.
|
187
|
-
activemodel (= 6.0.3.
|
188
|
-
activerecord (= 6.0.3.
|
189
|
-
activestorage (= 6.0.3.
|
190
|
-
activesupport (= 6.0.3.
|
180
|
+
rails (6.0.3.3)
|
181
|
+
actioncable (= 6.0.3.3)
|
182
|
+
actionmailbox (= 6.0.3.3)
|
183
|
+
actionmailer (= 6.0.3.3)
|
184
|
+
actionpack (= 6.0.3.3)
|
185
|
+
actiontext (= 6.0.3.3)
|
186
|
+
actionview (= 6.0.3.3)
|
187
|
+
activejob (= 6.0.3.3)
|
188
|
+
activemodel (= 6.0.3.3)
|
189
|
+
activerecord (= 6.0.3.3)
|
190
|
+
activestorage (= 6.0.3.3)
|
191
|
+
activesupport (= 6.0.3.3)
|
191
192
|
bundler (>= 1.3.0)
|
192
|
-
railties (= 6.0.3.
|
193
|
+
railties (= 6.0.3.3)
|
193
194
|
sprockets-rails (>= 2.0.0)
|
194
195
|
rails-dom-testing (2.0.3)
|
195
196
|
activesupport (>= 4.2.0)
|
196
197
|
nokogiri (>= 1.6)
|
197
198
|
rails-html-sanitizer (1.3.0)
|
198
199
|
loofah (~> 2.3)
|
199
|
-
railties (6.0.3.
|
200
|
-
actionpack (= 6.0.3.
|
201
|
-
activesupport (= 6.0.3.
|
200
|
+
railties (6.0.3.3)
|
201
|
+
actionpack (= 6.0.3.3)
|
202
|
+
activesupport (= 6.0.3.3)
|
202
203
|
method_source
|
203
204
|
rake (>= 0.8.7)
|
204
205
|
thor (>= 0.20.3, < 2.0)
|
205
206
|
rake (13.0.1)
|
206
|
-
rspec (3.
|
207
|
-
rspec-core (~> 3.
|
208
|
-
rspec-expectations (~> 3.
|
209
|
-
rspec-mocks (~> 3.
|
210
|
-
rspec-core (3.
|
211
|
-
rspec-support (~> 3.
|
212
|
-
rspec-expectations (3.
|
207
|
+
rspec (3.9.0)
|
208
|
+
rspec-core (~> 3.9.0)
|
209
|
+
rspec-expectations (~> 3.9.0)
|
210
|
+
rspec-mocks (~> 3.9.0)
|
211
|
+
rspec-core (3.9.2)
|
212
|
+
rspec-support (~> 3.9.3)
|
213
|
+
rspec-expectations (3.9.2)
|
213
214
|
diff-lcs (>= 1.2.0, < 2.0)
|
214
|
-
rspec-support (~> 3.
|
215
|
-
rspec-mocks (3.
|
215
|
+
rspec-support (~> 3.9.0)
|
216
|
+
rspec-mocks (3.9.1)
|
216
217
|
diff-lcs (>= 1.2.0, < 2.0)
|
217
|
-
rspec-support (~> 3.
|
218
|
-
rspec-support (3.
|
218
|
+
rspec-support (~> 3.9.0)
|
219
|
+
rspec-support (3.9.3)
|
219
220
|
ruby2_keywords (0.0.2)
|
220
|
-
safe_yaml (1.0.5)
|
221
221
|
simplecov (0.19.0)
|
222
222
|
docile (~> 1.1)
|
223
223
|
simplecov-html (~> 0.11)
|
224
|
-
simplecov-html (0.12.
|
225
|
-
sinatra (2.0
|
224
|
+
simplecov-html (0.12.3)
|
225
|
+
sinatra (2.1.0)
|
226
226
|
mustermann (~> 1.0)
|
227
|
-
rack (~> 2.
|
228
|
-
rack-protection (= 2.0
|
227
|
+
rack (~> 2.2)
|
228
|
+
rack-protection (= 2.1.0)
|
229
229
|
tilt (~> 2.0)
|
230
230
|
sprockets (4.0.2)
|
231
231
|
concurrent-ruby (~> 1.0)
|
232
232
|
rack (> 1, < 3)
|
233
|
-
sprockets-rails (3.2.
|
233
|
+
sprockets-rails (3.2.2)
|
234
234
|
actionpack (>= 4.0)
|
235
235
|
activesupport (>= 4.0)
|
236
236
|
sprockets (>= 3.0.0)
|
@@ -242,7 +242,7 @@ GEM
|
|
242
242
|
thread_safe (~> 0.1)
|
243
243
|
url_mount (0.2.1)
|
244
244
|
rack
|
245
|
-
webmock (3.
|
245
|
+
webmock (3.9.1)
|
246
246
|
addressable (>= 2.3.6)
|
247
247
|
crack (>= 0.3.2)
|
248
248
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -256,9 +256,8 @@ PLATFORMS
|
|
256
256
|
|
257
257
|
DEPENDENCIES
|
258
258
|
bundler (~> 2.0)
|
259
|
+
codecov
|
259
260
|
hanami
|
260
|
-
httpclient
|
261
|
-
parseconfig
|
262
261
|
rails
|
263
262
|
rake
|
264
263
|
rspec
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ gem 'securenative'
|
|
36
36
|
|
37
37
|
Then execute:
|
38
38
|
|
39
|
-
$ bundle
|
39
|
+
$ bundle install
|
40
40
|
|
41
41
|
Or install it yourself as:
|
42
42
|
|
@@ -47,38 +47,39 @@ Or install it yourself as:
|
|
47
47
|
To get your *API KEY*, login to your SecureNative account and go to project settings page:
|
48
48
|
|
49
49
|
### Option 1: Initialize via Config file
|
50
|
-
SecureNative can automatically load your config from *securenative.
|
50
|
+
SecureNative can automatically load your config from *securenative.yml* file or from the file that is specified in your *SECURENATIVE_CONFIG_FILE* env variable:
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
require 'securenative'
|
53
|
+
require 'securenative/securenative'
|
54
54
|
|
55
55
|
|
56
|
-
secureative = SecureNative.init
|
56
|
+
secureative = SecureNative::SecureNative.init
|
57
57
|
```
|
58
58
|
### Option 2: Initialize via API Key
|
59
59
|
|
60
60
|
```ruby
|
61
|
-
require 'securenative'
|
61
|
+
require 'securenative/sdk'
|
62
62
|
|
63
63
|
|
64
|
-
securenative = SecureNative.init_with_api_key('YOUR_API_KEY')
|
64
|
+
securenative = SecureNative::SecureNative.init_with_api_key('YOUR_API_KEY')
|
65
65
|
```
|
66
66
|
|
67
67
|
### Option 3: Initialize via ConfigurationBuilder
|
68
68
|
```ruby
|
69
|
-
require 'securenative'
|
69
|
+
require 'securenative/sdk'
|
70
70
|
|
71
71
|
|
72
|
-
|
72
|
+
options = SecureNative::ConfigurationBuilder.new(api_key: 'API_KEY', max_events: 10, log_level: 'ERROR')
|
73
|
+
SecureNative::SecureNative.init_with_options(options)
|
73
74
|
```
|
74
75
|
|
75
76
|
## Getting SecureNative instance
|
76
77
|
Once initialized, sdk will create a singleton instance which you can get:
|
77
78
|
```ruby
|
78
|
-
require 'securenative'
|
79
|
+
require 'securenative/sdk'
|
79
80
|
|
80
81
|
|
81
|
-
secureNative = SecureNative.instance
|
82
|
+
secureNative = SecureNative::SecureNative.instance
|
82
83
|
```
|
83
84
|
|
84
85
|
## Tracking events
|
@@ -87,43 +88,47 @@ Once the SDK has been initialized, tracking requests sent through the SDK
|
|
87
88
|
instance. Make sure you build event with the EventBuilder:
|
88
89
|
|
89
90
|
```ruby
|
90
|
-
require 'securenative'
|
91
|
+
require 'securenative/sdk'
|
92
|
+
require 'securenative/models/event_options'
|
91
93
|
require 'securenative/enums/event_types'
|
92
|
-
require 'securenative/event_options_builder'
|
93
94
|
require 'securenative/models/user_traits'
|
94
|
-
require 'securenative/context/context_builder'
|
95
95
|
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
context =
|
100
|
-
|
101
|
-
|
102
|
-
event_options = EventOptions(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
securenative.track(event_options)
|
97
|
+
def track
|
98
|
+
securenative = SecureNative::SecureNative.instance
|
99
|
+
context = SecureNative::SecureNativeContext.new(client_token: 'SECURED_CLIENT_TOKEN', ip: '127.0.0.1',
|
100
|
+
headers: { 'user-agent' => 'Mozilla: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.3 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/43.4' })
|
101
|
+
|
102
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
103
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
104
|
+
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
105
|
+
|
106
|
+
securenative.track(event_options)
|
107
|
+
|
108
|
+
@message = 'tracked'
|
109
|
+
end
|
107
110
|
```
|
108
111
|
|
109
|
-
You can also create request context from requests:
|
112
|
+
You can also create request securenative.context from requests:
|
110
113
|
|
111
114
|
```ruby
|
112
|
-
require 'securenative'
|
115
|
+
require 'securenative/sdk'
|
116
|
+
require 'securenative/models/event_options'
|
113
117
|
require 'securenative/enums/event_types'
|
114
|
-
require 'securenative/event_options_builder'
|
115
118
|
require 'securenative/models/user_traits'
|
116
119
|
|
117
120
|
|
118
121
|
def track(request)
|
119
|
-
securenative = SecureNative.instance
|
120
|
-
context = SecureNative.
|
121
|
-
|
122
|
-
event_options = EventOptions(
|
123
|
-
|
124
|
-
|
122
|
+
securenative = SecureNative::SecureNative.instance
|
123
|
+
context = SecureNative::SecureNativeContext.from_http_request(request)
|
124
|
+
|
125
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
126
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
127
|
+
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
125
128
|
|
126
129
|
securenative.track(event_options)
|
130
|
+
|
131
|
+
@message = 'tracked'
|
127
132
|
end
|
128
133
|
```
|
129
134
|
|
@@ -132,19 +137,19 @@ end
|
|
132
137
|
**Example**
|
133
138
|
|
134
139
|
```ruby
|
135
|
-
require 'securenative'
|
140
|
+
require 'securenative/sdk'
|
141
|
+
require 'securenative/models/event_options'
|
136
142
|
require 'securenative/enums/event_types'
|
137
|
-
require 'securenative/event_options_builder'
|
138
143
|
require 'securenative/models/user_traits'
|
139
144
|
|
140
145
|
|
141
146
|
def verify(request)
|
142
|
-
securenative = SecureNative.instance
|
143
|
-
context = SecureNative.
|
147
|
+
securenative = SecureNative::SecureNative.instance
|
148
|
+
context = SecureNative::SecureNativeContext.from_http_request(request)
|
144
149
|
|
145
|
-
event_options = EventOptions(
|
146
|
-
|
147
|
-
|
150
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
151
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
152
|
+
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
148
153
|
|
149
154
|
verify_result = securenative.verify(event_options)
|
150
155
|
verify_result.risk_level # Low, Medium, High
|
@@ -158,11 +163,11 @@ end
|
|
158
163
|
Apply our filter to verify the request is from us, for example:
|
159
164
|
|
160
165
|
```ruby
|
161
|
-
require 'securenative'
|
166
|
+
require 'securenative/sdk'
|
162
167
|
|
163
168
|
|
164
169
|
def webhook_endpoint(request)
|
165
|
-
securenative = SecureNative.instance
|
170
|
+
securenative = SecureNative::SecureNative.instance
|
166
171
|
|
167
172
|
# Checks if request is verified
|
168
173
|
is_verified = securenative.verify_request_payload(request)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securenative/models/sdk_event'
|
4
|
+
require 'securenative/enums/failover_strategy'
|
5
|
+
require 'securenative/enums/risk_level'
|
6
|
+
require 'securenative/enums/api_route'
|
7
|
+
require 'securenative/models/verify_result'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
module SecureNative
|
11
|
+
class ApiManager
|
12
|
+
def initialize(event_manager, securenative_options)
|
13
|
+
@event_manager = event_manager
|
14
|
+
@options = securenative_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def track(event_options)
|
18
|
+
SecureNativeLogger.debug('Track event call')
|
19
|
+
event = SDKEvent.new(event_options, @options)
|
20
|
+
@event_manager.send_async(event, ApiRoute::TRACK)
|
21
|
+
end
|
22
|
+
|
23
|
+
def verify(event_options)
|
24
|
+
SecureNativeLogger.debug('Verify event call')
|
25
|
+
event = SDKEvent.new(event_options, @options)
|
26
|
+
|
27
|
+
begin
|
28
|
+
res = @event_manager.send_sync(event, ApiRoute::VERIFY, false)
|
29
|
+
ver_result = JSON.parse(res.body)
|
30
|
+
return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
|
31
|
+
rescue StandardError => e
|
32
|
+
SecureNativeLogger.debug("Failed to call verify; #{e}")
|
33
|
+
end
|
34
|
+
if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
|
35
|
+
return VerifyResult.new(risk_level: RiskLevel::LOW, score: 0, triggers: nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
VerifyResult.new(risk_level: RiskLevel::HIGH, score: 1, triggers: nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|