diff --git a/Gemfile b/Gemfile index a5eeca3..5d546cb 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ gem 'rack-ssl-enforcer' gem 'fabrication', "~> 1.3.0" # Both for tests, and loading demo data gem 'rails_autolink', '~> 1.0.9' gem 'campy' +gem 'xmpp4r' # Please don't update this to airbrake - We override the send_notice method # to handle internal errors. diff --git a/Gemfile.lock b/Gemfile.lock index 1b06128..e5ec5d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -287,6 +287,7 @@ GEM webmock (1.8.7) addressable (>= 2.2.7) crack (>= 0.1.7) + xmpp4r (0.5) xpath (0.1.4) nokogiri (~> 1.3) yajl-ruby (1.1.0) @@ -341,4 +342,5 @@ DEPENDENCIES unicorn useragent (~> 0.3.1) webmock + xmpp4r yajl-ruby diff --git a/app/assets/images/gtalk_create.png b/app/assets/images/gtalk_create.png new file mode 100644 index 0000000..90d0e6d Binary files /dev/null and b/app/assets/images/gtalk_create.png differ diff --git a/app/assets/images/gtalk_goto.png b/app/assets/images/gtalk_goto.png new file mode 100644 index 0000000..90d0e6d Binary files /dev/null and b/app/assets/images/gtalk_goto.png differ diff --git a/app/assets/images/gtalk_inactive.png b/app/assets/images/gtalk_inactive.png new file mode 100644 index 0000000..f3f3241 Binary files /dev/null and b/app/assets/images/gtalk_inactive.png differ diff --git a/app/models/notice_observer.rb b/app/models/notice_observer.rb index 2fbb5ea..6de7ef7 100644 --- a/app/models/notice_observer.rb +++ b/app/models/notice_observer.rb @@ -9,15 +9,16 @@ class NoticeObserver < Mongoid::Observer notice.app.notification_service.create_notification(notice.problem) end - Mailer.err_notification(notice).deliver + if notice.app.notification_recipients.any? + Mailer.err_notification(notice).deliver + end end private def should_notify? notice app = notice.app - app.notify_on_errs? && - (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) && - app.notification_recipients.any? + app.notify_on_errs? and (app.notification_recipients.any? or !app.notification_service.nil?) and + (app.email_at_notices or Errbit::Config.email_at_notices).include?(notice.problem.notices_count) end end diff --git a/app/models/notification_services/gtalk_service.rb b/app/models/notification_services/gtalk_service.rb new file mode 100644 index 0000000..4940ddb --- /dev/null +++ b/app/models/notification_services/gtalk_service.rb @@ -0,0 +1,33 @@ +class NotificationServices::GtalkService < NotificationService + Label = "gtalk" + Fields = [ + [:subdomain, { + :placeholder => "username@example.com", + :label => "Username" + }], + [:api_token, { + :placeholder => "password", + :label => "Password" + }], + [:room_id, { + :placeholder => "touser@example.com", + :label => "Send To User" + }], + ] + + def check_params + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, 'You must specify your XMPP Domain, Username and Room Name' + end + end + + def create_notification(problem) + # build the xmpp client + client = Jabber::Client.new(Jabber::JID.new(subdomain)) + client.connect("talk.google.com") + client.auth(api_token) + + # post the issue to the xmpp room + client.send(Jabber::Message.new(room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) + end +end \ No newline at end of file diff --git a/spec/fabricators/notification_service_fabricator.rb b/spec/fabricators/notification_service_fabricator.rb index e5f6810..3684628 100644 --- a/spec/fabricators/notification_service_fabricator.rb +++ b/spec/fabricators/notification_service_fabricator.rb @@ -5,6 +5,6 @@ Fabricator :notification_service do subdomain { sequence :word } end -%w(campfire).each do |t| +%w(campfire gtalk).each do |t| Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" end diff --git a/spec/models/notification_service/gtalk_service_spec.rb b/spec/models/notification_service/gtalk_service_spec.rb new file mode 100644 index 0000000..85b454c --- /dev/null +++ b/spec/models/notification_service/gtalk_service_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe NotificationService::GtalkService do + it "it should send a notification to gtalk" do + # setup + notice = Fabricate :notice + notification_service = Fabricate :gtalk_notification_service, :app => notice.app + problem = notice.problem + + #gtalk stubbing + gtalk = mock('GtalkService') + jid = double("jid") + message = double("message") + Jabber::JID.should_receive(:new).with(notification_service.subdomain).and_return(jid) + Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) + gtalk.should_receive(:connect) + gtalk.should_receive(:auth).with(notification_service.api_token) + 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) + + #assert + gtalk.should_receive(:send).with(message) + + + notification_service.create_notification(problem) + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a6104c5..794d3cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'database_cleaner' require 'webmock/rspec' +require 'xmpp4r' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. -- libgit2 0.21.2