Commit a1ff86d683afa1a9bbba016fecb4f7d3b88ade77
1 parent
3db48ca3
Exists in
master
and in
1 other branch
adding support to gtalk notification
Showing
10 changed files
with
70 additions
and
5 deletions
Show diff stats
Gemfile
... | ... | @@ -33,6 +33,7 @@ gem 'rack-ssl-enforcer' |
33 | 33 | gem 'fabrication', "~> 1.3.0" # Both for tests, and loading demo data |
34 | 34 | gem 'rails_autolink', '~> 1.0.9' |
35 | 35 | gem 'campy' |
36 | +gem 'xmpp4r' | |
36 | 37 | |
37 | 38 | # Please don't update this to airbrake - We override the send_notice method |
38 | 39 | # to handle internal errors. | ... | ... |
Gemfile.lock
... | ... | @@ -287,6 +287,7 @@ GEM |
287 | 287 | webmock (1.8.7) |
288 | 288 | addressable (>= 2.2.7) |
289 | 289 | crack (>= 0.1.7) |
290 | + xmpp4r (0.5) | |
290 | 291 | xpath (0.1.4) |
291 | 292 | nokogiri (~> 1.3) |
292 | 293 | yajl-ruby (1.1.0) |
... | ... | @@ -341,4 +342,5 @@ DEPENDENCIES |
341 | 342 | unicorn |
342 | 343 | useragent (~> 0.3.1) |
343 | 344 | webmock |
345 | + xmpp4r | |
344 | 346 | yajl-ruby | ... | ... |
4.62 KB
4.62 KB
4.07 KB
app/models/notice_observer.rb
... | ... | @@ -9,15 +9,16 @@ class NoticeObserver < Mongoid::Observer |
9 | 9 | notice.app.notification_service.create_notification(notice.problem) |
10 | 10 | end |
11 | 11 | |
12 | - Mailer.err_notification(notice).deliver | |
12 | + if notice.app.notification_recipients.any? | |
13 | + Mailer.err_notification(notice).deliver | |
14 | + end | |
13 | 15 | end |
14 | 16 | |
15 | 17 | private |
16 | 18 | |
17 | 19 | def should_notify? notice |
18 | 20 | app = notice.app |
19 | - app.notify_on_errs? && | |
20 | - (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) && | |
21 | - app.notification_recipients.any? | |
21 | + app.notify_on_errs? and (app.notification_recipients.any? or !app.notification_service.nil?) and | |
22 | + (app.email_at_notices or Errbit::Config.email_at_notices).include?(notice.problem.notices_count) | |
22 | 23 | end |
23 | 24 | end | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +class NotificationServices::GtalkService < NotificationService | |
2 | + Label = "gtalk" | |
3 | + Fields = [ | |
4 | + [:subdomain, { | |
5 | + :placeholder => "username@example.com", | |
6 | + :label => "Username" | |
7 | + }], | |
8 | + [:api_token, { | |
9 | + :placeholder => "password", | |
10 | + :label => "Password" | |
11 | + }], | |
12 | + [:room_id, { | |
13 | + :placeholder => "touser@example.com", | |
14 | + :label => "Send To User" | |
15 | + }], | |
16 | + ] | |
17 | + | |
18 | + def check_params | |
19 | + if Fields.detect {|f| self[f[0]].blank? } | |
20 | + errors.add :base, 'You must specify your XMPP Domain, Username and Room Name' | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + def create_notification(problem) | |
25 | + # build the xmpp client | |
26 | + client = Jabber::Client.new(Jabber::JID.new(subdomain)) | |
27 | + client.connect("talk.google.com") | |
28 | + client.auth(api_token) | |
29 | + | |
30 | + # post the issue to the xmpp room | |
31 | + client.send(Jabber::Message.new(room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | |
32 | + end | |
33 | +end | |
0 | 34 | \ No newline at end of file | ... | ... |
spec/fabricators/notification_service_fabricator.rb
... | ... | @@ -5,6 +5,6 @@ Fabricator :notification_service do |
5 | 5 | subdomain { sequence :word } |
6 | 6 | end |
7 | 7 | |
8 | -%w(campfire).each do |t| | |
8 | +%w(campfire gtalk).each do |t| | |
9 | 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
10 | 10 | end | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe NotificationService::GtalkService do | |
4 | + it "it should send a notification to gtalk" do | |
5 | + # setup | |
6 | + notice = Fabricate :notice | |
7 | + notification_service = Fabricate :gtalk_notification_service, :app => notice.app | |
8 | + problem = notice.problem | |
9 | + | |
10 | + #gtalk stubbing | |
11 | + gtalk = mock('GtalkService') | |
12 | + jid = double("jid") | |
13 | + message = double("message") | |
14 | + Jabber::JID.should_receive(:new).with(notification_service.subdomain).and_return(jid) | |
15 | + Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) | |
16 | + gtalk.should_receive(:connect) | |
17 | + gtalk.should_receive(:auth).with(notification_service.api_token) | |
18 | + Jabber::Message.should_receive(:new).with(notification_service.room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_service.notification_description problem}").and_return(message) | |
19 | + | |
20 | + #assert | |
21 | + gtalk.should_receive(:send).with(message) | |
22 | + | |
23 | + | |
24 | + notification_service.create_notification(problem) | |
25 | + end | |
26 | +end | |
27 | + | ... | ... |
spec/spec_helper.rb
... | ... | @@ -5,6 +5,7 @@ require File.expand_path("../../config/environment", __FILE__) |
5 | 5 | require 'rspec/rails' |
6 | 6 | require 'database_cleaner' |
7 | 7 | require 'webmock/rspec' |
8 | +require 'xmpp4r' | |
8 | 9 | |
9 | 10 | # Requires supporting files with custom matchers and macros, etc, |
10 | 11 | # in ./support/ and its subdirectories. | ... | ... |