rnotifier 0.0.9 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67a2b60f6bf080a8814c12e59719bab1e080fe39
4
- data.tar.gz: 96aeb8786e52e6fd723cb9528e6bfd78ffb0cd6f
3
+ metadata.gz: 7fdda4804509a222da3da5cb876ec831a829659c
4
+ data.tar.gz: 1b6b2be167646512fd9078ecbd2c711a933d572f
5
5
  SHA512:
6
- metadata.gz: 8f65adfbbd5788e39ea264a5d3b84b2f0759f916ffcb002b04ac2c4ef975295b7511ca85fd126d5d2a93b30ea4d68985aaa5eea73fa765c1656b6472124e551b
7
- data.tar.gz: 9d0f025c02c33b4558271c27838575320b48052e7e31284c561c56e7b2e5d77bc3d0395012b44f6052d02e7b09e291841f99613fcf103087d99f1fa9d2927025
6
+ metadata.gz: 98a2cde857b4e00ef0a5fbd0a8a710c5c5563c07a81f5f8c081f634514ce9e684938df5a9915aa3f8ad2c8afb30008169dd36457294f4626c0dfa192e96133bf
7
+ data.tar.gz: e76ebcfd6889c2d0ac0a3ae2f8da50e986f85286f742b2caffe79ea000f8702d7e0957b782ec63b01624862bfec2fd9eebc87c9ec70203379ff0e4d96a6e0ebc
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ branches:
2
+ only:
3
+ - 'master'
4
+
5
+ language: ruby
6
+
7
+ rvm:
8
+ - 1.9.3
9
+ - 2.0.0
10
+
11
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'coveralls', require: false
3
4
  # Specify your gem's dependencies in rnotifier.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Exception catcher for rack base applications.
4
4
 
