informant-rails 0.0.1 → 0.0.2

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: 0dde7f5500ee63c025d17548c609e542d21f5bea
4
- data.tar.gz: 75e97a3d342e00fba823613865363a6a61e2fa08
3
+ metadata.gz: e591798b1be7affc8eaba1cb7ffd4d78e618cdef
4
+ data.tar.gz: 324e9e8515be049953be4c571e76dbdc3256a8fe
5
5
  SHA512:
6
- metadata.gz: 63689617d74d35ebe8ad8e6e1b2d89e0fd7b6b6433df875bee63457b9191b11d1f02faad5e0467470d6805e85c689c0fd32fe4408f1bded9517ba12c700e30f5
7
- data.tar.gz: 1c4e66104ba92696dd6c8965693895168e9e327297d73d23ebf683fa254394f2e2bd4581b51f27c949b4a50033b64da06fd824d61d7b2e1667eaffe4ecef42ea
6
+ metadata.gz: 321479096bc623127a210a3155c7e66fe6c4579326fda0ade882593f1eaccd74b50d71210a43cbc7434dfdcb86a594c813412b74631c1e407bc15a339a113db7
7
+ data.tar.gz: a8dce9703be9e0cc7249f43d3372fb7fcdd00c7f67b2b21e66e5cfd9402cefe8d01265876b417b90317dc2d5a3fe99c4dde398c66eb5a439dd32e80f7d96ff3d
@@ -1,4 +1,4 @@
1
- require 'net/http'
1
+ require 'typhoeus'
2
2
 
3
3
  module InformantRails
4
4
  class Client
@@ -16,12 +16,14 @@ module InformantRails
16
16
  end
17
17
 
18
18
  def self.inform(model)
19
- request.process_model(model) if request && model
19
+ request.process_model(model) if request && include_model?(model)
20
20
  end
21
21
 
22
22
  def self.process
23
23
  if Config.api_token.present? && request && request.models.any?
24
- Net::HTTP.post_form(api_url, request.as_json)
24
+ Typhoeus::Request.new(
25
+ api_url, method: :post, params: { payload: request.as_json }
26
+ ).run
25
27
  end
26
28
  remove_request
27
29
  end
@@ -32,6 +34,10 @@ module InformantRails
32
34
 
33
35
  private
34
36
 
37
+ def self.include_model?(model)
38
+ !InformantRails::Config.exclude_models.include?(model.class.to_s)
39
+ end
40
+
35
41
  def self.new_request
36
42
  @requests[request_id] = Request.new
37
43
  end
@@ -45,11 +51,11 @@ module InformantRails
45
51
  end
46
52
 
47
53
  def self.api_url
48
- @api_url ||= URI([
49
- 'http://informant-production.herokuapp.com/api/v1',
54
+ @api_url ||= [
55
+ 'http://api.informantapp.com/api/v1',
50
56
  InformantRails::Config.api_token,
51
57
  InformantRails::Config.server_environment
52
- ].join('/'))
58
+ ].join('/')
53
59
  end
54
60
  end
55
61
  end
@@ -1,10 +1,11 @@
1
1
  module InformantRails::Config
2
2
  extend self
3
3
 
4
- attr_accessor :api_token, :server_environment
4
+ attr_accessor :api_token, :server_environment, :exclude_models
5
5
 
6
- @api_token = ENV['INFORMANT_API_KEY']
7
- @server_environment = Rails.env
6
+ self.api_token = ENV['INFORMANT_API_KEY']
7
+ self.server_environment = Rails.env
8
+ self.exclude_models = []
8
9
 
9
10
  def configure; yield self end
10
11
  end
@@ -8,5 +8,9 @@ module InformantRails
8
8
  InformantRails::FieldError.new(field.to_s, model[field], error)
9
9
  end
10
10
  end
11
+
12
+ def as_json(*args)
13
+ { name: name, errors: errors.map(&:as_json) }
14
+ end
11
15
  end
12
16
  end
@@ -16,10 +16,8 @@ module InformantRails
16
16
 
17
17
  initializer 'informant ActiveRecord binding' do
18
18
  class ::ActiveRecord::Base
19
- def valid?(*args)
20
- result = super(*args)
19
+ set_callback(:validate, :after) do
21
20
  InformantRails::Client.inform(self)
22
- result
23
21
  end
24
22
  end
25
23
  end
@@ -9,5 +9,14 @@ module InformantRails
9
9
  def models
10
10
  @models ||= []
11
11
  end
12
+
13
+ def as_json(*args)
14
+ {
15
+ models: models.map(&:as_json),
16
+ request_url: request_url,
17
+ filename: filename,
18
+ action: action
19
+ }
20
+ end
12
21
  end
13
22
  end
@@ -1,3 +1,3 @@
1
1
  module InformantRails
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
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.0.1
4
+ version: 0.0.2
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: 2013-09-23 00:00:00.000000000 Z
12
+ date: 2013-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: typhoeus
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  description: The Informant tells you what's irritating your users.
29
43
  email:
30
44
  executables: []