campfire-bot-absentee-camper 0.1.0 → 0.2.0
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/CHANGELOG.md +7 -0
- data/Gemfile +0 -1
- data/lib/campfire_bot/absentee_camper.rb +1 -1
- data/lib/campfire_bot/absentee_camper/notification/notification_manager.rb +10 -3
- data/lib/campfire_bot/absentee_camper/version.rb +1 -1
- data/spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb +3 -4
- data/spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb +18 -10
- data/spec/lib/campfire_bot/absentee_camper_spec.rb +4 -4
- data/spec/spec_helper.rb +3 -1
- metadata +73 -46
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -29,7 +29,7 @@ module CampfireBot
|
|
29
29
|
|
30
30
|
# If the user isn't in the room, fire off a notification
|
31
31
|
unless room.users.map { |u| u['id'] }.include? user_id_from_config(mentioned)
|
32
|
-
NotificationManager.new(
|
32
|
+
NotificationManager.new(msg, plugin_config['users'][mentioned]).send_notifications
|
33
33
|
room.speak("[Notified #{mentioned}]")
|
34
34
|
end
|
35
35
|
end
|
@@ -3,7 +3,10 @@ module CampfireBot
|
|
3
3
|
module Notification
|
4
4
|
class NotificationManager
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(message, user_config)
|
7
|
+
@message = message
|
8
|
+
room = message[:room]
|
9
|
+
|
7
10
|
if user_config.is_a?(Hash) and user_config['notification_methods']
|
8
11
|
user_config['notification_methods'].each do |notifier, initialization_info|
|
9
12
|
add_notifier Notification.const_get("#{notifier}Notifier".to_sym).new(room, initialization_info)
|
@@ -17,12 +20,16 @@ module CampfireBot
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
def send_notifications
|
21
|
-
@notifiers.each { |notifier| notifier.notify message }
|
23
|
+
def send_notifications
|
24
|
+
@notifiers.each { |notifier| notifier.notify format_message(@message) }
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
25
28
|
|
29
|
+
def format_message(message)
|
30
|
+
"#{message[:person]} says: #{message[:message]}"
|
31
|
+
end
|
32
|
+
|
26
33
|
def add_notifier(notifier)
|
27
34
|
@notifiers ||= []
|
28
35
|
@notifiers << notifier
|
@@ -5,7 +5,6 @@ module CampfireBot
|
|
5
5
|
module Notification
|
6
6
|
describe EmailNotifier do
|
7
7
|
|
8
|
-
let(:email_address) { "johnny@test.com" }
|
9
8
|
let(:uri) { 'http://www.google.com' }
|
10
9
|
let(:body) do
|
11
10
|
body = <<-BODY
|
@@ -16,7 +15,7 @@ Come back to the campfire! We're having a good time telling ghost stories! Her
|
|
16
15
|
#{uri}
|
17
16
|
BODY
|
18
17
|
end
|
19
|
-
let(:message) { "this is a test" }
|
18
|
+
let(:message) { "Jon Levin says: this is a test" }
|
20
19
|
let(:user_id) { 1 }
|
21
20
|
let(:email_address) { 'jon.levin@shredders-r-us.com' }
|
22
21
|
let(:room) do
|
@@ -41,7 +40,7 @@ BODY
|
|
41
40
|
it "logs a message indicating the message is being sent" do
|
42
41
|
Pony.stub(:mail)
|
43
42
|
Logger.instance.should_receive(:debug).with("sending email to #{email_address}")
|
44
|
-
subject.notify
|
43
|
+
subject.notify message
|
45
44
|
end
|
46
45
|
|
47
46
|
it "sends the email with the correct information" do
|
@@ -50,7 +49,7 @@ BODY
|
|
50
49
|
:body => body
|
51
50
|
}.merge(pony_options))
|
52
51
|
|
53
|
-
subject.notify
|
52
|
+
subject.notify message
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -6,6 +6,13 @@ module CampfireBot
|
|
6
6
|
describe NotificationManager do
|
7
7
|
let(:room) { double('room').as_null_object }
|
8
8
|
let(:user_id) { 1 }
|
9
|
+
let(:message) do
|
10
|
+
{
|
11
|
+
:person => "Chad Boyd",
|
12
|
+
:message => "test",
|
13
|
+
:room => room
|
14
|
+
}
|
15
|
+
end
|
9
16
|
|
10
17
|
before(:all) do
|
11
18
|
NotificationManager.send :public, :add_notifier
|
@@ -103,12 +110,12 @@ module CampfireBot
|
|
103
110
|
|
104
111
|
it "logs a message" do
|
105
112
|
Logger.instance.should_receive(:debug).with(log_message)
|
106
|
-
NotificationManager.new(
|
113
|
+
NotificationManager.new(message, user_info)
|
107
114
|
end
|
108
115
|
|
109
116
|
it "creates an EmailNotifier by default" do
|
110
117
|
EmailNotifier.should_receive(:new).with(room, user_info)
|
111
|
-
NotificationManager.new(
|
118
|
+
NotificationManager.new(message, user_info)
|
112
119
|
end
|
113
120
|
end
|
114
121
|
end
|
@@ -118,7 +125,8 @@ module CampfireBot
|
|
118
125
|
let(:user_info) do
|
119
126
|
{ 'id' => user_id }
|
120
127
|
end
|
121
|
-
let(:
|
128
|
+
let(:user_name) { "Chad" }
|
129
|
+
let(:formatted_message) { "#{message[:person]} says: #{message[:message]}" }
|
122
130
|
|
123
131
|
context "when there is only one notifier" do
|
124
132
|
before do
|
@@ -127,8 +135,8 @@ module CampfireBot
|
|
127
135
|
|
128
136
|
it "only sends one notification" do
|
129
137
|
ProwlNotifier.any_instance.should_receive(:notify)
|
130
|
-
manager = NotificationManager.new(
|
131
|
-
manager.send_notifications
|
138
|
+
manager = NotificationManager.new(message, user_info)
|
139
|
+
manager.send_notifications
|
132
140
|
end
|
133
141
|
end
|
134
142
|
|
@@ -143,15 +151,15 @@ module CampfireBot
|
|
143
151
|
it "only sends one notification" do
|
144
152
|
ProwlNotifier.any_instance.should_receive(:notify)
|
145
153
|
EmailNotifier.any_instance.should_receive(:notify)
|
146
|
-
manager = NotificationManager.new(
|
147
|
-
manager.send_notifications
|
154
|
+
manager = NotificationManager.new(message, user_info)
|
155
|
+
manager.send_notifications
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
151
159
|
it "sends the correct message" do
|
152
|
-
EmailNotifier.any_instance.should_receive(:notify).with(
|
153
|
-
manager = NotificationManager.new(
|
154
|
-
manager.send_notifications
|
160
|
+
EmailNotifier.any_instance.should_receive(:notify).with(formatted_message)
|
161
|
+
manager = NotificationManager.new(message, user_id)
|
162
|
+
manager.send_notifications
|
155
163
|
end
|
156
164
|
end
|
157
165
|
end
|
@@ -91,11 +91,11 @@ module CampfireBot
|
|
91
91
|
|
92
92
|
NotificationManager
|
93
93
|
.should_receive(:new)
|
94
|
-
.with(
|
94
|
+
.with(message, users_in_config[name])
|
95
95
|
.and_return(notification_manager)
|
96
96
|
end
|
97
97
|
|
98
|
-
notification_manager.should_receive(:send_notifications).
|
98
|
+
notification_manager.should_receive(:send_notifications).exactly(times).times
|
99
99
|
subject.role_call message
|
100
100
|
end
|
101
101
|
end
|
@@ -130,10 +130,10 @@ module CampfireBot
|
|
130
130
|
def sends_notification_to(name)
|
131
131
|
NotificationManager
|
132
132
|
.should_receive(:new)
|
133
|
-
.with(
|
133
|
+
.with(message, users_in_config[name])
|
134
134
|
.and_return(notification_manager)
|
135
135
|
|
136
|
-
notification_manager.should_receive(:send_notifications)
|
136
|
+
notification_manager.should_receive(:send_notifications)
|
137
137
|
end
|
138
138
|
|
139
139
|
def does_not_send_notification
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "bundler/setup"
|
3
3
|
Bundler.require(:default, :test)
|
4
|
-
require 'ruby-debug'
|
5
4
|
|
6
5
|
BOT_ROOT = File.join(FileUtils.pwd, 'spec')
|
7
6
|
BOT_ENVIRONMENT = 'test'
|
@@ -11,6 +10,9 @@ require 'absentee_camper'
|
|
11
10
|
RSpec.configure do |config|
|
12
11
|
config.include CampfireBot::AbsenteeCamper::Notification
|
13
12
|
config.include CampfireBot::AbsenteeCamper::Config
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.filter_run focus: true
|
15
|
+
config.run_all_when_everything_filtered = true
|
14
16
|
|
15
17
|
config.before do
|
16
18
|
CampfireBot::AbsenteeCamper::Logger.stub(:instance).and_return(double('logger').as_null_object)
|
metadata
CHANGED
@@ -1,60 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: campfire-bot-absentee-camper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- hoverlover
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2011-12-07 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: campfire-bot
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- 1
|
21
32
|
version: 0.0.1
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: pony
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
40
|
+
requirements:
|
30
41
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 3
|
46
|
+
version: "1.3"
|
33
47
|
type: :runtime
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
37
50
|
name: prowl
|
38
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
53
|
none: false
|
40
|
-
requirements:
|
54
|
+
requirements:
|
41
55
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 1
|
60
|
+
- 3
|
43
61
|
version: 0.1.3
|
44
62
|
type: :runtime
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
a user that is @mentioned if they aren't present.
|
49
|
-
email:
|
63
|
+
version_requirements: *id003
|
64
|
+
description: Plugin for campfire-bot that monitors incoming messages and notifies a user that is @mentioned if they aren't present.
|
65
|
+
email:
|
50
66
|
- hoverlover@gmail.com
|
51
67
|
executables: []
|
68
|
+
|
52
69
|
extensions: []
|
70
|
+
|
53
71
|
extra_rdoc_files: []
|
54
|
-
|
72
|
+
|
73
|
+
files:
|
55
74
|
- .gitignore
|
56
75
|
- .rspec
|
57
76
|
- .travis.yml
|
77
|
+
- CHANGELOG.md
|
58
78
|
- Gemfile
|
59
79
|
- Guardfile
|
60
80
|
- README.md
|
@@ -75,32 +95,39 @@ files:
|
|
75
95
|
- spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb
|
76
96
|
- spec/lib/campfire_bot/absentee_camper_spec.rb
|
77
97
|
- spec/spec_helper.rb
|
78
|
-
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: ""
|
79
100
|
licenses: []
|
101
|
+
|
80
102
|
post_install_message:
|
81
103
|
rdoc_options: []
|
82
|
-
|
104
|
+
|
105
|
+
require_paths:
|
83
106
|
- lib/campfire_bot
|
84
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
108
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
116
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
96
123
|
requirements: []
|
124
|
+
|
97
125
|
rubyforge_project: campfire-bot-absentee-camper
|
98
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.3.7
|
99
127
|
signing_key:
|
100
128
|
specification_version: 3
|
101
|
-
summary: Plugin for campfire-bot that monitors incoming messages and notifies a user
|
102
|
-
|
103
|
-
test_files:
|
129
|
+
summary: Plugin for campfire-bot that monitors incoming messages and notifies a user that is @mentioned if they aren't present.
|
130
|
+
test_files:
|
104
131
|
- spec/absentee-camper-config.yml
|
105
132
|
- spec/config.yml
|
106
133
|
- spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb
|