5
+ [![Build Status](https://travis-ci.org/jiren/rnotifier.png?branch=master)](https://travis-ci.org/jiren/rnotifier)
6
+ [![Coverage Status](https://coveralls.io/repos/jiren/rnotifier/badge.png?branch=master)](https://coveralls.io/r/jiren/rnotifier?branch=master)
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -22,13 +25,13 @@ rnotifier install 'API-KEY' # This will create 'config/rnotifier.yaml' file.
22
25
 
23
26
  ### Config file options
24
27
 
25
- - environments: development #Default is production
26
- - capture_code: true #Default false
27
- - api_host: 'http://yourapp.com' #Default http://rnotifier.com
28
+ environments: development,test #default is production
29
+ capture_code: true #default false
30
+ api_host: 'http://yourapp.com' #default http://rnotifier.com
28
31
 
29
32
  ### To test config
30
33
 
31
- rnotifier test #This will send test exception to rnotifier.
34
+ rnotifier test #this will send test exception to rnotifier.
32
35
 
33
36
  ## Contributing
34
37
 
@@ -4,15 +4,16 @@ module Rnotifier
4
4
  :api_host => 'http://api.rnotifier.com',
5
5
  :api_version => 'v1',
6
6
  :notify_path => 'exception',
7
+ :event_path => 'event',
7
8
  :ignore_env => ['development', 'test'],
8
9
  :http_open_timeout => 2,
9
10
  :http_read_timeout => 4
10
11
  }
11
12
 
12
- CLIENT = "RN-RUBY-GEM:#{Rnotifier::VERSION}"
13
+ CLIENT = "RRG:#{Rnotifier::VERSION}"
13
14
 
14
15
  class << self
15
- attr_accessor :api_key, :notification_path, :environments, :current_env,
16
+ attr_accessor :api_key, :notification_path, :event_path, :environments, :current_env,
16
17
  :valid, :app_env, :api_host, :ignore_exceptions, :capture_code
17
18
 
18
19
  def [](val)
@@ -49,6 +50,8 @@ module Rnotifier
49
50
  self.app_env = get_app_env
50
51
  self.ignore_exceptions = self.ignore_exceptions.split(',') if self.ignore_exceptions.is_a?(String)
51
52
 
53
+ self.event_path = '/' + [DEFAULT[:api_version], DEFAULT[:event_path], self.api_key].join('/')
54
+
52
55
  self.valid = true
53
56
  end
54
57
 
@@ -80,6 +83,16 @@ module Rnotifier
80
83
  (defined?(Rails) && Rails.respond_to?(:root)) ? Rails.root.to_s : Dir.pwd
81
84
  end
82
85
 
86
+ def event_app_env
87
+ {
88
+ :env => self.current_env,
89
+ :pid => $$,
90
+ :host => (Socket.gethostname rescue ''),
91
+ :language => 'ruby',
92
+ :platform => (RUBY_PLATFORM rescue '')
93
+ }
94
+ end
95
+
83
96
  end
84
97
  end
85
98
  end
@@ -0,0 +1,31 @@
1
+ module Rnotifier
2
+ class EventData
3
+ attr_reader :data
4
+
5
+ def initialize(name, data = {})
6
+ @data = {
7
+ :name => name,
8
+ :data => data,
9
+ :app_env => EventData.app_env,
10
+ :occurred_at => Time.now.utc.to_s,
11
+ :data_from => :event,
12
+ :rnotifier_client => Config::CLIENT,
13
+ }
14
+ @data[:context_data] = Thread.current[:rnotifier_context] if Thread.current[:rnotifier_context]
15
+ end
16
+
17
+ def notify
18
+ begin
19
+ Notifier.send(data, Rnotifier::Config.event_path)
20
+ rescue Exception => e
21
+ Rlogger.error("[EVENT NOTIFY] #{e.message}")
22
+ Rlogger.error("[EVENT NOTIFY] #{e.backtrace}")
23
+ end
24
+ end
25
+
26
+ def self.app_env
27
+ @env ||= Rnotifier::Config.event_app_env
28
+ end
29
+
30
+ end
31
+ end
@@ -4,7 +4,10 @@ module Rnotifier
4
4
 
5
5
  def get(backtrace)
6
6
  return unless backtrace
7
- filename, line, method = (backtrace.find{|l| l =~ /^#{Config.app_env[:app_root]}/} || backtrace[0]).split(':')
7
+ bline = backtrace.find do |l|
8
+ l.index(Config.app_env[:app_root]) == 0 && !Gem.path.any?{|path| l.index(path) == 0}
9
+ end
10
+ filename, line, method = (bline|| backtrace[0]).split(':')
8
11
  self.find(filename, line.to_i, 3)
9
12
  end
10
13
 
@@ -18,9 +18,8 @@ module Rnotifier
18
18
 
19
19
  begin
20
20
  data = options[:type] == :rack ? self.rack_exception_data : {:extra => self.env }
21
-
22
21
  data[:app_env] = Rnotifier::Config.app_env
23
- data[:occurred_at] = Time.now.to_s
22
+ data[:occurred_at] = Time.now.utc.to_s
24
23
  data[:exception] = self.exception_data
25
24
  data[:context_data] = Thread.current[:rnotifier_context] if Thread.current[:rnotifier_context]
26
25
  data[:data_from] = options[:type]
@@ -30,10 +29,8 @@ module Rnotifier
30
29
  rescue Exception => e
31
30
  Rlogger.error("[NOTIFY] #{e.message}")
32
31
  Rlogger.error("[NOTIFY] #{e.backtrace}")
33
- ensure
34
- Rnotifier.clear_context
32
+ false
35
33
  end
36
- false
37
34
  end
38
35
 
39
36
  def rack_exception_data
@@ -3,23 +3,26 @@ module Rnotifier
3
3
  class << self
4
4
 
5
5
  def connection
6
- @connection ||= Faraday.new(:url => Rnotifier::Config.api_host) do |faraday|
6
+ @connection ||= Faraday.new(:url => Config.api_host) do |faraday|
7
7
  faraday.adapter Faraday.default_adapter
8
8
  end
9
9
  end
10
10
 
11
- def send(data)
11
+ def send(data, url = nil)
12
12
  response = self.connection.post do |req|
13
- req.url Rnotifier::Config.notification_path
13
+ req.url(url || Config.notification_path)
14
14
  req.headers['Content-Type'] = 'application/json'
15
- req.options[:timeout] = Rnotifier::Config[:http_open_timeout]
16
- req.options[:open_timeout] = Rnotifier::Config[:http_read_timeout]
15
+ req.headers['Api-Key'] = Config.api_key
16
+ req.options[:timeout] = Config[:http_open_timeout]
17
+ req.options[:open_timeout] = Config[:http_read_timeout]
17
18
  req.body = MultiJson.dump(data)
18
19
  end
19
20
 
20
21
  return true if response.status == 200
21
22
  Rlogger.error("[RNOTIFIER SERVER] Response Status:#{response.status}")
22
23
  false
24
+ ensure
25
+ Rnotifier.clear_context
23
26
  end
24
27
  end
25
28
  end
@@ -1,3 +1,3 @@
1
1
  module Rnotifier
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/rnotifier.rb CHANGED
@@ -9,6 +9,7 @@ require 'rnotifier/config'
9
9
  require 'rnotifier/rlogger'
10
10
  require 'rnotifier/notifier'
11
11
  require 'rnotifier/exception_data'
12
+ require 'rnotifier/event_data'
12
13
  require 'rnotifier/rack_middleware'
13
14
  require 'rnotifier/parameter_filter'
14
15
  require 'rnotifier/exception_code'
@@ -45,8 +46,12 @@ module Rnotifier
45
46
  Thread.current[:rnotifier_context] = nil
46
47
  end
47
48
 
48
- def send_exception(exception, opts = {})
49
- Rnotifier::ExceptionData.new(exception, opts, {:type => :rescue}).notify
49
+ def exception(exception, params = {})
50
+ Rnotifier::ExceptionData.new(exception, params, {:type => :rescue}).notify
51
+ end
52
+
53
+ def event(name, params = {})
54
+ Rnotifier::EventData.new(name, params).notify if Rnotifier::Config.valid?
50
55
  end
51
56
 
52
57
  end
@@ -0,0 +1,29 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'spec_helper'
3
+
4
+ describe Rnotifier::EventData do
5
+
6
+ before(:all) do
7
+ rnotifier_init
8
+ @name = 'product'
9
+ @data = {:id => 1, :name => 'ProductX'}
10
+ end
11
+
12
+ it 'is initialize exception_data object' do
13
+ e_data = Rnotifier::EventData.new(@name, @data)
14
+
15
+ expect(e_data.data[:name]).to eq @name
16
+ expect(e_data.data[:data]).to eq @data
17
+ expect(e_data.data[:data_from]).to eq :event
18
+ end
19
+
20
+ it 'sends event data to server' do
21
+ path = '/' + [ Rnotifier::Config::DEFAULT[:api_version], Rnotifier::Config::DEFAULT[:event_path], 'API-KEY'].join('/')
22
+ stubs = stub_faraday_request({:path => path})
23
+
24
+ Rnotifier::EventData.new(@name, @data).notify
25
+
26
+ expect { stubs.verify_stubbed_calls }.to_not raise_error
27
+ end
28
+
29
+ end
@@ -4,6 +4,7 @@ require 'sinatra/base'
4
4
  module RnotifierTest
5
5
 
6
6
  class FakeApp < Sinatra::Base
7
+ set :environment, :production
7
8
  use Rnotifier::RackMiddleware, 'spec/fixtures/rnotifier_test.yaml'
8
9
 
9
10
  get '/' do
@@ -12,11 +12,11 @@ describe Rnotifier::RackMiddleware do
12
12
  end
13
13
 
14
14
  it 'sends get request and catch exception' do
15
- get "/exception/1"
15
+ get "/exception/1"
16
16
 
17
- expect(last_response.errors.split(/:\n/).first).to eq @type_error
18
- expect(last_response.status).to eq 500
19
- expect { @stubs.verify_stubbed_calls }.to_not raise_error
17
+ expect(last_response.errors.split(/:\n/).first).to eq @type_error
18
+ expect(last_response.status).to eq 500
19
+ expect { @stubs.verify_stubbed_calls }.to_not raise_error
20
20
  end
21
21
 
22
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler/setup'
3
5
  require 'open-uri'
@@ -5,10 +7,14 @@ require 'rack'
5
7
  require 'rack/request'
6
8
  require 'rack/mock'
7
9
  require 'rack/test'
8
- require 'rnotifier'
10
+ require 'coveralls'
9
11
 
12
+ $:.unshift(File.dirname(__FILE__) + '/../lib/')
13
+ require 'rnotifier'
10
14
  require File.dirname(__FILE__) + "/fixtures/fake_app"
11
15
 
16
+ Coveralls.wear!
17
+
12
18
  RSpec.configure do |config|
13
19
  config.color_enabled = true
14
20
  #config.tty = true
@@ -20,24 +26,15 @@ RSpec.configure do |config|
20
26
  end
21
27
  end
22
28
 
23
- $:.unshift(File.dirname(__FILE__) + '/../lib/')
24
-
25
- ENV['RACK_ENV'] = 'test'
26
-
27
- require 'rnotifier'
28
-
29
29
  def rnotifier_init
30
30
  ENV['RACK_ENV'] = 'test'
31
31
  Rnotifier.load_config("#{Dir.pwd}/spec/fixtures/rnotifier.yaml")
32
32
  end
33
33
 
34
- def set_test_adapter
35
- end
36
-
37
34
  def stub_faraday_request(opts = {})
38
35
  opts[:status] ||= 200
39
36
  opts[:message] ||= 'ok'
40
- opts[:path] = '/' + [ Rnotifier::Config::DEFAULT[:api_version], Rnotifier::Config::DEFAULT[:notify_path], 'API-KEY'].join('/')
37
+ opts[:path] ||= '/' + [ Rnotifier::Config::DEFAULT[:api_version], Rnotifier::Config::DEFAULT[:notify_path], 'API-KEY'].join('/')
41
38
 
42
39
  stubs = Faraday::Adapter::Test::Stubs.new
43
40
  conn = Faraday.new do |builder|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rnotifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiren Patel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - .gitignore
120
+ - .travis.yml
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
@@ -127,6 +128,7 @@ files:
127
128
  - lib/rnotifier.rb
128
129
  - lib/rnotifier/config.rb
129
130
  - lib/rnotifier/config_test.rb
131
+ - lib/rnotifier/event_data.rb
130
132
  - lib/rnotifier/exception_code.rb
131
133
  - lib/rnotifier/exception_data.rb
132
134
  - lib/rnotifier/notifier.rb
@@ -138,6 +140,7 @@ files:
138
140
  - rnotifier.gemspec
139
141
  - spec/code.text
140
142
  - spec/config_spec.rb
143
+ - spec/event_data_spec.rb
141
144
  - spec/exception_code_spec.rb
142
145
  - spec/exception_data_spec.rb
143
146
  - spec/fixtures/fake_app.rb
@@ -172,6 +175,7 @@ summary: Exception catcher for Rails and other Rack apps
172
175
  test_files:
173
176
  - spec/code.text
174
177
  - spec/config_spec.rb
178
+ - spec/event_data_spec.rb
175
179
  - spec/exception_code_spec.rb
176
180
  - spec/exception_data_spec.rb
177
181
  - spec/fixtures/fake_app.rb