informant-rails 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/informant-rails.rb +7 -2
- data/lib/informant-rails/client.rb +13 -16
- data/lib/informant-rails/{connection_tester.rb → diagnostic.rb} +3 -3
- data/lib/informant-rails/event/base.rb +25 -0
- data/lib/informant-rails/event/client_info.rb +16 -0
- data/lib/informant-rails/{request.rb → event/form_submission.rb} +8 -8
- data/lib/informant-rails/railtie.rb +16 -11
- data/lib/informant-rails/version.rb +1 -1
- data/lib/tasks/diagnostic.rake +9 -0
- metadata +16 -8
- data/lib/tasks/test_connection.rake +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 508ce7cb53f750ba6b422a41c966b1fbdd46b623dcb311c4410d80c9b3b95f2f
|
4
|
+
data.tar.gz: 28662decb01dd5ae5b943a0f099bf68eaf3bbbfd1b6cb31172eb7d1673238b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: babd9a69b4121f59f3dae1bddc3933d33c083d2f86ad8cc95cd265b8dc7c13c795b8f6803c81764c91a0868357d27f11863bac12c9e83b55bbfbfbfb8f6f2010
|
7
|
+
data.tar.gz: ec774a339d41ba6c95f82bb37f78eb90280f4c238dcbf4b31f1a7b71abdc5c3ee05bbddeb888e99232cffdceb4a112df59de270c7963623deb130b4eb1765ed0
|
data/lib/informant-rails.rb
CHANGED
@@ -5,16 +5,21 @@ end
|
|
5
5
|
|
6
6
|
module InformantRails
|
7
7
|
autoload :Config, 'informant-rails/config'
|
8
|
-
autoload :
|
8
|
+
autoload :Diagnostic, 'informant-rails/diagnostic'
|
9
9
|
autoload :Client, 'informant-rails/client'
|
10
10
|
autoload :FieldError, 'informant-rails/field_error'
|
11
11
|
autoload :Middleware, 'informant-rails/middleware'
|
12
12
|
autoload :Model, 'informant-rails/model'
|
13
|
-
autoload :Request, 'informant-rails/request'
|
14
13
|
autoload :ParameterFilter, 'informant-rails/parameter_filter'
|
15
14
|
autoload :RequestTracking, 'informant-rails/request_tracking'
|
16
15
|
autoload :ValidationTracking, 'informant-rails/validation_tracking'
|
17
16
|
autoload :VERSION, 'informant-rails/version'
|
17
|
+
|
18
|
+
module Event
|
19
|
+
autoload :Base, 'informant-rails/event/base'
|
20
|
+
autoload :ClientInfo, 'informant-rails/event/client_info'
|
21
|
+
autoload :FormSubmission, 'informant-rails/event/form_submission'
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
require 'informant-rails/railtie'
|
@@ -3,8 +3,12 @@ require 'net/http'
|
|
3
3
|
module InformantRails
|
4
4
|
class Client
|
5
5
|
|
6
|
+
def self.supported_request_methods
|
7
|
+
@supported_request_methods ||= %w(POST PATCH PUT DELETE)
|
8
|
+
end
|
9
|
+
|
6
10
|
def self.record(env)
|
7
|
-
new_request
|
11
|
+
new_request if supported_request_methods.include?(env['REQUEST_METHOD'])
|
8
12
|
end
|
9
13
|
|
10
14
|
def self.record_action(controller_name, action)
|
@@ -35,31 +39,24 @@ module InformantRails
|
|
35
39
|
Thread.current[:informant_request] = nil
|
36
40
|
end
|
37
41
|
|
38
|
-
def self.transmit(
|
39
|
-
Net::HTTP.start(
|
40
|
-
http.request(
|
42
|
+
def self.transmit(event)
|
43
|
+
Net::HTTP.start(*event.net_http_start_arguments) do |http|
|
44
|
+
http.request(event.post_request)
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
def self.net_http_post_request(completed_request)
|
47
|
-
Net::HTTP::Post.new(api_endpoint, {
|
48
|
-
"Authorization" => ActionController::HttpAuthentication::Token.encode_credentials(Config.api_token),
|
49
|
-
"Content-Type" => "application/json"
|
50
|
-
}).tap { |r| r.body = { payload: completed_request }.to_json }
|
48
|
+
def self.log_client_info
|
49
|
+
transmit(InformantRails::Event::ClientInfo.new)
|
51
50
|
end
|
52
51
|
|
52
|
+
private
|
53
|
+
|
53
54
|
def self.include_model?(model)
|
54
55
|
!Config.exclude_models.include?(model.class.to_s)
|
55
56
|
end
|
56
57
|
|
57
58
|
def self.new_request
|
58
|
-
Thread.current[:informant_request] =
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.api_endpoint
|
62
|
-
@api_endpoint ||= URI("#{Config.collector_host}/api/v1/form_submissions")
|
59
|
+
Thread.current[:informant_request] = Event::FormSubmission.new
|
63
60
|
end
|
64
61
|
|
65
62
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module InformantRails
|
2
|
-
class
|
2
|
+
class Diagnostic
|
3
3
|
def self.run; new.run end
|
4
4
|
|
5
5
|
def run
|
6
6
|
if Config.api_token.blank?
|
7
7
|
Rails.logger.info missing_api_token_message
|
8
8
|
else
|
9
|
-
Client.record('
|
9
|
+
Client.record('REQUEST_METHOD' => 'POST')
|
10
10
|
Client.record_action('Connectivity', 'test')
|
11
11
|
Client.request.instance_variable_set('@models', [{
|
12
12
|
name: 'TestClass',
|
@@ -14,7 +14,7 @@ module InformantRails
|
|
14
14
|
}])
|
15
15
|
response = Client.transmit(Client.request)
|
16
16
|
|
17
|
-
if response.
|
17
|
+
if response.code == '204'
|
18
18
|
Rails.logger.info success_message
|
19
19
|
else
|
20
20
|
Rails.logger.info bad_response_message(response.body)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module InformantRails::Event
|
2
|
+
class Base
|
3
|
+
def self.endpoint
|
4
|
+
raise 'Must implement'
|
5
|
+
end
|
6
|
+
def endpoint; self.class.endpoint end
|
7
|
+
|
8
|
+
def self.authorization_header_value
|
9
|
+
@authorization_header_value ||= ActionController::HttpAuthentication::Token.encode_credentials(InformantRails::Config.api_token)
|
10
|
+
end
|
11
|
+
def authorization_header_value; self.class.authorization_header_value end
|
12
|
+
|
13
|
+
def post_request
|
14
|
+
Net::HTTP::Post.new(endpoint, {
|
15
|
+
"Authorization" => authorization_header_value,
|
16
|
+
"Content-Type" => "application/json"
|
17
|
+
}).tap { |r| r.body = to_json }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.net_http_start_arguments
|
21
|
+
@net_http_start_arguments ||= [endpoint.host, endpoint.port, use_ssl: endpoint.scheme == 'https']
|
22
|
+
end
|
23
|
+
def net_http_start_arguments; self.class.net_http_start_arguments end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module InformantRails::Event
|
2
|
+
class ClientInfo < Base
|
3
|
+
def as_json(*args)
|
4
|
+
{
|
5
|
+
agent_identifier: InformantRails::Config.client_identifier,
|
6
|
+
framework_version: "rails-#{Rails.version}",
|
7
|
+
runtime_version: "ruby-#{RUBY_VERSION}",
|
8
|
+
mongoid_version: defined?(Mongoid) ? Mongoid::VERSION : nil
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.endpoint
|
13
|
+
@endpoint ||= URI("#{InformantRails::Config.collector_host}/v2/client-info")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module InformantRails
|
2
|
-
class
|
1
|
+
module InformantRails::Event
|
2
|
+
class FormSubmission < Base
|
3
3
|
attr_accessor :request_url, :filename, :action
|
4
4
|
|
5
5
|
def process_model(model)
|
@@ -14,15 +14,15 @@ module InformantRails
|
|
14
14
|
|
15
15
|
def as_json(*args)
|
16
16
|
{
|
17
|
-
|
18
|
-
|
19
|
-
filename: filename,
|
20
|
-
action: action,
|
21
|
-
client: InformantRails::Config.client_identifier,
|
22
|
-
rails_version: rails_version
|
17
|
+
name: [filename, action].compact.join('#'),
|
18
|
+
models: models.map(&:as_json)
|
23
19
|
}
|
24
20
|
end
|
25
21
|
|
22
|
+
def self.endpoint
|
23
|
+
@endpoint ||= URI("#{InformantRails::Config.collector_host}/v2/form-submissions")
|
24
|
+
end
|
25
|
+
|
26
26
|
protected
|
27
27
|
|
28
28
|
def rails_version
|
@@ -3,22 +3,27 @@ module InformantRails
|
|
3
3
|
initializer 'informant' do |config|
|
4
4
|
Config.api_token ||= ENV['INFORMANT_API_KEY']
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
begin
|
7
|
+
if Config.enabled?
|
8
|
+
InformantRails::Client.log_client_info
|
9
|
+
InformantRails::Config.filter_parameters = Rails.configuration.filter_parameters
|
8
10
|
|
9
|
-
|
11
|
+
config.middleware.use InformantRails::Middleware
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
14
|
+
include InformantRails::RequestTracking
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
ActiveSupport.on_load(:active_record) do
|
18
|
+
include InformantRails::ValidationTracking
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
ActiveSupport.on_load(:mongoid) do
|
22
|
+
include InformantRails::ValidationTracking
|
23
|
+
end
|
21
24
|
end
|
25
|
+
rescue
|
26
|
+
puts "Unable to bootstrap informant."
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informant-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Informant, LLC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 7.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
29
|
+
version: 3.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 7.0.0
|
27
33
|
description: The Informant tracks what users do wrong in your forms so you can make
|
28
34
|
them better.
|
29
35
|
email:
|
@@ -38,17 +44,19 @@ files:
|
|
38
44
|
- lib/informant-rails.rb
|
39
45
|
- lib/informant-rails/client.rb
|
40
46
|
- lib/informant-rails/config.rb
|
41
|
-
- lib/informant-rails/
|
47
|
+
- lib/informant-rails/diagnostic.rb
|
48
|
+
- lib/informant-rails/event/base.rb
|
49
|
+
- lib/informant-rails/event/client_info.rb
|
50
|
+
- lib/informant-rails/event/form_submission.rb
|
42
51
|
- lib/informant-rails/field_error.rb
|
43
52
|
- lib/informant-rails/middleware.rb
|
44
53
|
- lib/informant-rails/model.rb
|
45
54
|
- lib/informant-rails/parameter_filter.rb
|
46
55
|
- lib/informant-rails/railtie.rb
|
47
|
-
- lib/informant-rails/request.rb
|
48
56
|
- lib/informant-rails/request_tracking.rb
|
49
57
|
- lib/informant-rails/validation_tracking.rb
|
50
58
|
- lib/informant-rails/version.rb
|
51
|
-
- lib/tasks/
|
59
|
+
- lib/tasks/diagnostic.rake
|
52
60
|
homepage: https://www.informantapp.com
|
53
61
|
licenses:
|
54
62
|
- MIT
|
@@ -69,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
77
|
version: '0'
|
70
78
|
requirements: []
|
71
79
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.7.8
|
73
81
|
signing_key:
|
74
82
|
specification_version: 4
|
75
83
|
summary: The Informant tracks server-side validation errors and gives you metrics
|