scamp-campfire 1.0.0.pre
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 +9 -0
- data/Gemfile +5 -0
- data/LICENCE.md +20 -0
- data/README.md +45 -0
- data/Rakefile +13 -0
- data/examples/v2.rb +29 -0
- data/lib/scamp-campfire.rb +6 -0
- data/lib/scamp-campfire/adapter.rb +76 -0
- data/lib/scamp-campfire/channel.rb +28 -0
- data/lib/scamp-campfire/message.rb +70 -0
- data/lib/scamp-campfire/users.rb +39 -0
- data/lib/scamp-campfire/version.rb +5 -0
- data/scamp-campfire.gemspec +29 -0
- data/spec/lib/adapter_spec.rb +5 -0
- data/spec/lib/channel_spec.rb +5 -0
- data/spec/lib/message_spec.rb +242 -0
- data/spec/spec_helper.rb +12 -0
- metadata +184 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENCE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Adam Holt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included
|
12
|
+
in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Scamp Campfire Adapter
|
2
|
+
|
3
|
+
This is the campfire adapter for Scamp, the bot framework
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Put this in your gemfile!
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'scamp-campfire'
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
See ./examples
|
17
|
+
|
18
|
+
## How to contribute
|
19
|
+
|
20
|
+
Here's the most direct way to get your work merged into the project:
|
21
|
+
|
22
|
+
1. Fork the project
|
23
|
+
2. Clone down your fork
|
24
|
+
3. Create a feature branch
|
25
|
+
4. Add your feature + tests
|
26
|
+
5. Document new features in the README
|
27
|
+
6. Make sure everything still passes by running the tests
|
28
|
+
7. If necessary, rebase your commits into logical chunks, without errors
|
29
|
+
8. Push the branch up
|
30
|
+
9. Send a pull request for your branch
|
31
|
+
|
32
|
+
Take a look at the TODO list or known issues for some inspiration if you
|
33
|
+
need it.
|
34
|
+
|
35
|
+
## Thanks
|
36
|
+
|
37
|
+
First class support, commits and pull requests, thanks guys!
|
38
|
+
|
39
|
+
* [Adam Holt](http://adamholt.co.uk/)
|
40
|
+
* [Caius Durling](http://caius.name/)
|
41
|
+
* [Will Jessop](http://willj.net/)
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
See LICENSE.md
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
rescue LoadError => e
|
7
|
+
task "spec" do
|
8
|
+
puts "RSpec not loaded - make sure it's installed and you're using bundle exec"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
data/examples/v2.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
require 'scamp'
|
4
|
+
require 'scamp-campfire'
|
5
|
+
|
6
|
+
Scamp.new do |bot|
|
7
|
+
bot.adapter :campfire, Scamp::Campfire::Adapter, :subdomain => 'SUBDOMAIN',
|
8
|
+
:api_key => 'YOUR_API_KEY',
|
9
|
+
:rooms => [123]
|
10
|
+
|
11
|
+
bot.match /^ping/ do |channel, msg|
|
12
|
+
channel.reply "pong"
|
13
|
+
end
|
14
|
+
|
15
|
+
bot.match /^come to the pub (?<name>\w+)/ do |channel, msg|
|
16
|
+
channel.say "ROGER DODGER #{msg.matches.name.upcase}!"
|
17
|
+
channel.reply "ON MY WAY!"
|
18
|
+
channel.paste <<-STR
|
19
|
+
bot.match /^come to the pub (?<name>\w+)/ do |channel, msg|
|
20
|
+
channel.say "ROGER DODGER!"
|
21
|
+
channel.reply "ON MY WAY! #{msg.matches.name}"
|
22
|
+
channel.play(:nyan)
|
23
|
+
end
|
24
|
+
STR
|
25
|
+
channel.play(:nyan)
|
26
|
+
end
|
27
|
+
|
28
|
+
bot.connect!
|
29
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'em-campfire'
|
2
|
+
require 'scamp/adapter'
|
3
|
+
|
4
|
+
class Scamp
|
5
|
+
module Campfire
|
6
|
+
class Adapter < Scamp::Adapter
|
7
|
+
include Scamp::Campfire::Users
|
8
|
+
|
9
|
+
def connect!
|
10
|
+
connection.on_message do |message|
|
11
|
+
if matches_required_format?(message[:body])
|
12
|
+
msg = Scamp::Campfire::Message.new self, :body => strip_prefix(message[:body]),
|
13
|
+
:room_id => message[:room_id],
|
14
|
+
:user_id => message[:user_id],
|
15
|
+
:type => message[:type]
|
16
|
+
|
17
|
+
channel = Scamp::Campfire::Channel.new self, msg
|
18
|
+
push [channel, msg]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@opts[:rooms].each do |room|
|
23
|
+
connection.join(room) do |room_id|
|
24
|
+
pre_populate_user_cache_from_room_data(room_id)
|
25
|
+
connection.stream(room_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def say(message, room_id)
|
31
|
+
connection.say(room_id, message)
|
32
|
+
end
|
33
|
+
|
34
|
+
def paste(message, room_id)
|
35
|
+
connection.paste(room_id, message)
|
36
|
+
end
|
37
|
+
|
38
|
+
def play(sound, room_id)
|
39
|
+
connection.play(room_id, sound)
|
40
|
+
end
|
41
|
+
|
42
|
+
def required_prefix
|
43
|
+
@opts[:required_prefix]
|
44
|
+
end
|
45
|
+
|
46
|
+
def ignore_self?
|
47
|
+
@opts[:ignore_self] || false
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_agent
|
51
|
+
@opts[:user_agent] || "scamp-campfire"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def pre_populate_user_cache_from_room_data(room_id)
|
57
|
+
connection.room_data_from_room_id(room_id) do |room_data|
|
58
|
+
room_data['users'].each do |user_data|
|
59
|
+
cache_data_for_user(user_data['id'], user_data)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def connection
|
65
|
+
@connection ||= EM::Campfire.new(
|
66
|
+
:subdomain => @opts[:subdomain],
|
67
|
+
:api_key => @opts[:api_key],
|
68
|
+
:verbose => @opts[:verbose],
|
69
|
+
:ignore_self => @opts[:ignore_self],
|
70
|
+
:logger => @opts[:logger],
|
71
|
+
:user_agent => user_agent
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Scamp
|
2
|
+
module Campfire
|
3
|
+
class Channel
|
4
|
+
attr_reader :adapter, :message
|
5
|
+
|
6
|
+
def initialize adapter, msg
|
7
|
+
@adapter = adapter
|
8
|
+
@message = msg
|
9
|
+
end
|
10
|
+
|
11
|
+
def say msg
|
12
|
+
adapter.say(message.room_id, msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def reply msg
|
16
|
+
adapter.say(message.room_id, "#{message.user_id}: #{msg}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def paste text
|
20
|
+
adapter.paste(message.room_id, text)
|
21
|
+
end
|
22
|
+
|
23
|
+
def play sound
|
24
|
+
adapter.play(message.room_id, sound.to_s)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'scamp/message'
|
2
|
+
|
3
|
+
class Scamp
|
4
|
+
module Campfire
|
5
|
+
class Message < Scamp::Message
|
6
|
+
def valid?(conditions={})
|
7
|
+
room_match?(conditions[:room]) &&
|
8
|
+
user_match?(conditions[:user])
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches? trigger
|
12
|
+
adapter.bot.logger.debug "Matching message body #{body} against trigger #{trigger}"
|
13
|
+
if adapter.required_prefix
|
14
|
+
if satisfies_required_prefix?
|
15
|
+
msg = body.split(adapter.required_prefix, 2)[1]
|
16
|
+
match? trigger, msg
|
17
|
+
else
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
else
|
21
|
+
match? trigger, body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_name
|
26
|
+
adapter.username_for_user_id(user_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def room_match?(condition)
|
32
|
+
return true if condition.nil?
|
33
|
+
|
34
|
+
if condition.is_a? Array
|
35
|
+
return (condition.include?(room.id) || condition.include?(room.name))
|
36
|
+
elsif condition.is_a? Fixnum
|
37
|
+
return room.id == condition
|
38
|
+
else
|
39
|
+
return room.name.downcase == condition.to_s.downcase
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def user_match?(condition)
|
44
|
+
return true if condition.nil?
|
45
|
+
|
46
|
+
if condition.is_a? Array
|
47
|
+
return (condition.include?(user.id) || condition.include?(user.name))
|
48
|
+
elsif condition.is_a? Fixnum
|
49
|
+
return user.id == condition
|
50
|
+
else
|
51
|
+
return user.name.downcase == condition.to_s.downcase
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def satisfies_required_prefix?
|
56
|
+
if adapter.required_prefix
|
57
|
+
if adapter.required_prefix.is_a? String
|
58
|
+
return true if adapter.required_prefix == body[0...adapter.required_prefix.length]
|
59
|
+
elsif adapter.required_prefix.is_a? Regexp
|
60
|
+
return true if adapter.required_prefix.match body
|
61
|
+
end
|
62
|
+
return false
|
63
|
+
else
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Scamp
|
2
|
+
module Campfire
|
3
|
+
module Users
|
4
|
+
def username_for_user_id(user_id)
|
5
|
+
user_data(user_id)['name'] rescue user_id
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def user_data(user_id)
|
11
|
+
ensure_user_data_is_cached(user_id)
|
12
|
+
puts user_cache.inspect
|
13
|
+
user_cache[user_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def ensure_user_data_is_cached(user_id)
|
17
|
+
user_cache[user_id] || begin
|
18
|
+
puts "Fetching user data for #{user_id}"
|
19
|
+
fetch_and_cache_user_data(user_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_and_cache_user_data(user_id)
|
24
|
+
connection.fetch_user_data_for_user_id(user_id) do |user_data|
|
25
|
+
puts "Setting cache to #{user_data.inspect}"
|
26
|
+
cache_data_for_user(user_id, user_data)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def cache_data_for_user(user_id, user_data_hash)
|
31
|
+
user_cache[user_id] = user_data_hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_cache
|
35
|
+
@user_cache ||= {}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "scamp-campfire/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "scamp-campfire"
|
7
|
+
s.version = Scamp::Campfire::VERSION
|
8
|
+
s.authors = ["Adam Holt", "Will Jessop"]
|
9
|
+
s.email = ["me@adamholt.co.uk", "will@willj.net"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A Campfire adapter for Scamp}
|
12
|
+
s.description = %q{scamp-campfire is an adapter for Scamp that uses the em-campfire lib to provide Campfire support}
|
13
|
+
|
14
|
+
s.rubyforge_project = "scamp-campfire"
|
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"]
|
20
|
+
|
21
|
+
s.add_dependency "em-campfire", '~> 1.1'
|
22
|
+
s.add_dependency "scamp"
|
23
|
+
s.add_dependency "eventmachine", '~> 1.0'
|
24
|
+
|
25
|
+
s.add_development_dependency "rspec"
|
26
|
+
s.add_development_dependency "mocha"
|
27
|
+
s.add_development_dependency "simplecov"
|
28
|
+
s.add_development_dependency "rake"
|
29
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Scamp::Campfire::Message do
|
4
|
+
before :each do
|
5
|
+
Scamp::Campfire::Adapter.any_instance.stubs(:pre_populate_user_cache_from_room_data)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:adapter) { Scamp::Campfire::Adapter.new(stub, {:api_key => "foo", :subdomain => "foo"}) }
|
9
|
+
let(:room) { stub(:id => 1234, :name => "Room") }
|
10
|
+
let(:user) { stub(:id => 1234, :name => "User") }
|
11
|
+
let(:body) { "Hello" }
|
12
|
+
let(:message) { Scamp::Campfire::Message.new(adapter, :body => body, :room => room, :user => user) }
|
13
|
+
|
14
|
+
describe ".matches?" do
|
15
|
+
describe "with string trigger" do
|
16
|
+
it "matches with valid trigger" do
|
17
|
+
message.matches?("Hello").should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not match with invalid trigger" do
|
21
|
+
message.matches?("Goodbye").should be_false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "with regex trigger" do
|
26
|
+
it "matches with valid trigger" do
|
27
|
+
message.matches?(/^Hello/).should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not match with invalid trigger" do
|
31
|
+
message.matches?(/^Goodbye/).should be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "required prefix" do
|
36
|
+
describe "with no prefix" do
|
37
|
+
it "matches" do
|
38
|
+
message.matches?(/^Hello/).should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "with string prefix" do
|
43
|
+
let(:adapter) { Scamp::Campfire::Adapter.new stub, :required_prefix => "User: " }
|
44
|
+
|
45
|
+
context "with valid message" do
|
46
|
+
let(:body) { "User: Hello" }
|
47
|
+
|
48
|
+
it "matches" do
|
49
|
+
message.matches?(/^Hello/).should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with invalid message" do
|
54
|
+
let(:body) { "Another User: Hello" }
|
55
|
+
|
56
|
+
it "does not match" do
|
57
|
+
message.matches?(/^Hello/).should be_false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with regex prefix" do
|
63
|
+
let(:adapter) { Scamp::Campfire::Adapter.new stub, :required_prefix => /^User: / }
|
64
|
+
|
65
|
+
context "with valid prefix" do
|
66
|
+
let(:body) { "User: Hello" }
|
67
|
+
|
68
|
+
it "matches" do
|
69
|
+
message.matches?(/^Hello/).should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with invalid prefix" do
|
74
|
+
let(:body) { "Another User: Hello" }
|
75
|
+
|
76
|
+
it "does not match" do
|
77
|
+
message.matches?(/^Hello/).should be_false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".valid?" do
|
85
|
+
describe "ignoring messages from self" do
|
86
|
+
let(:adapter) { Scamp::Campfire::Adapter.new stub, :ignore_self => true }
|
87
|
+
|
88
|
+
context "when message is from self" do
|
89
|
+
before do
|
90
|
+
adapter.stubs(:user).returns(stub(:id => 1234, :name => "User"))
|
91
|
+
end
|
92
|
+
|
93
|
+
it "is not valid" do
|
94
|
+
message.valid?().should be_false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "message from another user" do
|
99
|
+
before do
|
100
|
+
adapter.stubs(:user).returns(stub(:id => 5678, :name => "Another User"))
|
101
|
+
end
|
102
|
+
|
103
|
+
it "is valid" do
|
104
|
+
message.valid?().should be_true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
describe "matching rooms" do
|
111
|
+
describe "on no room condition" do
|
112
|
+
it "is valid" do
|
113
|
+
message.valid?().should be_true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "on room id" do
|
118
|
+
context "with valid room" do
|
119
|
+
it "is valid with a fixnum" do
|
120
|
+
message.valid?(:room => 1234).should be_true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "is valid with an array" do
|
124
|
+
message.valid?(:room => [1234]).should be_true
|
125
|
+
end
|
126
|
+
|
127
|
+
it "is valid with an array of multiple rooms" do
|
128
|
+
message.valid?(:room => [1234, 5678]).should be_true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with invalid room" do
|
133
|
+
it "is invalid with a fixnum" do
|
134
|
+
message.valid?(:room => 5678).should be_false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "is invalid with an array of fixnums" do
|
138
|
+
message.valid?(:room => [5678, 9012]).should be_false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "on room name" do
|
144
|
+
context "with valid room" do
|
145
|
+
it "is valid with a string" do
|
146
|
+
message.valid?(:room => "Room").should be_true
|
147
|
+
end
|
148
|
+
|
149
|
+
it "is valid with a symbol" do
|
150
|
+
message.valid?(:room => :room).should be_true
|
151
|
+
end
|
152
|
+
|
153
|
+
it "is valid with a string array" do
|
154
|
+
message.valid?(:room => ["Room"]).should be_true
|
155
|
+
end
|
156
|
+
|
157
|
+
it "is valid with a string array of multiple rooms" do
|
158
|
+
message.valid?(:room => ["Room", "Another"]).should be_true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "with invalid room" do
|
163
|
+
it "is invalid with a string" do
|
164
|
+
message.valid?(:room => "Another").should be_false
|
165
|
+
end
|
166
|
+
|
167
|
+
it "is invalid with an array of strings" do
|
168
|
+
message.valid?(:room => ["Another", "One More"]).should be_false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "matching users" do
|
175
|
+
context "on no user condition" do
|
176
|
+
it "is valid" do
|
177
|
+
message.should be_valid
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "on user id" do
|
182
|
+
context "with valid user" do
|
183
|
+
it "is valid with a fixnum" do
|
184
|
+
message.valid?(:user => 1234).should be_true
|
185
|
+
end
|
186
|
+
|
187
|
+
it "is valid with a fixnum array" do
|
188
|
+
message.valid?(:user => [1234]).should be_true
|
189
|
+
end
|
190
|
+
|
191
|
+
it "is valid with a fixnum array of multiple users" do
|
192
|
+
message.valid?(:user => [1234, 5678]).should be_true
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "with invalid user" do
|
197
|
+
it "is invalid with fixnum" do
|
198
|
+
message.valid?(:user => 5678).should be_false
|
199
|
+
end
|
200
|
+
|
201
|
+
it "is invalid with a fixnum array" do
|
202
|
+
message.valid?(:user => [5678]).should be_false
|
203
|
+
end
|
204
|
+
|
205
|
+
it "is invalid with a fixnum array of multiple users" do
|
206
|
+
message.valid?(:user => [5678, 9012]).should be_false
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context "on user user name" do
|
212
|
+
context "with valid user" do
|
213
|
+
it "is valid with string" do
|
214
|
+
message.valid?(:user => "User").should be_true
|
215
|
+
end
|
216
|
+
|
217
|
+
it "is valid with a string array" do
|
218
|
+
message.valid?(:user => ["User"]).should be_true
|
219
|
+
end
|
220
|
+
|
221
|
+
it "is valid with a string array of multiple users" do
|
222
|
+
message.valid?(:user => ["User", "Two"]).should be_true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context "with invalid user" do
|
227
|
+
it "is invalid with string" do
|
228
|
+
message.valid?(:user => "Two").should be_false
|
229
|
+
end
|
230
|
+
|
231
|
+
it "is invalid with a string array" do
|
232
|
+
message.valid?(:user => ["Two"]).should be_false
|
233
|
+
end
|
234
|
+
|
235
|
+
it "is invalid with a string array of multiple users" do
|
236
|
+
message.valid?(:user => ["Two", "Three"]).should be_false
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
2
|
+
require 'scamp-campfire'
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter "/spec/"
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.color_enabled = true
|
11
|
+
config.mock_framework = :mocha
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scamp-campfire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Holt
|
9
|
+
- Will Jessop
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: em-campfire
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.1'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: scamp
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: eventmachine
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: mocha
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: simplecov
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: scamp-campfire is an adapter for Scamp that uses the em-campfire lib
|
128
|
+
to provide Campfire support
|
129
|
+
email:
|
130
|
+
- me@adamholt.co.uk
|
131
|
+
- will@willj.net
|
132
|
+
executables: []
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- .gitignore
|
137
|
+
- Gemfile
|
138
|
+
- LICENCE.md
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- examples/v2.rb
|
142
|
+
- lib/scamp-campfire.rb
|
143
|
+
- lib/scamp-campfire/adapter.rb
|
144
|
+
- lib/scamp-campfire/channel.rb
|
145
|
+
- lib/scamp-campfire/message.rb
|
146
|
+
- lib/scamp-campfire/users.rb
|
147
|
+
- lib/scamp-campfire/version.rb
|
148
|
+
- scamp-campfire.gemspec
|
149
|
+
- spec/lib/adapter_spec.rb
|
150
|
+
- spec/lib/channel_spec.rb
|
151
|
+
- spec/lib/message_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
homepage: ''
|
154
|
+
licenses: []
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
hash: 3060748957179309889
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>'
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.3.1
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project: scamp-campfire
|
176
|
+
rubygems_version: 1.8.23.2
|
177
|
+
signing_key:
|
178
|
+
specification_version: 3
|
179
|
+
summary: A Campfire adapter for Scamp
|
180
|
+
test_files:
|
181
|
+
- spec/lib/adapter_spec.rb
|
182
|
+
- spec/lib/channel_spec.rb
|
183
|
+
- spec/lib/message_spec.rb
|
184
|
+
- spec/spec_helper.rb
|