moesif_rack 1.3.3 → 1.3.8
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/README.md +68 -30
- data/lib/moesif_rack/app_config.rb +121 -0
- data/lib/moesif_rack/moesif_middleware.rb +38 -37
- data/test/moesif_rack_test.rb +28 -11
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7bb716388bcb7fda82c1f7cfc11530c01e9f0a9bbf6e4d84a171eae0cb75898
|
4
|
+
data.tar.gz: fb000cc8620126bc8031c678b89cd03c55bc0a32cd8c1c2889db84818261e6b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92511aab26e9a6f09d46fbdedbb2925aa0dc66cdd4537acaff8fe19d158dbbde9cc0531bd6374f544d3de448f32b8edad54d298824a9ee1ff8c0ce6687c7eb9c
|
7
|
+
data.tar.gz: 4d0e8d6ed2561a87ce9aa396a4510b66d91c186e409f44137bcaa3ef624298d1b8bf9195e62e837650ddf38e02eed07f41f91a2d18db73a973455b330903b66c
|
data/README.md
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
[![Software License][ico-license]][link-license]
|
7
7
|
[![Source Code][ico-source]][link-source]
|
8
8
|
|
9
|
-
Rack Middleware that logs
|
9
|
+
Rack Middleware that logs API calls and sends
|
10
|
+
to [Moesif](https://www.moesif.com) for API analytics and log analysis.
|
11
|
+
|
10
12
|
Supports Ruby on Rails apps and other Ruby frameworks built on Rack.
|
11
13
|
|
12
14
|
[Source Code on GitHub](https://github.com/moesif/moesif-rack)
|
@@ -20,7 +22,7 @@ gem install moesif_rack
|
|
20
22
|
and if you have a `Gemfile` in your project, please add this line to
|
21
23
|
|
22
24
|
```
|
23
|
-
gem 'moesif_rack', '~> 1.3.
|
25
|
+
gem 'moesif_rack', '~> 1.3.8'
|
24
26
|
|
25
27
|
```
|
26
28
|
|
@@ -30,19 +32,40 @@ gem 'moesif_rack', '~> 1.3.2'
|
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
moesif_options = {
|
33
|
-
'application_id' => 'Your
|
35
|
+
'application_id' => 'Your Moesif Application Id',
|
36
|
+
'log_body' => true,
|
34
37
|
}
|
35
38
|
```
|
36
39
|
|
37
|
-
|
40
|
+
Your Moesif Application Id can be found in the [_Moesif Portal_](https://www.moesif.com/).
|
41
|
+
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
|
42
|
+
|
43
|
+
You can always find your Moesif Application Id at any time by logging
|
44
|
+
into the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,
|
45
|
+
and then clicking _Installation_.
|
38
46
|
|
39
47
|
### Add to middleware
|
40
48
|
|
41
|
-
|
49
|
+
Using strings or symbols for middleware class names is deprecated for newer frameworks like Ruby 5.0,
|
50
|
+
so you should pass the class directly.
|
51
|
+
|
52
|
+
#### For Rails 5.0 or newer:
|
42
53
|
|
43
54
|
```ruby
|
55
|
+
class Application < Rails::Application
|
56
|
+
# snip
|
44
57
|
|
58
|
+
config.middleware.use MoesifRack::MoesifMiddleware, moesif_options
|
45
59
|
|
60
|
+
# snip
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
#### For other frameworks:
|
65
|
+
|
66
|
+
within `config/application.rb`
|
67
|
+
|
68
|
+
```ruby
|
46
69
|
class Application < Rails::Application
|
47
70
|
# snip
|
48
71
|
|
@@ -50,35 +73,37 @@ within `config/application.rb`
|
|
50
73
|
|
51
74
|
# snip
|
52
75
|
end
|
53
|
-
|
54
76
|
```
|
55
77
|
|
56
78
|
#### Order of Middleware Matters
|
57
79
|
|
58
|
-
Since Moesif Rack is
|
59
|
-
Many
|
60
|
-
|
61
|
-
To see the list of middlewares that your system already have, type this into the bash.
|
62
|
-
|
63
|
-
```bash
|
64
|
-
bin/rails middleware
|
65
|
-
```
|
80
|
+
Since Moesif Rack is a logging middleware, the ordering of middleware matters for accuracy and data collection.
|
81
|
+
Many middleware are installed by default by Rails.
|
66
82
|
|
67
|
-
The best place for "MoesifRack::MoesifMidleware" is on top
|
83
|
+
The best place for "MoesifRack::MoesifMidleware" is on top (so it captures the data closest to the wire).
|
68
84
|
Typically, right above the default logger of Rails apps, "Rails::Rack::Logger" is a good spot.
|
69
85
|
Or if you want to be as close as wire as possible, put it before "ActionDispatch::Static"
|
70
86
|
|
71
|
-
|
87
|
+
To insert the Moesif middleware before "Rails::Rack::Logger", you can use the `insert_before` method instead of
|
88
|
+
`use`
|
72
89
|
|
73
90
|
```ruby
|
91
|
+
class Application < Rails::Application
|
92
|
+
# snip
|
74
93
|
|
75
|
-
config.middleware.insert_before
|
94
|
+
config.middleware.insert_before Rails::Rack::Logger, MoesifRack::MoesifMiddleware, moesif_options
|
76
95
|
|
96
|
+
# snip
|
97
|
+
end
|
77
98
|
```
|
99
|
+
If you are using "Rack::Deflater" or other compression middleware, make sure Moesif is after
|
100
|
+
it, so it can capture the uncompressed data.
|
78
101
|
|
79
|
-
|
80
|
-
is below it, so it can capture uncompressed data.
|
102
|
+
To see your current list of middleware:
|
81
103
|
|
104
|
+
```bash
|
105
|
+
bin/rails middleware
|
106
|
+
```
|
82
107
|
|
83
108
|
## Configuration options
|
84
109
|
|
@@ -106,7 +131,7 @@ moesif_options['identify_user'] = Proc.new { |env, headers, body|
|
|
106
131
|
|
107
132
|
#snip
|
108
133
|
|
109
|
-
'
|
134
|
+
'my_user_id'
|
110
135
|
}
|
111
136
|
|
112
137
|
```
|
@@ -122,7 +147,7 @@ moesif_options['identify_company'] = Proc.new { |env, headers, body|
|
|
122
147
|
|
123
148
|
#snip
|
124
149
|
|
125
|
-
'
|
150
|
+
'my_company_id'
|
126
151
|
}
|
127
152
|
|
128
153
|
```
|
@@ -327,9 +352,14 @@ metadata = JSON.parse('{'\
|
|
327
352
|
'"custom": "testdata"'\
|
328
353
|
'}')
|
329
354
|
|
330
|
-
|
355
|
+
campaign_model = {"utm_source" => "Newsletter",
|
356
|
+
"utm_medium" => "Email"}
|
357
|
+
|
358
|
+
user_model = { "user_id" => "12345",
|
359
|
+
"company_id" => "67890",
|
331
360
|
"modified_time" => Time.now.utc.iso8601,
|
332
|
-
"metadata" => metadata
|
361
|
+
"metadata" => metadata,
|
362
|
+
"campaign" => campaign_model }
|
333
363
|
|
334
364
|
update_user = MoesifRack::MoesifMiddleware.new(@app, @options).update_user(user_model)
|
335
365
|
```
|
@@ -347,11 +377,13 @@ metadata = JSON.parse('{'\
|
|
347
377
|
|
348
378
|
user_models = []
|
349
379
|
|
350
|
-
user_model_A = { "user_id" => "
|
380
|
+
user_model_A = { "user_id" => "12345",
|
381
|
+
"company_id" => "67890",
|
351
382
|
"modified_time" => Time.now.utc.iso8601,
|
352
383
|
"metadata" => metadata }
|
353
384
|
|
354
|
-
user_model_B = { "user_id" => "
|
385
|
+
user_model_B = { "user_id" => "1234",
|
386
|
+
"company_id" => "6789",
|
355
387
|
"modified_time" => Time.now.utc.iso8601,
|
356
388
|
"metadata" => metadata }
|
357
389
|
|
@@ -372,9 +404,13 @@ metadata = JSON.parse('{'\
|
|
372
404
|
'"custom": "testdata"'\
|
373
405
|
'}')
|
374
406
|
|
375
|
-
|
407
|
+
campaign_model = {"utm_source" => "Adwords",
|
408
|
+
"utm_medium" => "Twitter"}
|
409
|
+
|
410
|
+
company_model = { "company_id" => "12345",
|
376
411
|
"company_domain" => "acmeinc.com",
|
377
|
-
|
412
|
+
"metadata" => metadata,
|
413
|
+
"campaign" => campaign_model }
|
378
414
|
|
379
415
|
update_company = MoesifRack::MoesifMiddleware.new(@app, @options).update_company(company_model)
|
380
416
|
```
|
@@ -392,11 +428,11 @@ metadata = JSON.parse('{'\
|
|
392
428
|
|
393
429
|
company_models = []
|
394
430
|
|
395
|
-
company_model_A = { "company_id" => "
|
431
|
+
company_model_A = { "company_id" => "12345",
|
396
432
|
"company_domain" => "nowhere.com",
|
397
433
|
"metadata" => metadata }
|
398
434
|
|
399
|
-
company_model_B = { "company_id" => "
|
435
|
+
company_model_B = { "company_id" => "67890",
|
400
436
|
"company_domain" => "acmeinc.com",
|
401
437
|
"metadata" => metadata }
|
402
438
|
|
@@ -415,7 +451,9 @@ response = MoesifRack::MoesifMiddleware.new(@app, @options).update_companies_bat
|
|
415
451
|
|
416
452
|
## Example Code
|
417
453
|
|
418
|
-
[Moesif Rack Example](https://github.com/Moesif/moesif-
|
454
|
+
[Moesif Rack Example with Rails](https://github.com/Moesif/moesif-rails-example) is an example of Moesif Rack applied to a Rails application.
|
455
|
+
|
456
|
+
[Moesif Rack Example](https://github.com/Moesif/moesif-rack-example) is an example of Moesif Rack applied to a Rack application.
|
419
457
|
|
420
458
|
## Other integrations
|
421
459
|
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'moesif_api'
|
2
|
+
require 'json'
|
3
|
+
require 'time'
|
4
|
+
require 'zlib'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class AppConfig
|
8
|
+
|
9
|
+
def get_config(api_controller, debug)
|
10
|
+
# Get Application Config
|
11
|
+
begin
|
12
|
+
config_api_response = api_controller.get_app_config()
|
13
|
+
return config_api_response
|
14
|
+
rescue MoesifApi::APIException => e
|
15
|
+
if e.response_code.between?(401, 403)
|
16
|
+
puts 'Unauthorized access getting application configuration. Please check your Appplication Id.'
|
17
|
+
end
|
18
|
+
if debug
|
19
|
+
puts 'Error getting application configuration, with status code:'
|
20
|
+
puts e.response_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_configuration(config_api_response, debug)
|
26
|
+
# Parse configuration object and return Etag, sample rate and last updated time
|
27
|
+
begin
|
28
|
+
# Rails return gzipped compressed response body, so decompressing it and getting JSON response body
|
29
|
+
response_body = decompress_gzip_body(config_api_response, debug)
|
30
|
+
|
31
|
+
# Check if response body is not nil
|
32
|
+
if !response_body.nil? then
|
33
|
+
# Return Etag, sample rate and last updated time
|
34
|
+
return config_api_response.headers[:x_moesif_config_etag], response_body.fetch("sample_rate", 100), Time.now.utc
|
35
|
+
else
|
36
|
+
if debug
|
37
|
+
puts 'Response body is nil, assuming default behavior'
|
38
|
+
end
|
39
|
+
# Response body is nil, so assuming default behavior
|
40
|
+
return nil, 100, Time.now.utc
|
41
|
+
end
|
42
|
+
rescue => exception
|
43
|
+
if debug
|
44
|
+
puts 'Error while parsing the configuration object, assuming default behavior'
|
45
|
+
puts exception.to_s
|
46
|
+
end
|
47
|
+
# Assuming default behavior
|
48
|
+
return nil, 100, Time.now.utc
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_sampling_percentage(config_api_response, user_id, company_id, debug)
|
53
|
+
# Get sampling percentage
|
54
|
+
begin
|
55
|
+
# Rails return gzipped compressed response body, so decompressing it and getting JSON response body
|
56
|
+
response_body = decompress_gzip_body(config_api_response, debug)
|
57
|
+
|
58
|
+
# Check if response body is not nil
|
59
|
+
if !response_body.nil? then
|
60
|
+
|
61
|
+
# Get user sample rate object
|
62
|
+
user_sample_rate = response_body.fetch('user_sample_rate', nil)
|
63
|
+
|
64
|
+
# Get company sample rate object
|
65
|
+
company_sample_rate = response_body.fetch('company_sample_rate', nil)
|
66
|
+
|
67
|
+
# Get sample rate for the user if exist
|
68
|
+
if !user_id.nil? && !user_sample_rate.nil? && user_sample_rate.key?(user_id)
|
69
|
+
return user_sample_rate.fetch(user_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get sample rate for the company if exist
|
73
|
+
if !company_id.nil? && !company_sample_rate.nil? && company_sample_rate.key?(company_id)
|
74
|
+
return company_sample_rate.fetch(company_id)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Return sample rate
|
78
|
+
return response_body.fetch('sample_rate', 100)
|
79
|
+
else
|
80
|
+
if debug
|
81
|
+
puts 'Assuming default behavior as response body is nil - '
|
82
|
+
end
|
83
|
+
return 100
|
84
|
+
end
|
85
|
+
rescue => exception
|
86
|
+
if debug
|
87
|
+
puts 'Error while geting sampling percentage, assuming default behavior'
|
88
|
+
end
|
89
|
+
return 100
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def decompress_gzip_body(config_api_response, debug)
|
94
|
+
# Decompress gzip response body
|
95
|
+
begin
|
96
|
+
# Check if the content-encoding header exist and is of type zip
|
97
|
+
if config_api_response.headers.key?(:content_encoding) && config_api_response.headers[:content_encoding].eql?( 'gzip' ) then
|
98
|
+
|
99
|
+
# Create a GZipReader object to read data
|
100
|
+
gzip_reader = Zlib::GzipReader.new(StringIO.new(config_api_response.raw_body.to_s))
|
101
|
+
|
102
|
+
# Read the body
|
103
|
+
uncompressed_string = gzip_reader.read
|
104
|
+
|
105
|
+
# Return the parsed body
|
106
|
+
return JSON.parse( uncompressed_string )
|
107
|
+
else
|
108
|
+
if debug
|
109
|
+
puts 'Content Encoding is of type other than gzip, returning nil'
|
110
|
+
end
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
rescue => exception
|
114
|
+
if debug
|
115
|
+
puts 'Error while decompressing the response body'
|
116
|
+
puts exception.to_s
|
117
|
+
end
|
118
|
+
return nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -3,6 +3,7 @@ require 'json'
|
|
3
3
|
require 'time'
|
4
4
|
require 'base64'
|
5
5
|
require_relative './client_ip.rb'
|
6
|
+
require_relative './app_config.rb'
|
6
7
|
require_relative './update_user.rb'
|
7
8
|
require_relative './update_company.rb'
|
8
9
|
|
@@ -12,7 +13,7 @@ module MoesifRack
|
|
12
13
|
def initialize app, options = {}
|
13
14
|
@app = app
|
14
15
|
if not options['application_id']
|
15
|
-
raise 'application_id
|
16
|
+
raise 'application_id required for Moesif Middleware'
|
16
17
|
end
|
17
18
|
@api_client = MoesifApi::MoesifAPIClient.new(options['application_id'])
|
18
19
|
@api_controller = @api_client.api
|
@@ -25,12 +26,23 @@ module MoesifRack
|
|
25
26
|
@mask_data = options['mask_data']
|
26
27
|
@skip = options['skip']
|
27
28
|
@debug = options['debug']
|
29
|
+
@app_config = AppConfig.new
|
30
|
+
@config = @app_config.get_config(@api_controller, @debug)
|
31
|
+
@config_etag = nil
|
32
|
+
@sampling_percentage = 100
|
33
|
+
@last_updated_time = Time.now.utc
|
28
34
|
@config_dict = Hash.new
|
29
35
|
@disable_transaction_id = options['disable_transaction_id'] || false
|
30
36
|
@log_body = options.fetch('log_body', true)
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
begin
|
38
|
+
if !@config.nil?
|
39
|
+
@config_etag, @sampling_percentage, @last_updated_time = @app_config.parse_configuration(@config, @debug)
|
40
|
+
end
|
41
|
+
rescue => exception
|
42
|
+
if @debug
|
43
|
+
puts 'Error while parsing application configuration on initialization'
|
44
|
+
puts exception.to_s
|
45
|
+
end
|
34
46
|
end
|
35
47
|
@capture_outoing_requests = options['capture_outoing_requests']
|
36
48
|
if @capture_outoing_requests
|
@@ -42,35 +54,6 @@ module MoesifRack
|
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
|
-
def get_config(cached_config_etag)
|
46
|
-
sample_rate = 100
|
47
|
-
begin
|
48
|
-
# Calling the api
|
49
|
-
config_api_response = @api_controller.get_app_config()
|
50
|
-
# Fetch the response ETag
|
51
|
-
response_config_etag = JSON.parse( config_api_response.to_json )["headers"]["x_moesif_config_etag"]
|
52
|
-
# Remove ETag from the global dict if exist
|
53
|
-
if !cached_config_etag.nil? && @config_dict.key?(cached_config_etag)
|
54
|
-
@config_dict.delete(cached_config_etag)
|
55
|
-
end
|
56
|
-
# Fetch the response body
|
57
|
-
@config_dict[response_config_etag] = JSON.parse(JSON.parse( config_api_response.to_json )["raw_body"])
|
58
|
-
#
|
59
|
-
app_config = @config_dict[response_config_etag]
|
60
|
-
# Fetch the sample rate
|
61
|
-
if !app_config.nil?
|
62
|
-
sample_rate = app_config.fetch("sample_rate", 100)
|
63
|
-
end
|
64
|
-
# Set the last updated time
|
65
|
-
@last_updated_time = Time.now.utc
|
66
|
-
rescue
|
67
|
-
# Set the last updated time
|
68
|
-
@last_updated_time = Time.now.utc
|
69
|
-
end
|
70
|
-
# Return the sample rate
|
71
|
-
return sample_rate
|
72
|
-
end
|
73
|
-
|
74
57
|
def update_user(user_profile)
|
75
58
|
UserHelper.new.update_user(@api_controller, @debug, user_profile)
|
76
59
|
end
|
@@ -236,13 +219,31 @@ module MoesifRack
|
|
236
219
|
# Perform the API call through the SDK function
|
237
220
|
begin
|
238
221
|
@random_percentage = Random.rand(0.00..100.00)
|
222
|
+
|
223
|
+
begin
|
224
|
+
@sampling_percentage = @app_config.get_sampling_percentage(@config, event_model.user_id, event_model.company_id, @debug)
|
225
|
+
rescue => exception
|
226
|
+
if @debug
|
227
|
+
puts 'Error while getting sampling percentage, assuming default behavior'
|
228
|
+
puts exception.to_s
|
229
|
+
end
|
230
|
+
@sampling_percentage = 100
|
231
|
+
end
|
232
|
+
|
239
233
|
if @sampling_percentage > @random_percentage
|
240
234
|
event_api_response = @api_controller.create_event(event_model)
|
241
|
-
cached_config_etag = @config_dict.keys[0]
|
242
235
|
event_response_config_etag = event_api_response[:x_moesif_config_etag]
|
243
236
|
|
244
|
-
if !event_response_config_etag.nil? &&
|
245
|
-
|
237
|
+
if !event_response_config_etag.nil? && !@config_etag.nil? && @config_etag != event_response_config_etag && Time.now.utc > @last_updated_time + 300
|
238
|
+
begin
|
239
|
+
@config = @app_config.get_config(@api_controller, @debug)
|
240
|
+
@config_etag, @sampling_percentage, @last_updated_time = @app_config.parse_configuration(@config, @debug)
|
241
|
+
rescue => exception
|
242
|
+
if @debug
|
243
|
+
puts 'Error while updating the application configuration'
|
244
|
+
puts exception.to_s
|
245
|
+
end
|
246
|
+
end
|
246
247
|
end
|
247
248
|
if @debug
|
248
249
|
puts("Event successfully sent to Moesif")
|
@@ -285,7 +286,7 @@ module MoesifRack
|
|
285
286
|
|
286
287
|
def get_response_body(response)
|
287
288
|
body = response.respond_to?(:body) ? response.body : response
|
288
|
-
body = body.inject("") { |i, a| i << a } if body.respond_to?(:each)
|
289
|
+
body = body.inject("") { |i, a| i << a } if (body.respond_to?(:each) && body.respond_to?(:inject))
|
289
290
|
body.to_s
|
290
291
|
end
|
291
292
|
|
data/test/moesif_rack_test.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rack'
|
3
3
|
require 'net/http'
|
4
|
+
require_relative '../lib/moesif_rack/app_config.rb'
|
4
5
|
require_relative '../lib/moesif_rack'
|
5
6
|
|
6
7
|
class MoesifRackTest < Test::Unit::TestCase
|
7
8
|
def setup
|
8
9
|
@app = ->(env) { [200, { "Content-Type" => "application/json" }, ["{ \"key\": \"value\"}"]]}
|
9
|
-
@options = { 'application_id' => 'Your Application Id',
|
10
|
+
@options = { 'application_id' => 'Your Moesif Application Id',
|
10
11
|
'debug' => true,
|
11
12
|
'disable_transaction_id' => true,
|
12
13
|
'capture_outoing_requests' => true,
|
@@ -26,7 +27,7 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
26
27
|
'my_user_id'
|
27
28
|
},
|
28
29
|
'identify_company' => Proc.new{|request, response|
|
29
|
-
'
|
30
|
+
'my_company_id'
|
30
31
|
},
|
31
32
|
'identify_user_outgoing' => Proc.new{|request, response|
|
32
33
|
'outgoing_user_id'
|
@@ -45,6 +46,7 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
45
46
|
}
|
46
47
|
}
|
47
48
|
@moesif_rack_app = MoesifRack::MoesifMiddleware.new(@app, @options)
|
49
|
+
@app_config = AppConfig.new
|
48
50
|
end
|
49
51
|
|
50
52
|
def test_capture_outgoing
|
@@ -67,9 +69,14 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
67
69
|
'"custom": "testdata"'\
|
68
70
|
'}')
|
69
71
|
|
70
|
-
|
72
|
+
campaign_model = {"utm_source" => "Newsletter",
|
73
|
+
"utm_medium" => "Email"}
|
74
|
+
|
75
|
+
user_model = { "user_id" => "12345",
|
76
|
+
"company_id" => "67890",
|
71
77
|
"modified_time" => Time.now.utc.iso8601,
|
72
|
-
"metadata" => metadata
|
78
|
+
"metadata" => metadata,
|
79
|
+
"campaign" => campaign_model}
|
73
80
|
|
74
81
|
response = @moesif_rack_app.update_user(user_model)
|
75
82
|
assert_equal response, nil
|
@@ -84,11 +91,13 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
84
91
|
|
85
92
|
user_models = []
|
86
93
|
|
87
|
-
user_model_A = { "user_id" => "
|
94
|
+
user_model_A = { "user_id" => "12345",
|
95
|
+
"company_id" => "67890",
|
88
96
|
"modified_time" => Time.now.utc.iso8601,
|
89
97
|
"metadata" => metadata }
|
90
98
|
|
91
|
-
user_model_B = { "user_id" => "
|
99
|
+
user_model_B = { "user_id" => "1234",
|
100
|
+
"company_id" => "6789",
|
92
101
|
"modified_time" => Time.now.utc.iso8601,
|
93
102
|
"metadata" => metadata }
|
94
103
|
|
@@ -103,7 +112,11 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
103
112
|
end
|
104
113
|
|
105
114
|
def test_get_config
|
106
|
-
|
115
|
+
@api_client = MoesifApi::MoesifAPIClient.new(@options['application_id'])
|
116
|
+
@api_controller = @api_client.api
|
117
|
+
@config = @app_config.get_config(@api_controller, @debug)
|
118
|
+
@config_etag, @sampling_percentage, @last_updated_time = @app_config.parse_configuration(@config, @debug)
|
119
|
+
assert_operator 100, :>=, @sampling_percentage
|
107
120
|
end
|
108
121
|
|
109
122
|
def test_update_company
|
@@ -113,9 +126,13 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
113
126
|
'"custom": "testdata"'\
|
114
127
|
'}')
|
115
128
|
|
116
|
-
|
129
|
+
campaign_model = {"utm_source" => "Adwords",
|
130
|
+
"utm_medium" => "Twitter"}
|
131
|
+
|
132
|
+
company_model = { "company_id" => "12345",
|
117
133
|
"company_domain" => "acmeinc.com",
|
118
|
-
|
134
|
+
"metadata" => metadata,
|
135
|
+
"campaign" => campaign_model }
|
119
136
|
|
120
137
|
response = @moesif_rack_app.update_company(company_model)
|
121
138
|
assert_equal response, nil
|
@@ -130,11 +147,11 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
130
147
|
|
131
148
|
company_models = []
|
132
149
|
|
133
|
-
company_model_A = { "company_id" => "
|
150
|
+
company_model_A = { "company_id" => "12345",
|
134
151
|
"company_domain" => "nowhere.com",
|
135
152
|
"metadata" => metadata }
|
136
153
|
|
137
|
-
company_model_B = { "company_id" => "
|
154
|
+
company_model_B = { "company_id" => "1234",
|
138
155
|
"company_domain" => "acmeinc.com",
|
139
156
|
"metadata" => metadata }
|
140
157
|
|
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.8
|
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
|
+
date: 2019-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.2.
|
34
|
+
version: 1.2.9
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.2.
|
41
|
+
version: 1.2.9
|
42
42
|
description: Collection/Data Ingestion SDK for Rack (also Rails) Middleware / RoR
|
43
43
|
email: xing@moesif.com
|
44
44
|
executables: []
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- lib/moesif_rack.rb
|
51
|
+
- lib/moesif_rack/app_config.rb
|
51
52
|
- lib/moesif_rack/client_ip.rb
|
52
53
|
- lib/moesif_rack/moesif_middleware.rb
|
53
54
|
- lib/moesif_rack/update_company.rb
|