rulesio 0.9.3 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -26,6 +26,7 @@ You should create two incoming channels (event streams) in rules.io, and configu
26
26
  middleware :exceptions do # automatically generate events for exceptions
27
27
  token 'ERROR_CHANNEL_TOKEN' # separate channel for error-centric events
28
28
  end
29
+ disable_sending_events if Rails.env.test? || Rails.env.development?
29
30
 
30
31
  ###As general-purpose Rack middleware, with or without Rails
31
32
 
@@ -87,6 +88,7 @@ Options
87
88
  RulesIO::Rack accepts these options:
88
89
 
89
90
  * `token` -- the token for a rules.io channel
91
+ * `disable_sending_events` -- you probably want to include this directive for your test and development environments
90
92
  * `webhook_url` -- defaults to 'https://www.rules.io/events'
91
93
  * `middleware` -- takes the symbol for a middleware and a block, configuring it
92
94
  * `queue` -- takes the class used for queuing (default: RulesIO::MemoryQueue), and an optional hash; see the section on girl_friday for examples
@@ -3,10 +3,11 @@ require 'active_record'
3
3
 
4
4
  module RulesIO
5
5
  class RailsConfigurator
6
- attr_accessor :token, :webhook_url, :middlewares, :queue, :controller_data, :queue_options
6
+ attr_accessor :token, :webhook_url, :middlewares, :queue, :controller_data, :queue_options, :disable
7
7
  def initialize
8
8
  @webhook_url = 'https://www.rules.io/events/'
9
9
  @middlewares = {}
10
+ @disable = false
10
11
  end
11
12
 
12
13
  def token(token)
@@ -25,6 +26,10 @@ module RulesIO
25
26
  @queue = queue
26
27
  @queue_options = options
27
28
  end
29
+
30
+ def disable_sending_events
31
+ @disable = true
32
+ end
28
33
 
29
34
  def controller_data(data)
30
35
  @controller_data = data
@@ -75,6 +80,7 @@ module RulesIO
75
80
  if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
76
81
  ::Rails.configuration.middleware.insert_after 'ActionDispatch::Static', 'RulesIO::Rack',
77
82
  :webhook_url => @webhook_url,
83
+ :disable_sending_events => @disable,
78
84
  :token => @token,
79
85
  :queue => @queue,
80
86
  :queue_options => @queue_options,
@@ -84,6 +90,8 @@ module RulesIO
84
90
  ::Rails.configuration.middleware.use('RulesIO::Exceptions', @middlewares[:exceptions].configuration) if @middlewares.has_key?(:exceptions)
85
91
  end
86
92
  end
93
+ else
94
+ puts 'Warning: rulesio configuration file not found in config/rulesio.rb'
87
95
  end
88
96
  end
89
97
 
data/lib/rulesio/users.rb CHANGED
@@ -46,8 +46,13 @@ module RulesIO
46
46
  end
47
47
 
48
48
  def event(env, status, duration)
49
+ domain = if (status.to_i >= 400)
50
+ 'pageerror'
51
+ else
52
+ (env['rulesio.request_method'] == 'GET') ? 'pageview' : 'formpost'
53
+ end
49
54
  event = {
50
- :_domain => (status.to_i >= 400) ? 'pageerror' : 'pageview',
55
+ :_domain => domain,
51
56
  :status => status,
52
57
  :duration => "%.2f" % (duration * 1000)
53
58
  }
@@ -55,6 +60,9 @@ module RulesIO
55
60
  event[:_xactor] = actor_for_exception(exception)
56
61
  event[:_message] = exception.to_s
57
62
  end
63
+ if domain == 'pageerror' && status.to_i < 500
64
+ event[:_message] = "#{status}: #{::Rack::Utils::HTTP_STATUS_CODES[status.to_i]}"
65
+ end
58
66
  event.merge!(@options[:custom_data].call(env))
59
67
  event
60
68
  end
@@ -1,3 +1,3 @@
1
1
  module RulesIO
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.6'
3
3
  end
data/lib/rulesio.rb CHANGED
@@ -11,7 +11,7 @@ require 'active_support/core_ext/module/attribute_accessors'
11
11
  require 'active_support/core_ext/hash/indifferent_access'
12
12
 
13
13
  module RulesIO
14
- mattr_accessor :filter_parameters, :buffer, :token, :webhook_url, :queue, :queue_options, :controller_data, :logger
14
+ mattr_accessor :filter_parameters, :buffer, :token, :webhook_url, :queue, :queue_options, :controller_data, :logger, :disable_sending_events
15
15
 
16
16
  def self.default_ignored_crawlers
17
17
  %w(Baidu Gigabot Googlebot libwww-perl lwp-trivial msnbot SiteUptime Slurp WordPress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot NewRelicPinger)
@@ -29,6 +29,7 @@ module RulesIO
29
29
  end
30
30
 
31
31
  def self.post_payload_to_token(payload, token)
32
+ return if RulesIO.disable_sending_events
32
33
  uri = URI(RulesIO.webhook_url + token)
33
34
  req = Net::HTTP::Post.new(uri.path)
34
35
  req.body = payload.to_json
@@ -98,14 +99,16 @@ module RulesIO
98
99
  params = request.params
99
100
  action = page_event_name(request, params)
100
101
 
102
+ event[:_domain] = 'JSON' if event[:_domain] == 'pageview' && params['format'] == 'json'
103
+ event[:_domain] = 'XML' if event[:_domain] == 'pageview' && params['format'] == 'xml'
101
104
  event[:_name] ||= action
102
105
  event[:_from] ||= current_user.email if current_user && current_user.respond_to?(:email) && current_user.email != event[:_actor]
103
106
  event[:action] = action
104
107
  event[:request_url] = env['rulesio.request_url']
105
- event[:request_method] = request.request_method
108
+ event[:request_method] = env['rulesio.request_method']
106
109
  event[:user_agent] = request.user_agent
107
110
  event[:referer_url] = request.referer
108
- event[:params] = params.except(*RulesIO.filter_parameters)
111
+ event[:params] = params.except(*RulesIO.filter_parameters).reject{|k,v|k =~ /password/}
109
112
  event[:session] = request.session
110
113
  end
111
114
 
@@ -124,11 +127,14 @@ module RulesIO
124
127
  RulesIO.queue = options[:queue] || RulesIO::MemoryQueue
125
128
  RulesIO.queue_options = options[:queue_options] || {}
126
129
  RulesIO.controller_data = options[:controller_data] || '{}'
130
+ RulesIO.disable_sending_events = options[:disable_sending_events] || false
127
131
  end
128
132
 
129
133
  def call(env)
130
134
  RulesIO.buffer = []
131
- env['rulesio.request_url'] = ::Rack::Request.new(env).url
135
+ request = ::Rack::Request.new(env)
136
+ env['rulesio.request_url'] = request.url
137
+ env['rulesio.request_method'] = request.request_method
132
138
  @app.call(env)
133
139
  ensure
134
140
  RulesIO.flush(env)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulesio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-31 00:00:00.000000000 Z
13
+ date: 2012-09-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport