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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a65828c53957be32307a98b3b0d54e8faaa0c23
4
- data.tar.gz: 014728da192e78d784c737dcd9b17bf067eecab0
3
+ metadata.gz: 5995154e25aa6d876e155c33a55da4604f2f7757
4
+ data.tar.gz: fc7097388c33fd8a607e2deca10ffe7d769fe9c5
5
5
  SHA512:
6
- metadata.gz: 4df17ef313a87bc1a7f66bf25c2d5486fc94e4980eee851a2171ea3087c30731b4dac1b7b69a53a7c13c51b6c22b3a2363ccb8459d3a58e4150beb7d0d27d180
7
- data.tar.gz: 70366afc5e6eb6c236afb3576f1f826dba2e5445727119bf40cd3b443b530b1d7f33220c6b0b3ab45a8ef6048dce8c68c76e6410e45fef43a209247fb3cca374
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 is tested against Ruby 1.9.3, 2.0.0, and Rubinius.
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
- Typhoeus::Request.new(
27
- api_url,
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
- remove_request
29
+ cleanup
38
30
  end
39
31
 
40
32
  def self.request
41
- @requests[request_id]
33
+ Thread.current[:informant_request]
42
34
  end
43
35
 
44
- private
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.new_request
51
- @requests[request_id] = Request.new
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
- def self.remove_request
55
- @requests.delete(request_id)
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.request_id
59
- Thread.current.object_id
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 InformantRails::Config.api_token.blank?
6
+ if Config.api_token.blank?
7
7
  Rails.logger.info missing_api_token_message
8
8
  else
9
- InformantRails::Client.record('HTTP_REFERER' => '/connectivity/test')
10
- InformantRails::Client.record_action('Connectivity', 'test')
11
- InformantRails::Client.request.instance_variable_set('@models', [{
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 = InformantRails::Client.process
15
+ response = Client.transmit(Client.request)
16
16
 
17
17
  if response.success?
18
18
  Rails.logger.info success_message
@@ -1,9 +1,9 @@
1
1
  module InformantRails
2
2
  class Middleware < Struct.new(:app)
3
3
  def call(env)
4
- InformantRails::Client.record(env)
4
+ Client.record(env)
5
5
  response = app.call(env)
6
- InformantRails::Client.process
6
+ Client.process
7
7
  response
8
8
  end
9
9
  end
@@ -1,32 +1,24 @@
1
1
  module InformantRails
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer 'informant middleware' do |config|
4
- if InformantRails::Config.api_token
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
- if InformantRails::Config.api_token
11
- ActiveSupport.on_load :action_controller do
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
- if InformantRails::Config.api_token
21
-
22
- ActiveSupport.on_load(:active_record) do
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
@@ -1,3 +1,3 @@
1
1
  module InformantRails
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  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.5.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-06 00:00:00.000000000 Z
12
+ date: 2014-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails