diff --git a/app/models/notification_services/hubot_service.rb b/app/models/notification_services/hubot_service.rb new file mode 100644 index 0000000..80f8cd9 --- /dev/null +++ b/app/models/notification_services/hubot_service.rb @@ -0,0 +1,36 @@ +class NotificationServices::HubotService < NotificationService + Label = "hubot" + Fields = [ + [:api_token, { + :placeholder => 'http://hubot.example.org:8080/hubot/say', + :label => 'Hubot URL' + }], + [:room_id, { + :placeholder => '#dev', + :label => 'Room where Hubot should notify' + }] + ] + + def check_params + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, 'You must specify the URL of your hubot' + end + end + + def url + api_token + end + + def message_for_hubot(problem) + notification_description(problem) + end + + def create_notification(problem) + + Faraday.post(url, :message => message_for_hubot(problem), :room => room_id) + # 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 + diff --git a/spec/models/notification_service/hubot_service_spec.rb b/spec/models/notification_service/hubot_service_spec.rb new file mode 100644 index 0000000..cb32dd6 --- /dev/null +++ b/spec/models/notification_service/hubot_service_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe NotificationService::HubotService do + it "it should send a notification to Hubot" do + # setup + notice = Fabricate :notice + notification_service = Fabricate :hubot_notification_service, :app => notice.app + problem = notice.problem + + # faraday stubbing + Faraday.should_receive(:post).with(notification_service.api_token, {:message => '[production][foo#bar] FooError: Too Much Bar', :room => notification_service.room_id}).and_return(true) + + notification_service.create_notification(problem) + end +end -- libgit2 0.21.2