diff --git a/Gemfile b/Gemfile index 1758fc9..897feed 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,10 @@ gem 'octokit', '~> 1.0.0' gem 'campy' # Hipchat gem 'hipchat' +# Hoiio gem 'hoi' +# Pushover +gem 'rushover' # Authentication # --------------------------------------- diff --git a/Gemfile.lock b/Gemfile.lock index 7735b77..acda1f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -262,6 +262,9 @@ GEM ruby-fogbugz (0.1.1) crack rubyzip (0.9.9) + rushover (0.1.1) + json + rest-client selenium-webdriver (2.25.0) childprocess (>= 0.2.5) libwebsocket (~> 0.1.3) @@ -349,6 +352,7 @@ DEPENDENCIES rspec-rails (~> 2.6) ruby-debug ruby-fogbugz + rushover therubyracer thin timecop diff --git a/app/assets/images/pushover_create.png b/app/assets/images/pushover_create.png new file mode 100644 index 0000000..e6a2ca8 Binary files /dev/null and b/app/assets/images/pushover_create.png differ diff --git a/app/assets/images/pushover_goto.png b/app/assets/images/pushover_goto.png new file mode 100644 index 0000000..e6a2ca8 Binary files /dev/null and b/app/assets/images/pushover_goto.png differ diff --git a/app/assets/images/pushover_inactive.png b/app/assets/images/pushover_inactive.png new file mode 100644 index 0000000..9f88aed Binary files /dev/null and b/app/assets/images/pushover_inactive.png differ diff --git a/app/models/notification_services/pushover_service.rb b/app/models/notification_services/pushover_service.rb new file mode 100644 index 0000000..2d4d79f --- /dev/null +++ b/app/models/notification_services/pushover_service.rb @@ -0,0 +1,28 @@ +class NotificationServices::PushoverService < NotificationService + Label = "pushover" + Fields = [ + [:api_token, { + :placeholder => "User Key", + :label => "User Key" + }], + [:subdomain, { + :placeholder => "Application API Token", + :label => "Application API Token" + }] + ] + + def check_params + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, 'You must specify your User Key and Application API Token.' + end + end + + def create_notification(problem) + # build the hoi client + notification = Rushover::Client.new(subdomain) + + # send push notification to pushover + notification.notify(api_token, "#{notification_description problem}", :priority => 1, :title => "Errbit Notification", :url => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}", :url_title => "Link to error") + + 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 eaec410..fb21e7c 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 hipchat hoiio).each do |t| +%w(campfire hipchat hoiio pushover).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/pushover_service_spec.rb b/spec/models/notification_service/pushover_service_spec.rb new file mode 100644 index 0000000..115da0f --- /dev/null +++ b/spec/models/notification_service/pushover_service_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe NotificationService::PushoverService do + it "it should send a notification to Pushover" do + # setup + notice = Fabricate :notice + notification_service = Fabricate :pushover_notification_service, :app => notice.app + problem = notice.problem + + # hoi stubbing + notification = mock('PushoverService') + Rushover::Client.stub(:new).and_return(notification) + notification.stub(:notify) { true } + + #assert + notification.should_receive(:notify) + + notification_service.create_notification(problem) + end +end \ No newline at end of file -- libgit2 0.21.2