From 537c7e708b9cf2c2939b9ed0265c61451bfb5d92 Mon Sep 17 00:00:00 2001 From: Shuky Dvir Date: Fri, 5 Oct 2012 10:07:27 +0300 Subject: [PATCH] adding support for hoiio sms notification service - issue #148 --- Gemfile | 2 ++ Gemfile.lock | 7 +++++++ app/assets/images/hoiio_create.png | Bin 0 -> 1758 bytes app/assets/images/hoiio_goto.png | Bin 0 -> 1758 bytes app/assets/images/hoiio_inactive.png | Bin 0 -> 874 bytes app/models/notification_service.rb | 3 ++- app/models/notification_services/hoiio_service.rb | 38 ++++++++++++++++++++++++++++++++++++++ spec/fabricators/notification_service_fabricator.rb | 2 +- spec/models/notification_service/hoiio_service_spec.rb | 21 +++++++++++++++++++++ 9 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 app/assets/images/hoiio_create.png create mode 100644 app/assets/images/hoiio_goto.png create mode 100644 app/assets/images/hoiio_inactive.png create mode 100644 app/models/notification_services/hoiio_service.rb create mode 100644 spec/models/notification_service/hoiio_service_spec.rb diff --git a/Gemfile b/Gemfile index 995a004..431554d 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem 'fabrication', "~> 1.3.0" # Both for tests, and loading demo data gem 'rails_autolink', '~> 1.0.9' gem 'campy' gem 'hipchat' +gem 'hoi' # Please don't update this to airbrake - We override the send_notice method # to handle internal errors. @@ -55,6 +56,7 @@ group :development, :test do gem 'ruby-debug', :platform => :mri_18 gem 'debugger', :platform => :mri_19 gem 'pry' + gem 'pry-rails' end # gem 'rpm_contrib' # gem 'newrelic_rpm' diff --git a/Gemfile.lock b/Gemfile.lock index b20d5f3..1e97a36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,9 @@ GEM hike (1.2.1) hipchat (0.4.1) httparty + hoi (0.0.6) + httparty (> 0.6.0) + json (> 1.4.0) hoptoad_notifier (2.4.11) activesupport builder @@ -201,6 +204,8 @@ GEM coderay (~> 1.0.5) method_source (~> 0.7.1) slop (>= 2.4.4, < 3) + pry-rails (0.2.0) + pry rack (1.4.1) rack-cache (1.2) rack (>= 0.4) @@ -316,6 +321,7 @@ DEPENDENCIES fabrication (~> 1.3.0) haml hipchat + hoi hoptoad_notifier (~> 2.4) htmlentities (~> 4.3.0) inherited_resources @@ -332,6 +338,7 @@ DEPENDENCIES oruen_redmine_client pivotal-tracker pry + pry-rails rack-ssl rack-ssl-enforcer rails (= 3.2.8) diff --git a/app/assets/images/hoiio_create.png b/app/assets/images/hoiio_create.png new file mode 100644 index 0000000..e121515 Binary files /dev/null and b/app/assets/images/hoiio_create.png differ diff --git a/app/assets/images/hoiio_goto.png b/app/assets/images/hoiio_goto.png new file mode 100644 index 0000000..e121515 Binary files /dev/null and b/app/assets/images/hoiio_goto.png differ diff --git a/app/assets/images/hoiio_inactive.png b/app/assets/images/hoiio_inactive.png new file mode 100644 index 0000000..b396326 Binary files /dev/null and b/app/assets/images/hoiio_inactive.png differ diff --git a/app/models/notification_service.rb b/app/models/notification_service.rb index 4f73adb..6c88de0 100644 --- a/app/models/notification_service.rb +++ b/app/models/notification_service.rb @@ -7,7 +7,8 @@ class NotificationService field :room_id, :type => String field :api_token, :type => String field :subdomain, :type => String - + field :sender_name, :type => String + embedded_in :app, :inverse_of => :notification_service validate :check_params diff --git a/app/models/notification_services/hoiio_service.rb b/app/models/notification_services/hoiio_service.rb new file mode 100644 index 0000000..755412f --- /dev/null +++ b/app/models/notification_services/hoiio_service.rb @@ -0,0 +1,38 @@ +class NotificationServices::HoiioService < NotificationService + Label = "hoiio" + Fields = [ + [:api_token, { + :placeholder => "App ID", + :label => "App ID" + }], + [:subdomain, { + :placeholder => "Access Token", + :label => "Access Token" + }], + [:room_id, { + :placeholder => "+6511111111, +6511111111", + :label => "Recipient's phone numbers seperated by comma. Phone numbers should start with a \"+\" and country code." + }] + ] + + def check_params + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, 'You must specify your App ID, Access Token and Recipient\'s phone numbers' + end + end + + def notification_description(problem) + "[#{ problem.environment }]#{problem.message.to_s.truncate(50)}" + end + + def create_notification(problem) + # build the hoi client + sms = Hoi::SMS.new(api_token, subdomain) + + # send sms + room_id.split(',').each do |number| + sms.send :dest => number, :msg => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}" + end + + 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 a1c2ac0..eaec410 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).each do |t| +%w(campfire hipchat hoiio).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/hoiio_service_spec.rb b/spec/models/notification_service/hoiio_service_spec.rb new file mode 100644 index 0000000..2eb7033 --- /dev/null +++ b/spec/models/notification_service/hoiio_service_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe NotificationService::HoiioService do + it "it should send a notification to hoiio" do + # setup + notice = Fabricate :notice + notification_service = Fabricate :hoiio_notification_service, :app => notice.app + problem = notice.problem + + # hoi stubbing + sms = mock('HoiioService') + Hoi::SMS.stub(:new).and_return(sms) + sms.stub(:send) { true } + + #assert + sms.should_receive(:send) + + notification_service.create_notification(problem) + end +end + -- libgit2 0.21.2