informant-rails 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +54 -2
- data/lib/informant-rails/client.rb +24 -23
- data/lib/informant-rails/connection_tester.rb +5 -5
- data/lib/informant-rails/middleware.rb +2 -2
- data/lib/informant-rails/railtie.rb +10 -18
- data/lib/informant-rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5995154e25aa6d876e155c33a55da4604f2f7757
|
4
|
+
data.tar.gz: fc7097388c33fd8a607e2deca10ffe7d769fe9c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a01db40601239898b1b9999f73ec0ee16fa1d1833b64ffded4d6bd4a4bd1666e843ef4424c951b6494936320e6603e96090f52fb80c33b3d50f5b91b76b06e2
|
7
|
+
data.tar.gz: fc63088ae0632869acfd095ff2654d215fca6c2eda610468314937b53c0341c2ae0e97f40b941e9df4e061c0f17ee27ff248e9c4c5c7615b3ec6dd49bb86a99c
|
data/README.markdown
CHANGED
@@ -8,7 +8,13 @@ The informant-rails gem provides Rails and ActiveRecord hooks for The Informant.
|
|
8
8
|
|
9
9
|
## Compatibility
|
10
10
|
|
11
|
-
The informant-rails gem
|
11
|
+
The informant-rails gem supports the following versions of Ruby:
|
12
|
+
- 1.9.x
|
13
|
+
- 2.x
|
14
|
+
- rubinius
|
15
|
+
- jruby
|
16
|
+
|
17
|
+
It will work automatically with Rails 3.x / 4.x and Mongoid 3.x / 4.x.
|
12
18
|
|
13
19
|
[![Build Status](https://travis-ci.org/informantapp/informant-rails.svg?branch=master)](https://travis-ci.org/informantapp/informant-rails)
|
14
20
|
[![Code Climate](https://codeclimate.com/github/informantapp/informant-rails.png)](https://codeclimate.com/github/informantapp/informant-rails)
|
@@ -23,4 +29,50 @@ gem 'informant-rails', group: :production
|
|
23
29
|
|
24
30
|
## Usage
|
25
31
|
|
26
|
-
By default, any request that causes an ActiveRecord model to be validated will be tracked by the Informant once the gem is added to your project.
|
32
|
+
By default, any request that causes an ActiveRecord or Mongoid model to be validated will be tracked by the Informant once the gem is added to your project.
|
33
|
+
|
34
|
+
### Tracking Other Validations
|
35
|
+
|
36
|
+
If you have other objects that conform to the ActiveModel interface, you can include validation tracking in your class and it will just work.
|
37
|
+
|
38
|
+
```
|
39
|
+
class VeryActiveModel
|
40
|
+
include InformantRails::ValidationTracking
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
Configuration options are specified in the `InformantRails::Config` module. Reasonable defaults are provided but you can override them as necessary by creating an initializer and passing a block to `configure`.
|
47
|
+
|
48
|
+
```
|
49
|
+
InformantRails::Config.configure do |config|
|
50
|
+
config.api_token = ENV['INFORMANT_API_KEY']
|
51
|
+
config.exclude_models = %w(UntrackedModel)
|
52
|
+
config.filter_parameters.push *%w(password password_confirmation)
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
### api_token
|
57
|
+
|
58
|
+
Default Value: `ENV['INFORMANT_API_KEY']`
|
59
|
+
|
60
|
+
Example Value: `dff67d9e61eaa8cf110b3d3f3238a671`
|
61
|
+
|
62
|
+
This should be set to the API key assigned to you when you provisioned your application. Heroku will automatically add this to your environment when you provision the addon. Otherwise, you can get this from the Informant web application.
|
63
|
+
|
64
|
+
### exclude_models
|
65
|
+
|
66
|
+
Default Value: `[]`
|
67
|
+
|
68
|
+
Default Value: `['Person', 'Employee']`
|
69
|
+
|
70
|
+
This allows you to exclude certain models from tracking. If you don't want them to be included, just list their class names as strings.
|
71
|
+
|
72
|
+
### filter_parameters
|
73
|
+
|
74
|
+
Default Value: `Rails.configuration.filter_parameters`
|
75
|
+
|
76
|
+
Example Value: `['password', 'password_confirmation']`
|
77
|
+
|
78
|
+
Any field names specified here will not be included in value tracking. Any sensitive information that you wouldn't want to include in your server log should be listed here as well.
|
@@ -2,10 +2,9 @@ require 'typhoeus'
|
|
2
2
|
|
3
3
|
module InformantRails
|
4
4
|
class Client
|
5
|
-
@requests = {}
|
6
5
|
|
7
6
|
def self.record(env)
|
8
|
-
unless env['REQUEST_METHOD'] == 'GET'
|
7
|
+
unless Config.api_token.blank? || env['REQUEST_METHOD'] == 'GET'
|
9
8
|
new_request.request_url = env['HTTP_REFERER']
|
10
9
|
end
|
11
10
|
end
|
@@ -23,44 +22,46 @@ module InformantRails
|
|
23
22
|
|
24
23
|
def self.process
|
25
24
|
if request && request.models.any?
|
26
|
-
|
27
|
-
|
28
|
-
method: :post,
|
29
|
-
body: { payload: request }.to_json,
|
30
|
-
headers: {
|
31
|
-
"Authorization" => ActionController::HttpAuthentication::Token.encode_credentials(InformantRails::Config.api_token),
|
32
|
-
"Content-Type" => "application/json"
|
33
|
-
}
|
34
|
-
).run
|
25
|
+
this_request = request
|
26
|
+
Thread.new { transmit(this_request) }
|
35
27
|
end
|
36
28
|
ensure
|
37
|
-
|
29
|
+
cleanup
|
38
30
|
end
|
39
31
|
|
40
32
|
def self.request
|
41
|
-
|
33
|
+
Thread.current[:informant_request]
|
42
34
|
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
def self.include_model?(model)
|
47
|
-
!InformantRails::Config.exclude_models.include?(model.class.to_s)
|
36
|
+
def self.cleanup
|
37
|
+
Thread.current[:informant_request] = nil
|
48
38
|
end
|
49
39
|
|
50
|
-
def self.
|
51
|
-
|
40
|
+
def self.transmit(completed_request)
|
41
|
+
Typhoeus::Request.new(
|
42
|
+
api_url,
|
43
|
+
method: :post,
|
44
|
+
body: { payload: completed_request }.to_json,
|
45
|
+
headers: {
|
46
|
+
"Authorization" => ActionController::HttpAuthentication::Token.encode_credentials(Config.api_token),
|
47
|
+
"Content-Type" => "application/json"
|
48
|
+
}
|
49
|
+
).run
|
52
50
|
end
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
private
|
53
|
+
|
54
|
+
def self.include_model?(model)
|
55
|
+
!Config.exclude_models.include?(model.class.to_s)
|
56
56
|
end
|
57
57
|
|
58
|
-
def self.
|
59
|
-
Thread.current.
|
58
|
+
def self.new_request
|
59
|
+
Thread.current[:informant_request] = Request.new
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.api_url
|
63
63
|
@api_url ||= 'https://api.informantapp.com/api/v1/form_submissions'
|
64
64
|
end
|
65
|
+
|
65
66
|
end
|
66
67
|
end
|
@@ -3,16 +3,16 @@ module InformantRails
|
|
3
3
|
def self.run; new.run end
|
4
4
|
|
5
5
|
def run
|
6
|
-
if
|
6
|
+
if Config.api_token.blank?
|
7
7
|
Rails.logger.info missing_api_token_message
|
8
8
|
else
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Client.record('HTTP_REFERER' => '/connectivity/test')
|
10
|
+
Client.record_action('Connectivity', 'test')
|
11
|
+
Client.request.instance_variable_set('@models', [{
|
12
12
|
name: 'TestClass',
|
13
13
|
errors: [name: 'field_name', value: 'field_value', message: 'must be unique']
|
14
14
|
}])
|
15
|
-
response =
|
15
|
+
response = Client.transmit(Client.request)
|
16
16
|
|
17
17
|
if response.success?
|
18
18
|
Rails.logger.info success_message
|
@@ -1,32 +1,24 @@
|
|
1
1
|
module InformantRails
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer 'informant middleware' do |config|
|
4
|
-
|
5
|
-
config.middleware.use 'InformantRails::Middleware'
|
6
|
-
end
|
4
|
+
config.middleware.use 'InformantRails::Middleware'
|
7
5
|
end
|
8
6
|
|
9
7
|
initializer 'informant ActionController binding' do
|
10
|
-
|
11
|
-
|
12
|
-
include InformantRails::RequestTracking
|
13
|
-
end
|
14
|
-
|
15
|
-
InformantRails::Config.filter_parameters = Rails.configuration.filter_parameters
|
8
|
+
ActiveSupport.on_load :action_controller do
|
9
|
+
include InformantRails::RequestTracking
|
16
10
|
end
|
11
|
+
|
12
|
+
InformantRails::Config.filter_parameters = Rails.configuration.filter_parameters
|
17
13
|
end
|
18
14
|
|
19
15
|
initializer 'informant ActiveRecord binding' do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
include InformantRails::ValidationTracking
|
24
|
-
end
|
25
|
-
|
26
|
-
ActiveSupport.on_load(:mongoid) do
|
27
|
-
include InformantRails::ValidationTracking
|
28
|
-
end
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
17
|
+
include InformantRails::ValidationTracking
|
18
|
+
end
|
29
19
|
|
20
|
+
ActiveSupport.on_load(:mongoid) do
|
21
|
+
include InformantRails::ValidationTracking
|
30
22
|
end
|
31
23
|
end
|
32
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informant-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Elliott
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|