Commit 537c7e708b9cf2c2939b9ed0265c61451bfb5d92
1 parent
f761cda4
Exists in
master
and in
1 other branch
adding support for hoiio sms notification service - issue #148
Showing
9 changed files
with
71 additions
and
2 deletions
Show diff stats
Gemfile
... | ... | @@ -34,6 +34,7 @@ gem 'fabrication', "~> 1.3.0" # Both for tests, and loading demo data |
34 | 34 | gem 'rails_autolink', '~> 1.0.9' |
35 | 35 | gem 'campy' |
36 | 36 | gem 'hipchat' |
37 | +gem 'hoi' | |
37 | 38 | |
38 | 39 | # Please don't update this to airbrake - We override the send_notice method |
39 | 40 | # to handle internal errors. |
... | ... | @@ -55,6 +56,7 @@ group :development, :test do |
55 | 56 | gem 'ruby-debug', :platform => :mri_18 |
56 | 57 | gem 'debugger', :platform => :mri_19 |
57 | 58 | gem 'pry' |
59 | + gem 'pry-rails' | |
58 | 60 | end |
59 | 61 | # gem 'rpm_contrib' |
60 | 62 | # gem 'newrelic_rpm' | ... | ... |
Gemfile.lock
... | ... | @@ -99,6 +99,9 @@ GEM |
99 | 99 | hike (1.2.1) |
100 | 100 | hipchat (0.4.1) |
101 | 101 | httparty |
102 | + hoi (0.0.6) | |
103 | + httparty (> 0.6.0) | |
104 | + json (> 1.4.0) | |
102 | 105 | hoptoad_notifier (2.4.11) |
103 | 106 | activesupport |
104 | 107 | builder |
... | ... | @@ -201,6 +204,8 @@ GEM |
201 | 204 | coderay (~> 1.0.5) |
202 | 205 | method_source (~> 0.7.1) |
203 | 206 | slop (>= 2.4.4, < 3) |
207 | + pry-rails (0.2.0) | |
208 | + pry | |
204 | 209 | rack (1.4.1) |
205 | 210 | rack-cache (1.2) |
206 | 211 | rack (>= 0.4) |
... | ... | @@ -316,6 +321,7 @@ DEPENDENCIES |
316 | 321 | fabrication (~> 1.3.0) |
317 | 322 | haml |
318 | 323 | hipchat |
324 | + hoi | |
319 | 325 | hoptoad_notifier (~> 2.4) |
320 | 326 | htmlentities (~> 4.3.0) |
321 | 327 | inherited_resources |
... | ... | @@ -332,6 +338,7 @@ DEPENDENCIES |
332 | 338 | oruen_redmine_client |
333 | 339 | pivotal-tracker |
334 | 340 | pry |
341 | + pry-rails | |
335 | 342 | rack-ssl |
336 | 343 | rack-ssl-enforcer |
337 | 344 | 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 | field :room_id, :type => String |
8 | 8 | field :api_token, :type => String |
9 | 9 | field :subdomain, :type => String |
10 | - | |
10 | + field :sender_name, :type => String | |
11 | + | |
11 | 12 | embedded_in :app, :inverse_of => :notification_service |
12 | 13 | |
13 | 14 | validate :check_params | ... | ... |
... | ... | @@ -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 | 39 | \ No newline at end of file | ... | ... |
spec/fabricators/notification_service_fabricator.rb
... | ... | @@ -5,6 +5,6 @@ Fabricator :notification_service do |
5 | 5 | subdomain { sequence :word } |
6 | 6 | end |
7 | 7 | |
8 | -%w(campfire hipchat).each do |t| | |
8 | +%w(campfire hipchat hoiio).each do |t| | |
9 | 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
10 | 10 | end | ... | ... |
... | ... | @@ -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 | + | ... | ... |