Commit ea5b079557395ee3cc01ce266acf49ca6e34f3e6
Exists in
master
and in
1 other branch
Merge branch 'add_support_for_gtalk' of git://github.com/shukydvir/errbit into s…
…hukydvir-add_support_for_gtalk Conflicts: Gemfile app/models/notification_services/campfire_service.rb spec/fabricators/notification_service_fabricator.rb
Showing
13 changed files
with
86 additions
and
9 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -312,6 +312,7 @@ GEM |
312 | 312 | webmock (1.8.7) |
313 | 313 | addressable (>= 2.2.7) |
314 | 314 | crack (>= 0.1.7) |
315 | + xmpp4r (0.5) | |
315 | 316 | xpath (0.1.4) |
316 | 317 | nokogiri (~> 1.3) |
317 | 318 | yajl-ruby (1.1.0) |
... | ... | @@ -374,4 +375,5 @@ DEPENDENCIES |
374 | 375 | unicorn |
375 | 376 | useragent (~> 0.3.1) |
376 | 377 | webmock |
378 | + xmpp4r | |
377 | 379 | yajl-ruby | ... | ... |
4.62 KB
4.62 KB
4.07 KB
app/models/notice_observer.rb
... | ... | @@ -7,17 +7,16 @@ class NoticeObserver < Mongoid::Observer |
7 | 7 | notice.app.notification_service.create_notification(notice.problem) |
8 | 8 | end |
9 | 9 | |
10 | - return unless should_notify? notice | |
11 | - | |
12 | - Mailer.err_notification(notice).deliver | |
10 | + if notice.app.notification_recipients.any? | |
11 | + Mailer.err_notification(notice).deliver | |
12 | + end | |
13 | 13 | end |
14 | 14 | |
15 | 15 | private |
16 | 16 | |
17 | 17 | def should_notify? notice |
18 | 18 | 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? | |
19 | + app.notify_on_errs? and (app.notification_recipients.any? or !app.notification_service.nil?) and | |
20 | + (app.email_at_notices or Errbit::Config.email_at_notices).include?(notice.problem.notices_count) | |
22 | 21 | end |
23 | 22 | end | ... | ... |
app/models/notification_service.rb
app/models/notification_services/campfire_service.rb
... | ... | @@ -20,10 +20,13 @@ if defined? Campy |
20 | 20 | end |
21 | 21 | end |
22 | 22 | |
23 | + def url | |
24 | + "http://campfirenow.com/" | |
25 | + end | |
26 | + | |
23 | 27 | def create_notification(problem) |
24 | 28 | # build the campfire client |
25 | 29 | campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id) |
26 | - | |
27 | 30 | # post the issue to the campfire room |
28 | 31 | campy.speak "[errbit] #{problem.app.name} #{notification_description problem} - http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}/problems/#{problem.id.to_s}" |
29 | 32 | end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
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 Username, Password and To User' | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + def url | |
25 | + "http://www.google.com/talk/" | |
26 | + end | |
27 | + | |
28 | + def create_notification(problem) | |
29 | + # build the xmpp client | |
30 | + client = Jabber::Client.new(Jabber::JID.new(subdomain)) | |
31 | + client.connect("talk.google.com") | |
32 | + client.auth(api_token) | |
33 | + | |
34 | + # post the issue to the xmpp room | |
35 | + client.send(Jabber::Message.new(room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | |
36 | + end | |
37 | +end | |
0 | 38 | \ No newline at end of file | ... | ... |
app/views/apps/index.html.haml
... | ... | @@ -28,7 +28,11 @@ |
28 | 28 | - if any_notification_services? |
29 | 29 | %td.notification_service |
30 | 30 | - if app.notification_service_configured? |
31 | - = image_tag("#{app.notification_service.label}_goto.png") | |
31 | + - notification_service_img = image_tag("#{app.notification_service.label}_goto.png") | |
32 | + - if app.notification_service.url | |
33 | + = link_to( notification_service_img, app.notification_service.url, :target => "_blank" ) | |
34 | + - else | |
35 | + = notification_service_img | |
32 | 36 | - if any_issue_trackers? |
33 | 37 | %td.issue_tracker |
34 | 38 | - if app.issue_tracker_configured? | ... | ... |
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 hipchat hoiio pushover).each do |t| | |
8 | +%w(campfire gtalk hipchat hoiio pushover).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. | ... | ... |