babysitter 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- access_key = opts.delete :access_key_id
8
- secret_access_key = opts.delete :secret_access_key
9
- @sns = AWS::SNS.new(access_key_id: access_key, secret_access_key: secret_access_key)
10
- @topic = @sns.topics[opts.delete(:topic_arn)]
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
- @topic.publish(msg, subject: subject)
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
@@ -1,3 +1,3 @@
1
1
  module Babysitter
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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
- access_key_id: "an-access-key",
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.6
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-01-29 00:00:00.000000000 Z
15
+ date: 2013-02-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: fozzie