informant-rails 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0dde7f5500ee63c025d17548c609e542d21f5bea
4
+ data.tar.gz: 75e97a3d342e00fba823613865363a6a61e2fa08
5
+ SHA512:
6
+ metadata.gz: 63689617d74d35ebe8ad8e6e1b2d89e0fd7b6b6433df875bee63457b9191b11d1f02faad5e0467470d6805e85c689c0fd32fe4408f1bded9517ba12c700e30f5
7
+ data.tar.gz: 1c4e66104ba92696dd6c8965693895168e9e327297d73d23ebf683fa254394f2e2bd4581b51f27c949b4a50033b64da06fd824d61d7b2e1667eaffe4ecef42ea
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Copyright 2013 The Informant
data/README.markdown ADDED
@@ -0,0 +1,14 @@
1
+ # Overview
2
+
3
+ ## Informant Rails
4
+
5
+ The informant-rails gem provides Rails and ActiveRecord hooks for The Informant.
6
+
7
+ [![Homepage](http://www.informantapp.com)](http://www.informantapp.com)
8
+
9
+ ## Compatibility
10
+
11
+ Fabrication is tested against Ruby 1.9.3, 2.0.0, and Rubinius.
12
+
13
+ [![Build Status](https://secure.travis-ci.org/theinformant/informant-rails.png)](http://travis-ci.org/informant/informant-rails)
14
+ [![Code Climate](https://codeclimate.com/github/theinformant/informant-rails.png)](https://codeclimate.com/github/informant/informant-rails)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "rspec/core/rake_task"
2
+ RSpec::Core::RakeTask.new(:spec) do |spec|
3
+ spec.pattern = "spec/**/*_spec.rb"
4
+ end
5
+
6
+ task default: :spec
@@ -0,0 +1,55 @@
1
+ require 'net/http'
2
+
3
+ module InformantRails
4
+ class Client
5
+ @requests = {}
6
+
7
+ def self.record(env)
8
+ new_request.request_url = env['HTTP_REFERER']
9
+ end
10
+
11
+ def self.inform_action(controller_name, action)
12
+ if request
13
+ request.filename = controller_name
14
+ request.action = action
15
+ end
16
+ end
17
+
18
+ def self.inform(model)
19
+ request.process_model(model) if request && model
20
+ end
21
+
22
+ def self.process
23
+ if Config.api_token.present? && request && request.models.any?
24
+ Net::HTTP.post_form(api_url, request.as_json)
25
+ end
26
+ remove_request
27
+ end
28
+
29
+ def self.request
30
+ @requests[request_id]
31
+ end
32
+
33
+ private
34
+
35
+ def self.new_request
36
+ @requests[request_id] = Request.new
37
+ end
38
+
39
+ def self.remove_request
40
+ @requests.delete(request_id)
41
+ end
42
+
43
+ def self.request_id
44
+ Thread.current.object_id
45
+ end
46
+
47
+ def self.api_url
48
+ @api_url ||= URI([
49
+ 'http://informant-production.herokuapp.com/api/v1',
50
+ InformantRails::Config.api_token,
51
+ InformantRails::Config.server_environment
52
+ ].join('/'))
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ module InformantRails::Config
2
+ extend self
3
+
4
+ attr_accessor :api_token, :server_environment
5
+
6
+ @api_token = ENV['INFORMANT_API_KEY']
7
+ @server_environment = Rails.env
8
+
9
+ def configure; yield self end
10
+ end
@@ -0,0 +1,4 @@
1
+ module InformantRails
2
+ class FieldError < Struct.new(:name, :value, :message)
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module InformantRails
2
+ class Middleware < Struct.new(:app)
3
+ def call(env)
4
+ InformantRails::Client.record(env)
5
+ response = app.call(env)
6
+ InformantRails::Client.process
7
+ response
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module InformantRails
2
+ class Model
3
+ attr_accessor :name, :errors
4
+
5
+ def initialize(model)
6
+ self.name = model.class.name
7
+ self.errors = model.errors.map do |field, error|
8
+ InformantRails::FieldError.new(field.to_s, model[field], error)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module InformantRails
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'informant middleware' do |config|
4
+ config.middleware.use 'InformantRails::Middleware'
5
+ end
6
+
7
+ initializer 'informant ActionController binding' do
8
+ class ::ActionController::Base
9
+ before_filter do
10
+ InformantRails::Client.inform_action(
11
+ controller_name, action_name
12
+ )
13
+ end
14
+ end
15
+ end
16
+
17
+ initializer 'informant ActiveRecord binding' do
18
+ class ::ActiveRecord::Base
19
+ def valid?(*args)
20
+ result = super(*args)
21
+ InformantRails::Client.inform(self)
22
+ result
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module InformantRails
2
+ class Request
3
+ attr_accessor :request_url, :filename, :action
4
+
5
+ def process_model(model)
6
+ models << InformantRails::Model.new(model) if model
7
+ end
8
+
9
+ def models
10
+ @models ||= []
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module InformantRails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'informant-rails/railtie'
2
+
3
+ module InformantRails
4
+ autoload :Config, 'informant-rails/config'
5
+ autoload :Client, 'informant-rails/client'
6
+ autoload :FieldError, 'informant-rails/field_error'
7
+ autoload :Middleware, 'informant-rails/middleware'
8
+ autoload :Model, 'informant-rails/model'
9
+ autoload :Request, 'informant-rails/request'
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: informant-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Elliott
8
+ - Cameron Daigle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: The Informant tells you what's irritating your users.
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/informant-rails/client.rb
35
+ - lib/informant-rails/config.rb
36
+ - lib/informant-rails/field_error.rb
37
+ - lib/informant-rails/middleware.rb
38
+ - lib/informant-rails/model.rb
39
+ - lib/informant-rails/railtie.rb
40
+ - lib/informant-rails/request.rb
41
+ - lib/informant-rails/version.rb
42
+ - lib/informant-rails.rb
43
+ - LICENSE
44
+ - README.markdown
45
+ - Rakefile
46
+ homepage: http://www.theinformant.io
47
+ licenses:
48
+ - GPL
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.1.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: The Informant tells you what's irritating your users.
70
+ test_files: []