Commit e4a1b610bf794794cd056b7f374142ee3e921ef2
Exists in
master
and in
1 other branch
Merge pull request #267 from shukydvir/issue_148
added support for Hoiio SMS service
Showing
9 changed files
with
71 additions
and
2 deletions
Show diff stats
Gemfile
| @@ -44,6 +44,7 @@ gem 'octokit', '~> 1.0.0' | @@ -44,6 +44,7 @@ gem 'octokit', '~> 1.0.0' | ||
| 44 | gem 'campy' | 44 | gem 'campy' |
| 45 | # Hipchat | 45 | # Hipchat |
| 46 | gem 'hipchat' | 46 | gem 'hipchat' |
| 47 | +gem 'hoi' | ||
| 47 | 48 | ||
| 48 | # Authentication | 49 | # Authentication |
| 49 | # --------------------------------------- | 50 | # --------------------------------------- |
| @@ -69,6 +70,7 @@ group :development, :test do | @@ -69,6 +70,7 @@ group :development, :test do | ||
| 69 | gem 'ruby-debug', :platform => :mri_18 | 70 | gem 'ruby-debug', :platform => :mri_18 |
| 70 | gem 'debugger', :platform => :mri_19 | 71 | gem 'debugger', :platform => :mri_19 |
| 71 | gem 'pry' | 72 | gem 'pry' |
| 73 | + gem 'pry-rails' | ||
| 72 | end | 74 | end |
| 73 | # gem 'rpm_contrib' | 75 | # gem 'rpm_contrib' |
| 74 | # gem 'newrelic_rpm' | 76 | # gem 'newrelic_rpm' |
Gemfile.lock
| @@ -99,6 +99,9 @@ GEM | @@ -99,6 +99,9 @@ GEM | ||
| 99 | hike (1.2.1) | 99 | hike (1.2.1) |
| 100 | hipchat (0.4.1) | 100 | hipchat (0.4.1) |
| 101 | httparty | 101 | httparty |
| 102 | + hoi (0.0.6) | ||
| 103 | + httparty (> 0.6.0) | ||
| 104 | + json (> 1.4.0) | ||
| 102 | hoptoad_notifier (2.4.11) | 105 | hoptoad_notifier (2.4.11) |
| 103 | activesupport | 106 | activesupport |
| 104 | builder | 107 | builder |
| @@ -201,6 +204,8 @@ GEM | @@ -201,6 +204,8 @@ GEM | ||
| 201 | coderay (~> 1.0.5) | 204 | coderay (~> 1.0.5) |
| 202 | method_source (~> 0.7.1) | 205 | method_source (~> 0.7.1) |
| 203 | slop (>= 2.4.4, < 3) | 206 | slop (>= 2.4.4, < 3) |
| 207 | + pry-rails (0.2.0) | ||
| 208 | + pry | ||
| 204 | rack (1.4.1) | 209 | rack (1.4.1) |
| 205 | rack-cache (1.2) | 210 | rack-cache (1.2) |
| 206 | rack (>= 0.4) | 211 | rack (>= 0.4) |
| @@ -316,6 +321,7 @@ DEPENDENCIES | @@ -316,6 +321,7 @@ DEPENDENCIES | ||
| 316 | fabrication (~> 1.3.0) | 321 | fabrication (~> 1.3.0) |
| 317 | haml | 322 | haml |
| 318 | hipchat | 323 | hipchat |
| 324 | + hoi | ||
| 319 | hoptoad_notifier (~> 2.4) | 325 | hoptoad_notifier (~> 2.4) |
| 320 | htmlentities (~> 4.3.0) | 326 | htmlentities (~> 4.3.0) |
| 321 | inherited_resources | 327 | inherited_resources |
| @@ -333,6 +339,7 @@ DEPENDENCIES | @@ -333,6 +339,7 @@ DEPENDENCIES | ||
| 333 | oruen_redmine_client | 339 | oruen_redmine_client |
| 334 | pivotal-tracker | 340 | pivotal-tracker |
| 335 | pry | 341 | pry |
| 342 | + pry-rails | ||
| 336 | rack-ssl | 343 | rack-ssl |
| 337 | rack-ssl-enforcer | 344 | rack-ssl-enforcer |
| 338 | rails (= 3.2.8) | 345 | rails (= 3.2.8) |
1.72 KB
1.72 KB
874 Bytes
app/models/notification_service.rb
| @@ -7,7 +7,8 @@ class NotificationService | @@ -7,7 +7,8 @@ class NotificationService | ||
| 7 | field :room_id, :type => String | 7 | field :room_id, :type => String |
| 8 | field :api_token, :type => String | 8 | field :api_token, :type => String |
| 9 | field :subdomain, :type => String | 9 | field :subdomain, :type => String |
| 10 | - | 10 | + field :sender_name, :type => String |
| 11 | + | ||
| 11 | embedded_in :app, :inverse_of => :notification_service | 12 | embedded_in :app, :inverse_of => :notification_service |
| 12 | 13 | ||
| 13 | validate :check_params | 14 | validate :check_params |
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +class NotificationServices::HoiioService < NotificationService | ||
| 2 | + Label = "hoiio" | ||
| 3 | + Fields = [ | ||
| 4 | + [:api_token, { | ||
| 5 | + :placeholder => "App ID", | ||
| 6 | + :label => "App ID" | ||
| 7 | + }], | ||
| 8 | + [:subdomain, { | ||
| 9 | + :placeholder => "Access Token", | ||
| 10 | + :label => "Access Token" | ||
| 11 | + }], | ||
| 12 | + [:room_id, { | ||
| 13 | + :placeholder => "+6511111111, +6511111111", | ||
| 14 | + :label => "Recipient's phone numbers seperated by comma. Phone numbers should start with a \"+\" and country code." | ||
| 15 | + }] | ||
| 16 | + ] | ||
| 17 | + | ||
| 18 | + def check_params | ||
| 19 | + if Fields.detect {|f| self[f[0]].blank? } | ||
| 20 | + errors.add :base, 'You must specify your App ID, Access Token and Recipient\'s phone numbers' | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + def notification_description(problem) | ||
| 25 | + "[#{ problem.environment }]#{problem.message.to_s.truncate(50)}" | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + def create_notification(problem) | ||
| 29 | + # build the hoi client | ||
| 30 | + sms = Hoi::SMS.new(api_token, subdomain) | ||
| 31 | + | ||
| 32 | + # send sms | ||
| 33 | + room_id.split(',').each do |number| | ||
| 34 | + sms.send :dest => number, :msg => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}" | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | + end | ||
| 38 | +end | ||
| 0 | \ No newline at end of file | 39 | \ No newline at end of file |
spec/fabricators/notification_service_fabricator.rb
| @@ -5,6 +5,6 @@ Fabricator :notification_service do | @@ -5,6 +5,6 @@ Fabricator :notification_service do | ||
| 5 | subdomain { sequence :word } | 5 | subdomain { sequence :word } |
| 6 | end | 6 | end |
| 7 | 7 | ||
| 8 | -%w(campfire hipchat).each do |t| | 8 | +%w(campfire hipchat hoiio).each do |t| |
| 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" | 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
| 10 | end | 10 | end |
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe NotificationService::HoiioService do | ||
| 4 | + it "it should send a notification to hoiio" do | ||
| 5 | + # setup | ||
| 6 | + notice = Fabricate :notice | ||
| 7 | + notification_service = Fabricate :hoiio_notification_service, :app => notice.app | ||
| 8 | + problem = notice.problem | ||
| 9 | + | ||
| 10 | + # hoi stubbing | ||
| 11 | + sms = mock('HoiioService') | ||
| 12 | + Hoi::SMS.stub(:new).and_return(sms) | ||
| 13 | + sms.stub(:send) { true } | ||
| 14 | + | ||
| 15 | + #assert | ||
| 16 | + sms.should_receive(:send) | ||
| 17 | + | ||
| 18 | + notification_service.create_notification(problem) | ||
| 19 | + end | ||
| 20 | +end | ||
| 21 | + |