moesif_rack 1.3.9 → 1.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +173 -110
- data/lib/moesif_rack/moesif_middleware.rb +2 -1
- data/test/moesif_rack_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5449e55b2da865cdc2bd4d52eef977b45db5a3e7648ee18f67f93795bf1fcd46
|
4
|
+
data.tar.gz: 930c9fb3a9181eec3b12d5aea8073c12646f94f77d16638dfa0422107b8000f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13012b377dac7ca5da3dcaf1d50ef97e71f6515df9e7f94e61b39746b4f29b134efcbc87eaafcb8dcd04dd67e0e052d8f0c5e9c77dd6ea20a7d997f50df3feb6
|
7
|
+
data.tar.gz: d7499b20fa602a2dd1bde29099b5b11755f36421f79c32f59fc1e1aa7f0e1dce7794b7ed1ca703c74ff07f040492b3ecc12f038eb3f52625348b13ae9becb2ec
|
data/README.md
CHANGED
@@ -126,12 +126,10 @@ Optional.
|
|
126
126
|
identify_user is a Proc that takes env, headers, and body as arguments and returns a user_id string. This helps us attribute requests to unique users. Even though Moesif can automatically retrieve the user_id without this, this is highly recommended to ensure accurate attribution.
|
127
127
|
|
128
128
|
```ruby
|
129
|
-
|
130
129
|
moesif_options['identify_user'] = Proc.new { |env, headers, body|
|
131
130
|
|
132
|
-
#
|
133
|
-
|
134
|
-
'my_user_id'
|
131
|
+
# Add your custom code that returns a string for user id
|
132
|
+
'12345'
|
135
133
|
}
|
136
134
|
|
137
135
|
```
|
@@ -145,13 +143,24 @@ identify_company is a Proc that takes env, headers, and body as arguments and re
|
|
145
143
|
|
146
144
|
moesif_options['identify_company'] = Proc.new { |env, headers, body|
|
147
145
|
|
148
|
-
#
|
149
|
-
|
150
|
-
'my_company_id'
|
146
|
+
# Add your custom code that returns a string for company id
|
147
|
+
'67890'
|
151
148
|
}
|
152
149
|
|
153
150
|
```
|
154
151
|
|
152
|
+
#### __`identify_session`__
|
153
|
+
|
154
|
+
Optional. A Proc that takes env, headers, body and returns a string.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
|
158
|
+
moesif_options['identify_session'] = Proc.new { |env, headers, body|
|
159
|
+
# Add your custom code that returns a string for session/API token
|
160
|
+
'XXXXXXXXX'
|
161
|
+
}
|
162
|
+
```
|
163
|
+
|
155
164
|
#### __`get_metadata`__
|
156
165
|
|
157
166
|
Optional.
|
@@ -162,31 +171,15 @@ metadata to this event.
|
|
162
171
|
```ruby
|
163
172
|
|
164
173
|
moesif_options['get_metadata'] = Proc.new { |env, headers, body|
|
165
|
-
|
166
|
-
#snip
|
174
|
+
# Add your custom code that returns a dictionary
|
167
175
|
value = {
|
168
|
-
'
|
169
|
-
'
|
176
|
+
'datacenter' => 'westus',
|
177
|
+
'deployment_version' => 'v1.2.3'
|
170
178
|
}
|
171
|
-
|
172
179
|
value
|
173
180
|
}
|
174
181
|
```
|
175
182
|
|
176
|
-
#### __`identify_session`__
|
177
|
-
|
178
|
-
Optional. A Proc that takes env, headers, body and returns a string.
|
179
|
-
|
180
|
-
```ruby
|
181
|
-
|
182
|
-
moesif_options['identify_session'] = Proc.new { |env, headers, body|
|
183
|
-
|
184
|
-
#snip
|
185
|
-
|
186
|
-
'the_session_token'
|
187
|
-
}
|
188
|
-
|
189
|
-
```
|
190
183
|
|
191
184
|
#### __`mask_data`__
|
192
185
|
|
@@ -196,9 +189,8 @@ With mask_data, you can make modifications to headers or body of the event befor
|
|
196
189
|
```ruby
|
197
190
|
|
198
191
|
moesif_options['mask_data'] = Proc.new { |event_model|
|
199
|
-
|
200
|
-
|
201
|
-
|
192
|
+
# Add your custom code that returns a event_model after modifying any fields
|
193
|
+
event_model.response.body.password = nil
|
202
194
|
event_model
|
203
195
|
}
|
204
196
|
|
@@ -213,9 +205,7 @@ Optional. A Proc that takes env, headers, body and returns a boolean.
|
|
213
205
|
```ruby
|
214
206
|
|
215
207
|
moesif_options['skip'] = Proc.new { |env, headers, body|
|
216
|
-
|
217
|
-
#snip
|
218
|
-
|
208
|
+
# Add your custom code that returns true to skip logging the API call
|
219
209
|
false
|
220
210
|
}
|
221
211
|
|
@@ -232,7 +222,7 @@ Optional. Boolean. Default false. If true, it will print out debug messages. In
|
|
232
222
|
|
233
223
|
Optional. Boolean. Default true. If false, will not log request and response body to Moesif.
|
234
224
|
|
235
|
-
#### __`
|
225
|
+
#### __`capture_outgoing_requests`__
|
236
226
|
Optional. boolean, Default `false`. Set to `true` to capture all outgoing API calls from your app to third parties like Stripe, Github or to your own dependencies while using [Net::HTTP](https://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html) package. The options below is applied to outgoing API calls. When the request is outgoing, for options functions that take request and response as input arguments, the request and response objects passed in are [Request](https://www.rubydoc.info/stdlib/net/Net/HTTPRequest) request and [Response](https://www.rubydoc.info/stdlib/net/Net/HTTPResponse) response objects.
|
237
227
|
|
238
228
|
|
@@ -245,9 +235,8 @@ identify_user_outgoing is a Proc that takes request and response as arguments an
|
|
245
235
|
|
246
236
|
moesif_options['identify_user_outgoing'] = Proc.new { |request, response|
|
247
237
|
|
248
|
-
#
|
249
|
-
|
250
|
-
'the_user_id'
|
238
|
+
# Add your custom code that returns a string for user id
|
239
|
+
'12345'
|
251
240
|
}
|
252
241
|
|
253
242
|
```
|
@@ -261,9 +250,8 @@ identify_company_outgoing is a Proc that takes request and response as arguments
|
|
261
250
|
|
262
251
|
moesif_options['identify_company_outgoing'] = Proc.new { |request, response|
|
263
252
|
|
264
|
-
#
|
265
|
-
|
266
|
-
'the_company_id'
|
253
|
+
# Add your custom code that returns a string for company id
|
254
|
+
'67890'
|
267
255
|
}
|
268
256
|
|
269
257
|
```
|
@@ -279,12 +267,11 @@ metadata to this event.
|
|
279
267
|
|
280
268
|
moesif_options['get_metadata_outgoing'] = Proc.new { |request, response|
|
281
269
|
|
282
|
-
#
|
270
|
+
# Add your custom code that returns a dictionary
|
283
271
|
value = {
|
284
|
-
'
|
285
|
-
'
|
272
|
+
'datacenter' => 'westus',
|
273
|
+
'deployment_version' => 'v1.2.3'
|
286
274
|
}
|
287
|
-
|
288
275
|
value
|
289
276
|
}
|
290
277
|
```
|
@@ -297,9 +284,8 @@ Optional. A Proc that takes request, response and returns a string.
|
|
297
284
|
|
298
285
|
moesif_options['identify_session_outgoing'] = Proc.new { |request, response|
|
299
286
|
|
300
|
-
|
301
|
-
|
302
|
-
'the_session_token'
|
287
|
+
# Add your custom code that returns a string for session/API token
|
288
|
+
'XXXXXXXXX'
|
303
289
|
}
|
304
290
|
|
305
291
|
```
|
@@ -312,8 +298,7 @@ Optional. A Proc that takes request, response and returns a boolean. If `true` w
|
|
312
298
|
|
313
299
|
moesif_options['skip_outgoing'] = Proc.new{ |request, response|
|
314
300
|
|
315
|
-
#
|
316
|
-
|
301
|
+
# Add your custom code that returns true to skip logging the API call
|
317
302
|
false
|
318
303
|
}
|
319
304
|
|
@@ -328,8 +313,8 @@ With mask_data_outgoing, you can make modifications to headers or body of the ev
|
|
328
313
|
|
329
314
|
moesif_options['mask_data_outgoing'] = Proc.new { |event_model|
|
330
315
|
|
331
|
-
#
|
332
|
-
|
316
|
+
# Add your custom code that returns a event_model after modifying any fields
|
317
|
+
event_model.response.body.password = nil
|
333
318
|
event_model
|
334
319
|
}
|
335
320
|
|
@@ -341,32 +326,51 @@ Optional. Boolean. Default true. If false, will not log request and response bod
|
|
341
326
|
|
342
327
|
## Update User
|
343
328
|
|
344
|
-
###
|
345
|
-
|
346
|
-
The metadata field can be any
|
329
|
+
### Update a Single User
|
330
|
+
Create or update a user profile in Moesif.
|
331
|
+
The metadata field can be any customer demographic or other info you want to store.
|
332
|
+
Only the `user_id` field is required.
|
333
|
+
This method is a convenient helper that calls the Moesif API lib.
|
334
|
+
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-a-user).
|
347
335
|
|
348
336
|
```ruby
|
349
|
-
metadata
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
337
|
+
metadata => {
|
338
|
+
:email => 'john@acmeinc.com',
|
339
|
+
:first_name => 'John',
|
340
|
+
:last_name => 'Doe',
|
341
|
+
:title => 'Software Engineer',
|
342
|
+
:salesInfo => {
|
343
|
+
:stage => 'Customer',
|
344
|
+
:lifetime_value => 24000,
|
345
|
+
:accountOwner => 'mary@contoso.com',
|
346
|
+
}
|
347
|
+
}
|
357
348
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
349
|
+
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
|
350
|
+
# See https://www.moesif.com/docs/api#users for campaign schema
|
351
|
+
campaign = CampaignModel.new()
|
352
|
+
campaign.utm_source = "google"
|
353
|
+
campaign.utm_medium = "cpc"
|
354
|
+
campaign.utm_campaign = "adwords"
|
355
|
+
campaign.utm_term = "api+tooling"
|
356
|
+
campaign.utm_content = "landing"
|
357
|
+
|
358
|
+
# Only user_id is required.
|
359
|
+
# metadata can be any custom object
|
360
|
+
user = UserModel.new()
|
361
|
+
user.user_id = "12345"
|
362
|
+
user.company_id = "67890" # If set, associate user with a company object
|
363
|
+
user.campaign = campaign
|
364
|
+
user.metadata = metadata
|
363
365
|
|
364
366
|
update_user = MoesifRack::MoesifMiddleware.new(@app, @options).update_user(user_model)
|
365
367
|
```
|
366
368
|
|
367
|
-
###
|
368
|
-
|
369
|
-
|
369
|
+
### Update Users in Batch
|
370
|
+
Similar to update_user, but used to update a list of users in one batch.
|
371
|
+
Only the `user_id` field is required.
|
372
|
+
This method is a convenient helper that calls the Moesif API lib.
|
373
|
+
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-users-in-batch).
|
370
374
|
|
371
375
|
```ruby
|
372
376
|
metadata = JSON.parse('{'\
|
@@ -375,49 +379,88 @@ metadata = JSON.parse('{'\
|
|
375
379
|
'"custom": "testdata"'\
|
376
380
|
'}')
|
377
381
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
382
|
+
users = []
|
383
|
+
|
384
|
+
metadata => {
|
385
|
+
:email => 'john@acmeinc.com',
|
386
|
+
:first_name => 'John',
|
387
|
+
:last_name => 'Doe',
|
388
|
+
:title => 'Software Engineer',
|
389
|
+
:salesInfo => {
|
390
|
+
:stage => 'Customer',
|
391
|
+
:lifetime_value => 24000,
|
392
|
+
:accountOwner => 'mary@contoso.com',
|
393
|
+
}
|
394
|
+
}
|
389
395
|
|
390
|
-
|
391
|
-
|
396
|
+
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
|
397
|
+
# See https://www.moesif.com/docs/api#users for campaign schema
|
398
|
+
campaign = CampaignModel.new()
|
399
|
+
campaign.utm_source = "google"
|
400
|
+
campaign.utm_medium = "cpc"
|
401
|
+
campaign.utm_campaign = "adwords"
|
402
|
+
campaign.utm_term = "api+tooling"
|
403
|
+
campaign.utm_content = "landing"
|
404
|
+
|
405
|
+
# Only user_id is required.
|
406
|
+
# metadata can be any custom object
|
407
|
+
user = UserModel.new()
|
408
|
+
user.user_id = "12345"
|
409
|
+
user.company_id = "67890" # If set, associate user with a company object
|
410
|
+
user.campaign = campaign
|
411
|
+
user.metadata = metadata
|
412
|
+
|
413
|
+
users << user
|
414
|
+
|
415
|
+
response = MoesifRack::MoesifMiddleware.new(@app, @options).update_users_batch(users)
|
392
416
|
```
|
393
417
|
|
394
418
|
## Update Company
|
395
419
|
|
396
|
-
###
|
397
|
-
|
398
|
-
The metadata field can be any
|
420
|
+
### Update a Single Company
|
421
|
+
Create or update a company profile in Moesif.
|
422
|
+
The metadata field can be any company demographic or other info you want to store.
|
423
|
+
Only the `company_id` field is required.
|
424
|
+
This method is a convenient helper that calls the Moesif API lib.
|
425
|
+
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-a-company).
|
399
426
|
|
400
427
|
```ruby
|
401
|
-
metadata
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
428
|
+
metadata => {
|
429
|
+
:org_name => 'Acme, Inc',
|
430
|
+
:plan_name => 'Free',
|
431
|
+
:deal_stage => 'Lead',
|
432
|
+
:mrr => 24000,
|
433
|
+
:demographics => {
|
434
|
+
:alexa_ranking => 500000,
|
435
|
+
:employee_count => 47
|
436
|
+
}
|
437
|
+
}
|
409
438
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
439
|
+
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
|
440
|
+
# See https://www.moesif.com/docs/api#update-a-company for campaign schema
|
441
|
+
campaign = CampaignModel.new()
|
442
|
+
campaign.utm_source = "google"
|
443
|
+
campaign.utm_medium = "cpc"
|
444
|
+
campaign.utm_campaign = "adwords"
|
445
|
+
campaign.utm_term = "api+tooling"
|
446
|
+
campaign.utm_content = "landing"
|
447
|
+
|
448
|
+
# Only company_id is required.
|
449
|
+
# metadata can be any custom object
|
450
|
+
company = CompanyModel.new()
|
451
|
+
company.company_id = "67890"
|
452
|
+
company.company_domain = "acmeinc.com" # If domain is set, Moesif will enrich your profiles with publicly available info
|
453
|
+
company.campaign = campaign
|
454
|
+
company.metadata = metadata
|
414
455
|
|
415
456
|
update_company = MoesifRack::MoesifMiddleware.new(@app, @options).update_company(company_model)
|
416
457
|
```
|
417
458
|
|
418
|
-
###
|
419
|
-
|
420
|
-
|
459
|
+
### Update Companies in Batch
|
460
|
+
Similar to update_company, but used to update a list of companies in one batch.
|
461
|
+
Only the `company_id` field is required.
|
462
|
+
This method is a convenient helper that calls the Moesif API lib.
|
463
|
+
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-companies-in-batch).
|
421
464
|
|
422
465
|
```ruby
|
423
466
|
metadata = JSON.parse('{'\
|
@@ -426,18 +469,38 @@ metadata = JSON.parse('{'\
|
|
426
469
|
'"custom": "testdata"'\
|
427
470
|
'}')
|
428
471
|
|
429
|
-
|
472
|
+
companies = []
|
430
473
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
474
|
+
metadata => {
|
475
|
+
:org_name => 'Acme, Inc',
|
476
|
+
:plan_name => 'Free',
|
477
|
+
:deal_stage => 'Lead',
|
478
|
+
:mrr => 24000,
|
479
|
+
:demographics => {
|
480
|
+
:alexa_ranking => 500000,
|
481
|
+
:employee_count => 47
|
482
|
+
}
|
483
|
+
}
|
438
484
|
|
439
|
-
|
440
|
-
|
485
|
+
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
|
486
|
+
# See https://www.moesif.com/docs/api#update-a-company for campaign schema
|
487
|
+
campaign = CampaignModel.new()
|
488
|
+
campaign.utm_source = "google"
|
489
|
+
campaign.utm_medium = "cpc"
|
490
|
+
campaign.utm_campaign = "adwords"
|
491
|
+
campaign.utm_term = "api+tooling"
|
492
|
+
campaign.utm_content = "landing"
|
493
|
+
|
494
|
+
# Only company_id is required.
|
495
|
+
# metadata can be any custom object
|
496
|
+
company = CompanyModel.new()
|
497
|
+
company.company_id = "67890"
|
498
|
+
company.company_domain = "acmeinc.com" # If domain is set, Moesif will enrich your profiles with publicly available info
|
499
|
+
company.campaign = campaign
|
500
|
+
company.metadata = metadata
|
501
|
+
|
502
|
+
companies << company
|
503
|
+
response = MoesifRack::MoesifMiddleware.new(@app, @options).update_companies_batch(companies)
|
441
504
|
```
|
442
505
|
|
443
506
|
## How to test
|
@@ -45,7 +45,8 @@ module MoesifRack
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
@capture_outoing_requests = options['capture_outoing_requests']
|
48
|
-
|
48
|
+
@capture_outgoing_requests = options['capture_outgoing_requests']
|
49
|
+
if @capture_outoing_requests || @capture_outgoing_requests
|
49
50
|
if @debug
|
50
51
|
puts 'Start Capturing outgoing requests'
|
51
52
|
end
|
data/test/moesif_rack_test.rb
CHANGED
@@ -10,7 +10,7 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
10
10
|
@options = { 'application_id' => 'Your Moesif Application Id',
|
11
11
|
'debug' => true,
|
12
12
|
'disable_transaction_id' => true,
|
13
|
-
'
|
13
|
+
'capture_outgoing_requests' => true,
|
14
14
|
'get_metadata' => Proc.new {|request, response|
|
15
15
|
{
|
16
16
|
'foo' => 'abc',
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moesif_rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moesif, Inc
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-12-
|
12
|
+
date: 2019-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|