campfire_chat 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/campfire_chat +21 -0
- data/campfire_chat.gemspec +27 -0
- data/lib/campfire_chat.rb +19 -0
- data/lib/campfire_chat/checks.rb +18 -0
- data/lib/campfire_chat/checks/pair_message.rb +20 -0
- data/lib/campfire_chat/client.rb +32 -0
- data/lib/campfire_chat/configuration.rb +30 -0
- data/lib/campfire_chat/engineer.rb +9 -0
- data/lib/campfire_chat/message.rb +11 -0
- data/lib/campfire_chat/monitor.rb +56 -0
- data/lib/campfire_chat/notification.rb +51 -0
- data/lib/campfire_chat/notifier/growl.rb +27 -0
- data/lib/campfire_chat/version.rb +3 -0
- data/notes.txt +7 -0
- data/spec/fixtures/campfire.yml +4 -0
- data/spec/lib/campfire_chat/checks/pair_message_spec.rb +34 -0
- data/spec/lib/campfire_chat/checks_spec.rb +20 -0
- data/spec/lib/campfire_chat/client_spec.rb +61 -0
- data/spec/lib/campfire_chat/configuration_spec.rb +46 -0
- data/spec/lib/campfire_chat/engineer_spec.rb +11 -0
- data/spec/lib/campfire_chat/message_spec.rb +24 -0
- data/spec/lib/campfire_chat/monitor_spec.rb +85 -0
- data/spec/lib/campfire_chat/notification_spec.rb +71 -0
- data/spec/lib/campfire_chat/notifier/growl_spec.rb +15 -0
- data/spec/spec_helper.rb +27 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7adbda79939752b58f8a50c20e2fe70c8f443af
|
4
|
+
data.tar.gz: 8d1fcb826b80add159346ea4eed7dec26d1247b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce7231f38939e362eff142f85f37f91977d738040201bd36ef3fbd594f2b78977d5467754a0b9496f9a9663f4738af44cc181126af6555e26447ab02175fddb3
|
7
|
+
data.tar.gz: 0fe85245e61629bf896e77cffd9e843b2b70d8e5b9321c422218911c5592cd1a85655868d0eb43ac57ecb1cb70b604ff8b5ea89341884e7680cc1792cb68d18a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Richard Luther
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# CampfireChat
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'campfire_chat'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install campfire_chat
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/campfire_chat
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'campfire_chat'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: campfire_chat [Names seperated by spaces] [options]"
|
11
|
+
end.parse!
|
12
|
+
|
13
|
+
raise RuntimeError.new("growlnotify is required to run campfire_chat") if `which growlnotify`.empty?
|
14
|
+
|
15
|
+
pairs = ARGV
|
16
|
+
|
17
|
+
pairs.each do |pair|
|
18
|
+
CampfireChat.config.add_pair pair
|
19
|
+
end
|
20
|
+
|
21
|
+
CampfireChat::Monitor.run
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'campfire_chat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "campfire_chat"
|
8
|
+
spec.version = CampfireChat::VERSION
|
9
|
+
spec.authors = ["Richard Luther"]
|
10
|
+
spec.email = ["richard.luther@gmail.com"]
|
11
|
+
spec.description = %q{Monitor a campfire room for messages to notify via growl}
|
12
|
+
spec.summary = %q{Monitor a campfire room for messages to notify via growl}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'tinder'
|
22
|
+
spec.add_dependency 'growl'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'time' #getting an error with Tinder "#undefined method parse for Time
|
3
|
+
require "campfire_chat/version"
|
4
|
+
require 'campfire_chat/engineer'
|
5
|
+
require 'campfire_chat/client'
|
6
|
+
require 'campfire_chat/configuration'
|
7
|
+
require 'campfire_chat/message'
|
8
|
+
require 'campfire_chat/monitor'
|
9
|
+
require 'campfire_chat/checks'
|
10
|
+
require 'campfire_chat/checks/pair_message'
|
11
|
+
require 'campfire_chat/notification'
|
12
|
+
require 'campfire_chat/notifier/growl'
|
13
|
+
|
14
|
+
module CampfireChat
|
15
|
+
def self.config
|
16
|
+
@config ||= Configuration.build
|
17
|
+
end
|
18
|
+
# Your code goes here...
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CampfireChat
|
2
|
+
module Checks
|
3
|
+
def self.extended(base)
|
4
|
+
checks << base
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.checks
|
8
|
+
@checks ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.process(notification)
|
12
|
+
checks.each do |check|
|
13
|
+
check.process_notification(notification)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CampfireChat
|
2
|
+
module Checks
|
3
|
+
module PairMessage
|
4
|
+
extend CampfireChat::Checks
|
5
|
+
|
6
|
+
def self.process_notification(notification)
|
7
|
+
CampfireChat.config.pairs.each do |pair|
|
8
|
+
if notification.message.body.include?(pair.name)
|
9
|
+
notification.important!
|
10
|
+
notification.add_title title(pair)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.title(pair)
|
16
|
+
"#{pair.name}:"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'tinder'
|
2
|
+
module CampfireChat
|
3
|
+
class Client
|
4
|
+
attr_reader :config
|
5
|
+
attr_accessor :last_message_id
|
6
|
+
def initialize(config = CampfireChat.config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def tinder
|
11
|
+
@tinder ||= Tinder::Campfire.new(config.subdomain, :token => config.token)
|
12
|
+
end
|
13
|
+
|
14
|
+
def messages
|
15
|
+
recent_messages = room.recent.select {|x| x.type == 'TextMessage' }
|
16
|
+
recent_messages = recent_messages.select {|x| x.id.to_i > last_message_id.to_i }.map {|m| build_message(m) }
|
17
|
+
self.last_message_id = recent_messages.last.id unless recent_messages.empty?
|
18
|
+
recent_messages
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_message(msg)
|
24
|
+
CampfireChat::Message.new(msg)
|
25
|
+
end
|
26
|
+
|
27
|
+
def room
|
28
|
+
@room ||= tinder.find_room_by_name(config.room)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module CampfireChat
|
3
|
+
class Configuration
|
4
|
+
attr_reader :token, :room, :subdomain, :pairs
|
5
|
+
|
6
|
+
def self.build(path = nil)
|
7
|
+
path ||= Pathname.new(ENV['HOME']).join('.campfire.yml')
|
8
|
+
new load_config(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load_config(path)
|
12
|
+
conf = YAML.load_file(path) || {}
|
13
|
+
Hash[conf.map{ |k, v| [k.to_sym, v] }]
|
14
|
+
rescue Errno::ENOENT, TypeError
|
15
|
+
{}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(attrs={})
|
19
|
+
@token = attrs[:token]
|
20
|
+
@subdomain = attrs[:subdomain]
|
21
|
+
@room = attrs[:room]
|
22
|
+
@pairs = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_pair(name)
|
26
|
+
pairs << CampfireChat::Engineer.new(:name => name)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module CampfireChat
|
2
|
+
class Monitor
|
3
|
+
include Singleton
|
4
|
+
attr_accessor :last_run_time
|
5
|
+
|
6
|
+
def self.retry_time
|
7
|
+
30
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.sleep_time
|
11
|
+
retry_time / 2
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.run
|
15
|
+
instance.run
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
loop do
|
20
|
+
if check_client?
|
21
|
+
check_messages
|
22
|
+
set_last_run_time
|
23
|
+
sleep self.class.sleep_time
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_messages
|
29
|
+
client.messages.each do |message|
|
30
|
+
notification = prepare_notification(message)
|
31
|
+
notifier.push(notification)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_last_run_time
|
36
|
+
self.last_run_time = Time.now
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_client?
|
40
|
+
return true if last_run_time.nil?
|
41
|
+
last_run_time + self.class.retry_time < Time.now
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare_notification(message)
|
45
|
+
CampfireChat::Notification.build(message)
|
46
|
+
end
|
47
|
+
|
48
|
+
def client
|
49
|
+
@client ||= CampfireChat::Client.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def notifier
|
53
|
+
@notifier ||= CampfireChat::Notifier::Growl.instance
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module CampfireChat
|
2
|
+
class Notification
|
3
|
+
attr_reader :message
|
4
|
+
|
5
|
+
def self.build(message)
|
6
|
+
notification = new(message)
|
7
|
+
CampfireChat::Checks.process(notification)
|
8
|
+
notification
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(message)
|
12
|
+
@message = message
|
13
|
+
@additional_messages = []
|
14
|
+
@titles = []
|
15
|
+
@important = false
|
16
|
+
@error = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
(@additional_messages + [message.body]).join("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def <<(more_message)
|
24
|
+
@additional_messages << more_message
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_title(another_title)
|
28
|
+
@titles << another_title
|
29
|
+
end
|
30
|
+
|
31
|
+
def title
|
32
|
+
@titles.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def important?
|
36
|
+
@important
|
37
|
+
end
|
38
|
+
|
39
|
+
def important!
|
40
|
+
@important = true
|
41
|
+
end
|
42
|
+
|
43
|
+
def error!
|
44
|
+
@error = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def error?
|
48
|
+
@error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'growl'
|
2
|
+
module CampfireChat
|
3
|
+
module Notifier
|
4
|
+
class Growl
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def push(notification)
|
8
|
+
notify_ok notification
|
9
|
+
end
|
10
|
+
|
11
|
+
def growl
|
12
|
+
::Growl
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def notify_ok(notification)
|
18
|
+
growl.notify notification.body, :title => notification.title, :sticky => notification.important?, :image => image_path('sr')
|
19
|
+
end
|
20
|
+
|
21
|
+
def image_path(image)
|
22
|
+
File.join(File.expand_path(File.dirname(__FILE__)), '../', 'images', "#{image}.png")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/notes.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Checks::PairMessage do
|
4
|
+
let(:message) { double(:body => 'Fred you broke the build') }
|
5
|
+
let(:notification) { double(:message => message, :important! => true, :<< => nil, :add_title => nil)}
|
6
|
+
let(:config) { double(:pairs => [double(:name => 'Bob')]) }
|
7
|
+
before do
|
8
|
+
CampfireChat.stub(:config => config)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.process_notification' do
|
12
|
+
context 'when the notification contains a name in the pairs' do
|
13
|
+
before do
|
14
|
+
config.pairs << double(:name => 'Fred')
|
15
|
+
end
|
16
|
+
it 'flags the notification as important' do
|
17
|
+
notification.should_receive(:important!)
|
18
|
+
CampfireChat::Checks::PairMessage.process_notification(notification)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'adds additional titles to the notification' do
|
22
|
+
notification.should_receive(:add_title).with("Fred:")
|
23
|
+
CampfireChat::Checks::PairMessage.process_notification(notification)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when the notification does not contain a name in the pairs' do
|
28
|
+
it 'does not flag the notification as important' do
|
29
|
+
notification.should_not_receive(:important!)
|
30
|
+
CampfireChat::Checks::PairMessage.process_notification(notification)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Checks do
|
4
|
+
let(:notification) { double }
|
5
|
+
describe '.process' do
|
6
|
+
module AwesomeCheck
|
7
|
+
extend CampfireChat::Checks
|
8
|
+
|
9
|
+
def self.process_notification(notification)
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sends the notification to all known Check objects' do
|
15
|
+
AwesomeCheck.should_receive(:process_notification).with(notification)
|
16
|
+
CampfireChat::Checks.process(notification)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Client do
|
4
|
+
let(:room) { double(:recent => []) }
|
5
|
+
let(:config) { double(:room => 'room', :subdomain => 'sub', :token => 'token') }
|
6
|
+
let(:tinder_double) { double(:find_room_by_name => room) }
|
7
|
+
let(:client) { described_class.new(config) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Tinder::Campfire.stub(:new => tinder_double)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#tinder' do
|
14
|
+
it 'builds a new tender box object' do
|
15
|
+
Tinder::Campfire.should_receive(:new).with(config.subdomain, :token => config.token)
|
16
|
+
client.tinder
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#messages' do
|
21
|
+
|
22
|
+
it 'returns message objects' do
|
23
|
+
room.stub(:recent => [build_message("Bob", 'another')])
|
24
|
+
client.messages.first.should be_a(CampfireChat::Message)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'stores the last ID of the previous request and only returns the new messages' do
|
28
|
+
raw_messages = [
|
29
|
+
build_message("Bob", "something more"),
|
30
|
+
build_message("Fred", "something else"),
|
31
|
+
build_message("Pete", "something again")
|
32
|
+
]
|
33
|
+
room.stub(:recent => raw_messages)
|
34
|
+
client.last_message_id = raw_messages.first.id
|
35
|
+
messages = client.messages
|
36
|
+
messages.should have(2).message
|
37
|
+
messages.first.id.should == raw_messages[1].id
|
38
|
+
client.last_message_id.should == raw_messages[2].id
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not store a nil ID if there are no new messages' do
|
42
|
+
messages = [
|
43
|
+
build_message("Bob", "something more"),
|
44
|
+
]
|
45
|
+
room.stub(:recent => messages)
|
46
|
+
client.last_message_id = messages.first.id
|
47
|
+
client.last_message_id.should == messages.first.id
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'excludes non TextMessage messages' do
|
51
|
+
raw_messages = [
|
52
|
+
build_message("Bob", "something more"),
|
53
|
+
build_message("Fred", "something else", 'RoomEnter'),
|
54
|
+
]
|
55
|
+
room.stub(:recent => raw_messages)
|
56
|
+
messages = client.messages
|
57
|
+
messages.should have(1).message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Configuration do
|
4
|
+
let(:config_hash) { {:room => 'room', :token => 'token', :subdomain => 'subdomain'} }
|
5
|
+
let(:config) { described_class.new(config_hash) }
|
6
|
+
|
7
|
+
describe '#add_pair' do
|
8
|
+
it 'adds an engineer to the pairs' do
|
9
|
+
config.add_pair 'Fred'
|
10
|
+
config.pairs.should have(1).pair
|
11
|
+
config.pairs.first.name.should == 'Fred'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#room' do
|
16
|
+
it 'returns the campfire room' do
|
17
|
+
config.room.should == config_hash[:room]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#token' do
|
22
|
+
it 'returns the campfire token' do
|
23
|
+
config.token.should == config_hash[:token]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#subdomain' do
|
28
|
+
it 'returns the campfire subdomain' do
|
29
|
+
config.subdomain.should == config_hash[:subdomain]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.build' do
|
34
|
+
context 'when a valid config file is present' do
|
35
|
+
let(:path) { fixture_path('campfire.yml') }
|
36
|
+
it 'loads configurations from the YAML file' do
|
37
|
+
config = described_class.build(path)
|
38
|
+
config.room.should == 'some room'
|
39
|
+
config.token.should == 'the-token'
|
40
|
+
config.subdomain.should == 'the-subdomain'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Engineer do
|
4
|
+
let(:attributes) { {:name => 'Bob'}}
|
5
|
+
let(:engineer) { described_class.new(attributes) }
|
6
|
+
describe '#name' do
|
7
|
+
it 'returns the name of the engineer' do
|
8
|
+
engineer.name.should == attributes[:name]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Message do
|
4
|
+
let(:raw_message) { build_message("Pete", "something again") }
|
5
|
+
let(:message) { described_class.new(raw_message) }
|
6
|
+
|
7
|
+
describe '#body' do
|
8
|
+
it 'returns the content of the message' do
|
9
|
+
message.body.should == raw_message.body
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#author' do
|
14
|
+
it 'returns the author of the message' do
|
15
|
+
message.author.should == raw_message.user.name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#id' do
|
20
|
+
it 'returns the id of the message' do
|
21
|
+
message.id.should == raw_message.id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Monitor do
|
4
|
+
let(:monitor) { described_class.instance }
|
5
|
+
|
6
|
+
describe '#run' do
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#set_last_run_time' do
|
11
|
+
it 'sets the last run time to now' do
|
12
|
+
Time.stub(:now => 1)
|
13
|
+
monitor.set_last_run_time
|
14
|
+
monitor.last_run_time.should == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#check_client?' do
|
20
|
+
context 'when the last_run_time is nil' do
|
21
|
+
before { monitor.last_run_time = nil }
|
22
|
+
it 'returns true' do
|
23
|
+
monitor.should be_check_client
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when the last_run_time is less than time.now' do
|
28
|
+
before { monitor.last_run_time = Time.now - 1000 }
|
29
|
+
it 'returns true' do
|
30
|
+
monitor.should be_check_client
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when the last_run_time has not exceeded the retry' do
|
35
|
+
before { monitor.last_run_time = Time.now - described_class.retry_time + 1 }
|
36
|
+
it 'returns false' do
|
37
|
+
monitor.should_not be_check_client
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the last_run_time is more than time.now' do
|
42
|
+
before { monitor.last_run_time = Time.now + 100 }
|
43
|
+
it 'returns false' do
|
44
|
+
monitor.should_not be_check_client
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#check_messages' do
|
51
|
+
let(:notifier) { double(:push) }
|
52
|
+
before do
|
53
|
+
monitor.stub(:notifier => notifier)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'loops over the messages and prepares the notification' do
|
57
|
+
notification = double
|
58
|
+
new_message = double
|
59
|
+
monitor.client.stub(:messages => [new_message])
|
60
|
+
monitor.should_receive(:prepare_notification).with(new_message).and_return(notification)
|
61
|
+
notifier.should_receive(:push).with(notification)
|
62
|
+
monitor.check_messages
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#prepare_notification' do
|
67
|
+
it 'builds a new notification object' do
|
68
|
+
message = double
|
69
|
+
CampfireChat::Notification.should_receive(:build).with(message)
|
70
|
+
monitor.prepare_notification(message)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#notifier' do
|
75
|
+
it 'returns the notifier instance' do
|
76
|
+
monitor.notifier.should be_a(CampfireChat::Notifier::Growl)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#client' do
|
81
|
+
it 'returns the client instance' do
|
82
|
+
monitor.client.should be_a(CampfireChat::Client)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Notification do
|
4
|
+
let(:message) { double(:body => 'the body') }
|
5
|
+
let(:notification) { described_class.new(message) }
|
6
|
+
|
7
|
+
describe '#important?' do
|
8
|
+
context 'when default' do
|
9
|
+
it 'returns false' do
|
10
|
+
notification.should_not be_important
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when marked as important' do
|
15
|
+
it 'returns true' do
|
16
|
+
notification.important!
|
17
|
+
notification.should be_important
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#error?' do
|
23
|
+
context 'when default' do
|
24
|
+
it 'returns false' do
|
25
|
+
notification.should_not be_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when marked as error' do
|
30
|
+
it 'returns true' do
|
31
|
+
notification.error!
|
32
|
+
notification.should be_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#<<' do
|
38
|
+
it 'prepends strings to the message body' do
|
39
|
+
notification << 'YO'
|
40
|
+
notification.body.should == "YO\n#{message.body}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#add_title' do
|
45
|
+
it 'adds the title to the list of titles' do
|
46
|
+
notification.add_title 'YO'
|
47
|
+
notification.add_title 'MA'
|
48
|
+
notification.title.should == "YO\nMA"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#body' do
|
53
|
+
it 'returns the message body' do
|
54
|
+
notification.body.should == message.body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.build' do
|
59
|
+
it 'instantiates a new notification from the message' do
|
60
|
+
notification = described_class.build(message)
|
61
|
+
notification.message.should == message
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'passes the notification into the Checks.process method' do
|
65
|
+
notification = double
|
66
|
+
described_class.stub(:new => notification)
|
67
|
+
CampfireChat::Checks.should_receive(:process).with(notification)
|
68
|
+
described_class.build(message)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CampfireChat::Notifier::Growl do
|
4
|
+
let(:notification) { double(:body => 'some message', :title => 'some title', :important? => false, :error? => false) }
|
5
|
+
|
6
|
+
let(:notifier) { described_class.instance }
|
7
|
+
|
8
|
+
describe '#push' do
|
9
|
+
it 'delegates to Growl' do
|
10
|
+
::Growl.should_receive(:notify).with(notification.body, :title => notification.title, :sticky => notification.important?, :image => anything)
|
11
|
+
notifier.push notification
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'campfire_chat'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
|
+
# loaded once.
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
19
|
+
|
20
|
+
def fixture_path(file_name)
|
21
|
+
Pathname.new(File.dirname(__FILE__)).join('fixtures', file_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_message(user, message, type='TextMessage')
|
25
|
+
@message_id ||= 0
|
26
|
+
double(:user => double(:name => user), :body=> message, :user_id=>"1", :id=> @message_id += 1, :type => type)
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: campfire_chat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Luther
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tinder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: growl
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Monitor a campfire room for messages to notify via growl
|
84
|
+
email:
|
85
|
+
- richard.luther@gmail.com
|
86
|
+
executables:
|
87
|
+
- campfire_chat
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/campfire_chat
|
98
|
+
- campfire_chat.gemspec
|
99
|
+
- lib/campfire_chat.rb
|
100
|
+
- lib/campfire_chat/checks.rb
|
101
|
+
- lib/campfire_chat/checks/pair_message.rb
|
102
|
+
- lib/campfire_chat/client.rb
|
103
|
+
- lib/campfire_chat/configuration.rb
|
104
|
+
- lib/campfire_chat/engineer.rb
|
105
|
+
- lib/campfire_chat/message.rb
|
106
|
+
- lib/campfire_chat/monitor.rb
|
107
|
+
- lib/campfire_chat/notification.rb
|
108
|
+
- lib/campfire_chat/notifier/growl.rb
|
109
|
+
- lib/campfire_chat/version.rb
|
110
|
+
- notes.txt
|
111
|
+
- spec/fixtures/campfire.yml
|
112
|
+
- spec/lib/campfire_chat/checks/pair_message_spec.rb
|
113
|
+
- spec/lib/campfire_chat/checks_spec.rb
|
114
|
+
- spec/lib/campfire_chat/client_spec.rb
|
115
|
+
- spec/lib/campfire_chat/configuration_spec.rb
|
116
|
+
- spec/lib/campfire_chat/engineer_spec.rb
|
117
|
+
- spec/lib/campfire_chat/message_spec.rb
|
118
|
+
- spec/lib/campfire_chat/monitor_spec.rb
|
119
|
+
- spec/lib/campfire_chat/notification_spec.rb
|
120
|
+
- spec/lib/campfire_chat/notifier/growl_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: ''
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.0.3
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Monitor a campfire room for messages to notify via growl
|
146
|
+
test_files:
|
147
|
+
- spec/fixtures/campfire.yml
|
148
|
+
- spec/lib/campfire_chat/checks/pair_message_spec.rb
|
149
|
+
- spec/lib/campfire_chat/checks_spec.rb
|
150
|
+
- spec/lib/campfire_chat/client_spec.rb
|
151
|
+
- spec/lib/campfire_chat/configuration_spec.rb
|
152
|
+
- spec/lib/campfire_chat/engineer_spec.rb
|
153
|
+
- spec/lib/campfire_chat/message_spec.rb
|
154
|
+
- spec/lib/campfire_chat/monitor_spec.rb
|
155
|
+
- spec/lib/campfire_chat/notification_spec.rb
|
156
|
+
- spec/lib/campfire_chat/notifier/growl_spec.rb
|
157
|
+
- spec/spec_helper.rb
|