campfire-bot-absentee-camper 0.0.1
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/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +11 -0
- data/Guardfile +9 -0
- data/README.md +100 -0
- data/Rakefile +5 -0
- data/absentee-camper-config.example.yml +24 -0
- data/campfire-bot-absentee-camper.gemspec +24 -0
- data/lib/campfire_bot/absentee_camper.rb +55 -0
- data/lib/campfire_bot/absentee_camper/config.rb +24 -0
- data/lib/campfire_bot/absentee_camper/logger.rb +11 -0
- data/lib/campfire_bot/absentee_camper/notification/email_notifier.rb +41 -0
- data/lib/campfire_bot/absentee_camper/notification/notification_manager.rb +33 -0
- data/lib/campfire_bot/absentee_camper/notification/prowl_notifier.rb +26 -0
- data/lib/campfire_bot/absentee_camper/version.rb +5 -0
- data/spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb +59 -0
- data/spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb +160 -0
- data/spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb +47 -0
- data/spec/spec_helper.rb +14 -0
- metadata +104 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# NOTE
|
2
|
+
|
3
|
+
Currently, this only works with [my fork](https://github.com/hoverlover/campfire-bot). Hopefully,
|
4
|
+
the maintainers of the [main repo](https://github.com/joshwand/campfire-bot) will pull in my changes.
|
5
|
+
|
6
|
+
#CampfireBot::AbsenteeCamper [](http://travis-ci.org/hoverlover/campfire-bot-absentee-camper)
|
7
|
+
|
8
|
+
This is a plugin for use with [campfire-bot](https://github.com/joshwand/campfire-bot).
|
9
|
+
It will monitor a Campfire room for _@mentions_, and notify the
|
10
|
+
mentioned users using one of the built-in notifiers (email by default)
|
11
|
+
if they aren't present in the room. Multiple users
|
12
|
+
can be mentioned in one Campfire message, and each user will receive one
|
13
|
+
notification. The notification will contain the message that was
|
14
|
+
triggered by the _@mention_.
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
1. First, make sure you install the campfire-bot gem.
|
19
|
+
2. `gem install campfire-bot-absentee-camper`
|
20
|
+
3. Create Gemfile with the following lines:
|
21
|
+
gem 'campfire-bot'
|
22
|
+
gem 'campfire-bot-absentee-camper'
|
23
|
+
4. Create your _absentee-camper-config.yml_ file (see below).
|
24
|
+
5. Register the plugin to your main _config.yml_ file
|
25
|
+
6. `bundle exec bot <environment>`, where `<environment>` is the
|
26
|
+
matching environment from the config file.
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
Here is a sample config file:
|
31
|
+
|
32
|
+
---
|
33
|
+
production:
|
34
|
+
pony_options:
|
35
|
+
# NOTE: The colons before these options are very important.
|
36
|
+
# Pony requires that the keys be symbols and not strings.
|
37
|
+
#
|
38
|
+
:from: Absentee Camper <no-reply@your-company.com>
|
39
|
+
:subject: "[Campfire] People are talking about you!"
|
40
|
+
:via: :smtp
|
41
|
+
:via_options:
|
42
|
+
:address: smtp.sendgrid.net
|
43
|
+
:port: 587
|
44
|
+
:enable_starttls_auto: true
|
45
|
+
:authentication: plain
|
46
|
+
:user_name: your-user-name
|
47
|
+
:password: secret
|
48
|
+
users:
|
49
|
+
# User with custom (and possibly multiple) notifiers
|
50
|
+
chad:
|
51
|
+
id: 1234567
|
52
|
+
notification_methods:
|
53
|
+
Prowl: your-prowl-api-key
|
54
|
+
# Default email notifier
|
55
|
+
john: 987654
|
56
|
+
|
57
|
+
* `production` - This is the environment for which the settins apply.
|
58
|
+
You can specify multiple environments (e.g. development, test, etc).
|
59
|
+
* `pony_options` - The configuration options for [Pony](https://github.com/adamwiggins/pony)
|
60
|
+
* `users` - Each user line consists of the name of the mention name and
|
61
|
+
that user's corresponding 37Signals Campfire user ID. One way to get
|
62
|
+
this user ID is to log into Campfire as a user that has admin privileges,
|
63
|
+
click on the _Users_ tab, and then hover over the _change_ link of the
|
64
|
+
user for which you want to find the user ID and take note of the number
|
65
|
+
in the path (e.g. https://_your-company_.campfirenow.com/member/12345/permissions).
|
66
|
+
For example, if you have a user named John Smith with a
|
67
|
+
user ID of 12345, and you want to be able to mention them as _@john_,
|
68
|
+
the users line in the config file would be `john: 12345`.
|
69
|
+
* `notification_methods` - Alternate notification methods. Currently,
|
70
|
+
the only notification method other than the default (email) is Prowl.
|
71
|
+
|
72
|
+
## TODO
|
73
|
+
|
74
|
+
* More specs!
|
75
|
+
* Provide context in the notification. For example, in a Campfire
|
76
|
+
session there are two users: John and Steve. Another user, Chad
|
77
|
+
is not present in the room:
|
78
|
+
|
79
|
+
John Smith: Hey Steve. I am having a problem with the build.
|
80
|
+
Steve Stallion: Hey John. I don't know anything about that. You
|
81
|
+
should ask @chad. That's his department.
|
82
|
+
John Smith: Oh, I thought you were the one that handled that. OK,
|
83
|
+
I will wait for Chad's response.
|
84
|
+
|
85
|
+
Currently, the email notification that Absentee Camper sends out will
|
86
|
+
only contain the second message, which doesn't have any context about
|
87
|
+
what was being discussed. It would be nice to set some configuration
|
88
|
+
variables that indicated you wanted to include context in the
|
89
|
+
notification message, and how many lines on either side to include.
|
90
|
+
|
91
|
+
## Testing
|
92
|
+
|
93
|
+
You have two options:
|
94
|
+
|
95
|
+
* run `bundle exec rake`
|
96
|
+
* run `bundle exec guard` for continuous feedback
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
Do the usual fork -> change -> pull request dance.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
production:
|
3
|
+
pony_options:
|
4
|
+
# NOTE: The colons before these options are very important.
|
5
|
+
# Pony requires that the keys be symbols and not strings.
|
6
|
+
#
|
7
|
+
:from: Absentee Camper <no-reply@your-company.com>
|
8
|
+
:subject: "[Campfire] People are talking about you!"
|
9
|
+
:via: :smtp
|
10
|
+
:via_options:
|
11
|
+
:address: smtp.sendgrid.net
|
12
|
+
:port: 587
|
13
|
+
:enable_starttls_auto: true
|
14
|
+
:authentication: plain
|
15
|
+
:user_name: your-user-name
|
16
|
+
:password: secret
|
17
|
+
users:
|
18
|
+
# User with custom (and possibly multiple) notifiers
|
19
|
+
chad:
|
20
|
+
id: 1234567
|
21
|
+
notification_methods:
|
22
|
+
Prowl: your-prowl-api-key
|
23
|
+
# Default email notifier
|
24
|
+
john: 987654
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "campfire_bot/absentee_camper/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "campfire-bot-absentee-camper"
|
7
|
+
s.version = CampfireBot::AbsenteeCamper::VERSION
|
8
|
+
s.authors = ["hoverlover"]
|
9
|
+
s.email = ["hoverlover@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Plugin for campfire-bot that monitors incoming messages and notifies a user that is @mentioned if they aren't present.}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = "campfire-bot-absentee-camper"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib/campfire_bot"]
|
20
|
+
|
21
|
+
s.add_dependency 'campfire-bot', '~> 0.0.1'
|
22
|
+
s.add_dependency 'pony', '~> 1.3'
|
23
|
+
s.add_dependency 'prowl', '~> 0.1.3'
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module CampfireBot
|
2
|
+
module AbsenteeCamper
|
3
|
+
autoload :Config, "absentee_camper/config"
|
4
|
+
autoload :Logger, "absentee_camper/logger"
|
5
|
+
autoload :NotificationManager, "absentee_camper/notification/notification_manager"
|
6
|
+
|
7
|
+
module Notification
|
8
|
+
autoload :EmailNotifier, "absentee_camper/notification/email_notifier"
|
9
|
+
autoload :ProwlNotifier, "absentee_camper/notification/prowl_notifier"
|
10
|
+
end
|
11
|
+
|
12
|
+
class Plugin < CampfireBot::Plugin
|
13
|
+
include Notification
|
14
|
+
include Config
|
15
|
+
|
16
|
+
on_message /@\w+/i, :role_call
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
Logger.instance.log = bot.log
|
20
|
+
end
|
21
|
+
|
22
|
+
def role_call(msg)
|
23
|
+
room = msg[:room]
|
24
|
+
|
25
|
+
body = msg['body']
|
26
|
+
body.scan(/@\w+/).each do |mention|
|
27
|
+
mentioned = mention[1..-1]
|
28
|
+
if plugin_config['users'].keys.include? mentioned
|
29
|
+
# If the user isn't in the room, fire off a notification
|
30
|
+
unless room.users.map { |u| u['id'] }.include? user_id_from_config(mentioned)
|
31
|
+
NotificationManager.new(room, plugin_config['users'][mentioned]).send_notifications body
|
32
|
+
room.speak("[Notified #{mentioned}]")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def user_id_from_config(mentioned)
|
41
|
+
if plugin_config['users'][mentioned].is_a? Hash
|
42
|
+
plugin_config['users'][mentioned]['id']
|
43
|
+
else
|
44
|
+
plugin_config['users'][mentioned]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Helpers
|
50
|
+
def room_uri(room)
|
51
|
+
"https://#{root_config['site']}.campfirenow.com/room/#{room.id}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CampfireBot
|
2
|
+
module AbsenteeCamper
|
3
|
+
module Config
|
4
|
+
|
5
|
+
def root_config
|
6
|
+
bot.config
|
7
|
+
end
|
8
|
+
|
9
|
+
def plugin_config
|
10
|
+
PluginConfig.instance.config
|
11
|
+
end
|
12
|
+
|
13
|
+
class PluginConfig
|
14
|
+
include Singleton
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
self.config = YAML::load(ERB.new(File.read("#{BOT_ROOT}/absentee-camper-config.yml")).result)[BOT_ENVIRONMENT]
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :config
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pony'
|
2
|
+
|
3
|
+
module CampfireBot
|
4
|
+
module AbsenteeCamper
|
5
|
+
module Notification
|
6
|
+
class EmailNotifier
|
7
|
+
include Config
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
def initialize(room, user_id)
|
11
|
+
@email_address = room.user(user_id)['email_address']
|
12
|
+
@room = room
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify(message)
|
16
|
+
Logger.instance.debug "sending email to #{@email_address}"
|
17
|
+
Pony.mail({
|
18
|
+
:to => @email_address,
|
19
|
+
:body => email_body(message)
|
20
|
+
}.merge(pony_options))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def email_body(message)
|
26
|
+
body = <<-BODY
|
27
|
+
Come back to the campfire! We're having a good time telling ghost stories! Here's one you missed:
|
28
|
+
|
29
|
+
#{message}
|
30
|
+
|
31
|
+
#{room_uri(@room)}
|
32
|
+
BODY
|
33
|
+
end
|
34
|
+
|
35
|
+
def pony_options
|
36
|
+
plugin_config['pony_options']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CampfireBot
|
2
|
+
module AbsenteeCamper
|
3
|
+
module Notification
|
4
|
+
class NotificationManager
|
5
|
+
|
6
|
+
def initialize(room, user_config)
|
7
|
+
if user_config.is_a?(Hash) and user_config['notification_methods']
|
8
|
+
user_config['notification_methods'].each do |notifier, initialization_info|
|
9
|
+
add_notifier Notification.const_get("#{notifier}Notifier".to_sym).new(room, initialization_info)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
# Everyone gets Email notifications if no other notifier is defined.
|
13
|
+
# In this case, user_config is the user_id.
|
14
|
+
|
15
|
+
Logger.instance.debug "No notification methods defined. Falling back to email notifications."
|
16
|
+
@notifiers = [EmailNotifier.new(room, user_config)]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_notifications(message)
|
21
|
+
@notifiers.each { |notifier| notifier.notify message }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def add_notifier(notifier)
|
27
|
+
@notifiers ||= []
|
28
|
+
@notifiers << notifier
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'prowl'
|
2
|
+
|
3
|
+
module CampfireBot
|
4
|
+
module AbsenteeCamper
|
5
|
+
module Notification
|
6
|
+
class ProwlNotifier
|
7
|
+
include Config
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
def initialize(room, api_key)
|
11
|
+
@api_key = api_key
|
12
|
+
@room = room
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify(message)
|
16
|
+
Logger.instance.debug "sending prowl notification"
|
17
|
+
Prowl.add(:apikey => @api_key,
|
18
|
+
:application => 'Campfire',
|
19
|
+
:event => @room.name,
|
20
|
+
:description => message,
|
21
|
+
:url => room_uri(@room))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CampfireBot
|
4
|
+
module AbsenteeCamper
|
5
|
+
module Notification
|
6
|
+
describe EmailNotifier do
|
7
|
+
|
8
|
+
let(:email_address) { "johnny@test.com" }
|
9
|
+
let(:uri) { 'http://www.google.com' }
|
10
|
+
let(:body) do
|
11
|
+
body = <<-BODY
|
12
|
+
Come back to the campfire! We're having a good time telling ghost stories! Here's one you missed:
|
13
|
+
|
14
|
+
#{message}
|
15
|
+
|
16
|
+
#{uri}
|
17
|
+
BODY
|
18
|
+
end
|
19
|
+
let(:message) { "this is a test" }
|
20
|
+
let(:user_id) { 1 }
|
21
|
+
let(:email_address) { 'jon.levin@shredders-r-us.com' }
|
22
|
+
let(:room) do
|
23
|
+
room = double('room').as_null_object
|
24
|
+
room.stub(:user).with(user_id).and_return({ 'email_address' => email_address })
|
25
|
+
room
|
26
|
+
end
|
27
|
+
let(:pony_options) { { :via => :smtp } }
|
28
|
+
|
29
|
+
before do
|
30
|
+
subject.stub(:room_uri).and_return(uri)
|
31
|
+
EmailNotifier.any_instance.stub(:room_uri).and_return(uri)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe :notify do
|
35
|
+
subject { EmailNotifier.new(room, user_id) }
|
36
|
+
|
37
|
+
before do
|
38
|
+
subject.stub(:plugin_config).and_return({'pony_options' => pony_options })
|
39
|
+
end
|
40
|
+
|
41
|
+
it "logs a message indicating the message is being sent" do
|
42
|
+
Pony.stub(:mail)
|
43
|
+
Logger.instance.should_receive(:debug).with("sending email to #{email_address}")
|
44
|
+
subject.notify(message)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sends the email with the correct information" do
|
48
|
+
Pony.should_receive(:mail).with({
|
49
|
+
:to => email_address,
|
50
|
+
:body => body
|
51
|
+
}.merge(pony_options))
|
52
|
+
|
53
|
+
subject.notify(message)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CampfireBot
|
4
|
+
module AbsenteeCamper
|
5
|
+
module Notification
|
6
|
+
describe NotificationManager do
|
7
|
+
let(:room) { double('room').as_null_object }
|
8
|
+
let(:user_id) { 1 }
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
NotificationManager.send :public, :add_notifier
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
NotificationManager.send :private, :add_notifier
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "creating the NotificationManager" do
|
19
|
+
let(:prowl_api_key) { "abcde" }
|
20
|
+
|
21
|
+
context "when the user_info is a Hash" do
|
22
|
+
let(:user_info) do
|
23
|
+
{ 'id' => user_id }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "and contains only one notification method" do
|
27
|
+
before do
|
28
|
+
user_info['notification_methods'] = { 'Prowl' => prowl_api_key }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates the correct type of notifier" do
|
32
|
+
ProwlNotifier.should_receive(:new).with(room, prowl_api_key)
|
33
|
+
NotificationManager.new(room, user_info)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "only creates one notifier" do
|
37
|
+
Notification
|
38
|
+
.should_receive(:const_get)
|
39
|
+
.once
|
40
|
+
.and_return(ProwlNotifier)
|
41
|
+
|
42
|
+
NotificationManager.new(room, user_info)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "adds the notifier to the list of notifiers" do
|
46
|
+
NotificationManager.any_instance.should_receive(:add_notifier).with(an_instance_of(ProwlNotifier))
|
47
|
+
NotificationManager.new(room, user_info)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "and contains more than one notification method" do
|
52
|
+
before do
|
53
|
+
user_info['notification_methods'] = {
|
54
|
+
'Prowl' => prowl_api_key,
|
55
|
+
'Email' => user_id
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
it "creates the correct types of notifiers" do
|
60
|
+
ProwlNotifier.should_receive(:new).with(room, prowl_api_key)
|
61
|
+
EmailNotifier.should_receive(:new).with(room, user_id)
|
62
|
+
|
63
|
+
NotificationManager.new(room, user_info)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "creates the correct number of notifiers" do
|
67
|
+
Notification
|
68
|
+
.should_receive(:const_get)
|
69
|
+
.exactly(user_info['notification_methods'].size)
|
70
|
+
.times
|
71
|
+
.and_return(ProwlNotifier, EmailNotifier)
|
72
|
+
|
73
|
+
NotificationManager.new(room, user_info)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "adds the notifiers to the list of notifiers" do
|
77
|
+
# I really don't like the way I'm testing this. Seems
|
78
|
+
# hacky. I want to do something like this:
|
79
|
+
#
|
80
|
+
# NotificationManager
|
81
|
+
# .any_instance
|
82
|
+
# .should_receive(:add_notifier)
|
83
|
+
# .once.with(an_instance_of(ProwlNotifier))
|
84
|
+
# .once.with(an_instance_of(EmailNotifier))
|
85
|
+
#
|
86
|
+
# but, this doesn't work.
|
87
|
+
|
88
|
+
with_prowl, with_email = false
|
89
|
+
NotificationManager.any_instance.should_receive(:add_notifier).twice { |notifier|
|
90
|
+
with_prowl = true if notifier.is_a? ProwlNotifier
|
91
|
+
with_email = true if notifier.is_a? EmailNotifier
|
92
|
+
}
|
93
|
+
|
94
|
+
NotificationManager.new(room, user_info)
|
95
|
+
with_prowl.should be_true
|
96
|
+
with_email.should be_true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "and the user_info is not a Hash" do
|
101
|
+
let(:user_info) { user_id }
|
102
|
+
let(:log_message) { "No notification methods defined. Falling back to email notifications." }
|
103
|
+
|
104
|
+
it "logs a message" do
|
105
|
+
Logger.instance.should_receive(:debug).with(log_message)
|
106
|
+
NotificationManager.new(room, user_info)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "creates an EmailNotifier by default" do
|
110
|
+
EmailNotifier.should_receive(:new).with(room, user_info)
|
111
|
+
NotificationManager.new(room, user_info)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "sending notifications" do
|
118
|
+
let(:user_info) do
|
119
|
+
{ 'id' => user_id }
|
120
|
+
end
|
121
|
+
let(:message) { "test" }
|
122
|
+
|
123
|
+
context "when there is only one notifier" do
|
124
|
+
before do
|
125
|
+
user_info['notification_methods'] = { 'Prowl' => 'abcde' }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "only sends one notification" do
|
129
|
+
ProwlNotifier.any_instance.should_receive(:notify)
|
130
|
+
manager = NotificationManager.new(room, user_info)
|
131
|
+
manager.send_notifications message
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when there are multiple notifiers" do
|
136
|
+
before do
|
137
|
+
user_info['notification_methods'] = {
|
138
|
+
'Prowl' => 'abcde',
|
139
|
+
'Email' => user_id
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
it "only sends one notification" do
|
144
|
+
ProwlNotifier.any_instance.should_receive(:notify)
|
145
|
+
EmailNotifier.any_instance.should_receive(:notify)
|
146
|
+
manager = NotificationManager.new(room, user_info)
|
147
|
+
manager.send_notifications message
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "sends the correct message" do
|
152
|
+
EmailNotifier.any_instance.should_receive(:notify).with(message)
|
153
|
+
manager = NotificationManager.new(room, user_id)
|
154
|
+
manager.send_notifications message
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CampfireBot
|
4
|
+
module AbsenteeCamper
|
5
|
+
module Notification
|
6
|
+
describe ProwlNotifier do
|
7
|
+
let(:api_key) { '123456789' }
|
8
|
+
let(:application) { 'Campfire' }
|
9
|
+
let(:event) { 'Mentioned' }
|
10
|
+
let(:message) { 'testing 1 2 3' }
|
11
|
+
let(:uri) { 'http://www.google.com' }
|
12
|
+
let(:room) do
|
13
|
+
room = double('room').as_null_object
|
14
|
+
room.stub(:name).and_return(event)
|
15
|
+
room
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { ProwlNotifier.new(room, api_key) }
|
19
|
+
|
20
|
+
before do
|
21
|
+
subject.stub(:room_uri).and_return(uri)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :notify do
|
25
|
+
|
26
|
+
it "logs a message indicating the message is being sent" do
|
27
|
+
Prowl.stub(:add)
|
28
|
+
Logger.instance.should_receive(:debug).with('sending prowl notification')
|
29
|
+
subject.notify(message)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sends the Prowl message" do
|
33
|
+
Prowl.should_receive(:add).with({
|
34
|
+
:apikey => api_key,
|
35
|
+
:application => application,
|
36
|
+
:event => event,
|
37
|
+
:description => message,
|
38
|
+
:url => uri
|
39
|
+
})
|
40
|
+
|
41
|
+
subject.notify(message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
|
5
|
+
BOT_ROOT = '..'
|
6
|
+
BOT_ENVIRONMENT = 'test'
|
7
|
+
require 'bot'
|
8
|
+
require 'absentee_camper'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.before do
|
12
|
+
CampfireBot::AbsenteeCamper::Logger.stub(:instance).and_return(double('logger').as_null_object)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: campfire-bot-absentee-camper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- hoverlover
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: campfire-bot
|
16
|
+
requirement: &70151619075160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70151619075160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pony
|
27
|
+
requirement: &70151619063060 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.3'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70151619063060
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: prowl
|
38
|
+
requirement: &70151619062520 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.3
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70151619062520
|
47
|
+
description: Plugin for campfire-bot that monitors incoming messages and notifies
|
48
|
+
a user that is @mentioned if they aren't present.
|
49
|
+
email:
|
50
|
+
- hoverlover@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rspec
|
57
|
+
- .travis.yml
|
58
|
+
- Gemfile
|
59
|
+
- Guardfile
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- absentee-camper-config.example.yml
|
63
|
+
- campfire-bot-absentee-camper.gemspec
|
64
|
+
- lib/campfire_bot/absentee_camper.rb
|
65
|
+
- lib/campfire_bot/absentee_camper/config.rb
|
66
|
+
- lib/campfire_bot/absentee_camper/logger.rb
|
67
|
+
- lib/campfire_bot/absentee_camper/notification/email_notifier.rb
|
68
|
+
- lib/campfire_bot/absentee_camper/notification/notification_manager.rb
|
69
|
+
- lib/campfire_bot/absentee_camper/notification/prowl_notifier.rb
|
70
|
+
- lib/campfire_bot/absentee_camper/version.rb
|
71
|
+
- spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb
|
72
|
+
- spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb
|
73
|
+
- spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib/campfire_bot
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: campfire-bot-absentee-camper
|
95
|
+
rubygems_version: 1.8.10
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Plugin for campfire-bot that monitors incoming messages and notifies a user
|
99
|
+
that is @mentioned if they aren't present.
|
100
|
+
test_files:
|
101
|
+
- spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb
|
102
|
+
- spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb
|
103
|
+
- spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb
|
104
|
+
- spec/spec_helper.rb
|