babysitter 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/babysitter/configuration.rb +0 -4
- data/lib/babysitter/exception_notifiers/simple_notification_service.rb +12 -6
- data/lib/babysitter/version.rb +1 -1
- data/spec/lib/babysitter/configuration_spec.rb +1 -17
- data/spec/lib/babysitter/exception_notifiers/simple_notification_service_spec.rb +13 -0
- metadata +2 -2
@@ -14,10 +14,6 @@ module Babysitter
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def enable_simple_notification_service(opts = {})
|
17
|
-
[:access_key_id, :secret_access_key, :topic_arn].each do |key|
|
18
|
-
raise ArgumentError, "#{key} is required" unless opts.has_key?(key)
|
19
|
-
end
|
20
|
-
|
21
17
|
@exception_notifiers << ExceptionNotifiers::SimpleNotificationService.new(opts)
|
22
18
|
end
|
23
19
|
|
@@ -3,16 +3,22 @@ require 'aws-sdk'
|
|
3
3
|
module Babysitter
|
4
4
|
module ExceptionNotifiers
|
5
5
|
class SimpleNotificationService
|
6
|
-
def initialize(opts)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@
|
6
|
+
def initialize(opts = {})
|
7
|
+
topic_arn = opts.delete(:topic_arn)
|
8
|
+
raise ArgumentError, "topic_arn is required." if topic_arn.nil?
|
9
|
+
|
10
|
+
@sns = AWS::SNS.new(opts)
|
11
|
+
@topic = @sns.topics[topic_arn]
|
11
12
|
validate_topic
|
12
13
|
end
|
13
14
|
|
14
15
|
def notify(subject, msg)
|
15
|
-
|
16
|
+
sanitised_subject = if subject.size > 100
|
17
|
+
subject[0..96] + "..."
|
18
|
+
else
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
@topic.publish(msg, subject: sanitised_subject)
|
16
22
|
end
|
17
23
|
|
18
24
|
private
|
data/lib/babysitter/version.rb
CHANGED
@@ -20,8 +20,7 @@ module Babysitter
|
|
20
20
|
describe 'enabling Amazon simple notification service integration' do
|
21
21
|
let (:sns_exception_notifier) { double }
|
22
22
|
let (:valid_params) { {
|
23
|
-
|
24
|
-
secret_access_key: "a-secret-address-key",
|
23
|
+
arbritary_key: "some-value",
|
25
24
|
topic_arn: "my-topic-arn"
|
26
25
|
} }
|
27
26
|
|
@@ -29,21 +28,6 @@ module Babysitter
|
|
29
28
|
Babysitter::ExceptionNotifiers::SimpleNotificationService.stub(:new).and_return(sns_exception_notifier)
|
30
29
|
end
|
31
30
|
|
32
|
-
it 'requires an access key id' do
|
33
|
-
valid_params.delete :access_key_id
|
34
|
-
-> { subject.enable_simple_notification_service(valid_params) }.should raise_error(ArgumentError, /access_key_id/)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'requires a secret address key' do
|
38
|
-
valid_params.delete :secret_access_key
|
39
|
-
-> { subject.enable_simple_notification_service(valid_params) }.should raise_error(ArgumentError, /secret_access_key/)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'requires a topic arn' do
|
43
|
-
valid_params.delete :topic_arn
|
44
|
-
-> { subject.enable_simple_notification_service(valid_params) }.should raise_error(ArgumentError, /topic_arn/)
|
45
|
-
end
|
46
|
-
|
47
31
|
it 'adds an exception notifier' do
|
48
32
|
subject.enable_simple_notification_service(valid_params)
|
49
33
|
|
@@ -15,6 +15,10 @@ module Babysitter
|
|
15
15
|
AWS::SNS.stub(:new).and_return(sns)
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'requires a topic_arn' do
|
19
|
+
-> { SimpleNotificationService.new() }.should raise_error(ArgumentError, /topic_arn/)
|
20
|
+
end
|
21
|
+
|
18
22
|
it 'uses the options passed to configure the credentials for sns' do
|
19
23
|
AWS::SNS.should_receive(:new).with(valid_opts.reject { |key| key == :topic_arn } )
|
20
24
|
subject
|
@@ -40,6 +44,15 @@ module Babysitter
|
|
40
44
|
|
41
45
|
subject.notify(notification_subject, message)
|
42
46
|
end
|
47
|
+
|
48
|
+
it "shortens the subject to 100 characters if necessary" do
|
49
|
+
shortened_subject = 97.times.map { "x" }.join + "..."
|
50
|
+
original_subject = 101.times.map { "x" }.join
|
51
|
+
|
52
|
+
topic.should_receive(:publish).with(message, hash_including(subject: shortened_subject))
|
53
|
+
|
54
|
+
subject.notify(original_subject, message)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
45
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babysitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: fozzie
|