firebot 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +46 -0
- data/MIT-LICENSE +19 -0
- data/README.md +48 -0
- data/Rakefile +13 -0
- data/bin/firebot +6 -0
- data/firebot.gemspec +30 -0
- data/lib/firebot.rb +33 -0
- data/lib/firebot/campfire.rb +36 -0
- data/lib/firebot/cli.rb +48 -0
- data/lib/firebot/cli/config.tt +3 -0
- data/lib/firebot/exceptions.rb +3 -0
- data/lib/firebot/listener.rb +29 -0
- data/lib/firebot/plugin.rb +36 -0
- data/lib/firebot/plugins/ping_pong.rb +19 -0
- data/lib/firebot/runner.rb +32 -0
- data/lib/firebot/settings.rb +38 -0
- data/lib/firebot/tasks.rb +8 -0
- data/lib/firebot/version.rb +3 -0
- data/spec/campfire_spec.rb +42 -0
- data/spec/cli_spec.rb +21 -0
- data/spec/fixtures/config.yml +7 -0
- data/spec/fixtures/sample_response.txt +8 -0
- data/spec/listener_spec.rb +18 -0
- data/spec/runner_spec.rb +7 -0
- data/spec/settings_spec.rb +16 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/attr_switcher.rb +12 -0
- data/spec/support/em_helpers.rb +17 -0
- metadata +171 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
firebot (0.0.1)
|
5
|
+
daemons (~> 1.1.0)
|
6
|
+
faraday (~> 0.5.7)
|
7
|
+
thor (~> 0.14.6)
|
8
|
+
twitter-stream (~> 0.1.10)
|
9
|
+
yajl-ruby (~> 0.8.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: http://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.2.4)
|
15
|
+
daemons (1.1.0)
|
16
|
+
diff-lcs (1.1.2)
|
17
|
+
eventmachine (0.12.10)
|
18
|
+
fakeweb (1.3.0)
|
19
|
+
faraday (0.5.7)
|
20
|
+
addressable (~> 2.2.4)
|
21
|
+
multipart-post (~> 1.1.0)
|
22
|
+
rack (< 2, >= 1.1.0)
|
23
|
+
multipart-post (1.1.0)
|
24
|
+
rack (1.2.2)
|
25
|
+
roauth (0.0.3)
|
26
|
+
rspec (2.5.0)
|
27
|
+
rspec-core (~> 2.5.0)
|
28
|
+
rspec-expectations (~> 2.5.0)
|
29
|
+
rspec-mocks (~> 2.5.0)
|
30
|
+
rspec-core (2.5.1)
|
31
|
+
rspec-expectations (2.5.0)
|
32
|
+
diff-lcs (~> 1.1.2)
|
33
|
+
rspec-mocks (2.5.0)
|
34
|
+
thor (0.14.6)
|
35
|
+
twitter-stream (0.1.12)
|
36
|
+
eventmachine (>= 0.12.8)
|
37
|
+
roauth (>= 0.0.2)
|
38
|
+
yajl-ruby (0.8.1)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
fakeweb (~> 1.3.0)
|
45
|
+
firebot!
|
46
|
+
rspec (~> 2.5.0)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 Marcelo Silveira
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
Firebot
|
2
|
+
=========
|
3
|
+
|
4
|
+
Firebot is a bot for Campfire, the chat application from 37Signals, that offers an extensible
|
5
|
+
interface to programmatically integrate it with other applications/services.
|
6
|
+
|
7
|
+
WARNING
|
8
|
+
-------
|
9
|
+
|
10
|
+
FIREBOT IS UNDER DEVELOPMENT. NO STABLE RELEASE IS AVAILABLE.
|
11
|
+
|
12
|
+
Usage
|
13
|
+
-----
|
14
|
+
|
15
|
+
Firebot comes with its own executable. `firebot` in the terminal
|
16
|
+
gives you its options:
|
17
|
+
|
18
|
+
Tasks:
|
19
|
+
firebot create_config # Create a sample config file in ~/.firebot
|
20
|
+
firebot help [TASK] # Describe available tasks or one specific task
|
21
|
+
firebot start # Startup the Firebot daemon
|
22
|
+
firebot stop # Stop the Firebot daemon
|
23
|
+
|
24
|
+
The steps to get it up and running are:
|
25
|
+
|
26
|
+
1. Run `firebot create_config`
|
27
|
+
2. Tweak the config file in `~/.firebot`
|
28
|
+
3. Run `firebot start`
|
29
|
+
|
30
|
+
Supported Applications/Services
|
31
|
+
-------------------------------
|
32
|
+
|
33
|
+
PingPong: dummy plugin to check the plugins interface.
|
34
|
+
|
35
|
+
Meta
|
36
|
+
----
|
37
|
+
|
38
|
+
* Home: <https://github.com/mhfs/firebot/>
|
39
|
+
|
40
|
+
Author
|
41
|
+
------
|
42
|
+
|
43
|
+
Marcelo Silveira :: marcelo@mhfs.com.br :: @mhfsilveira
|
44
|
+
|
45
|
+
License
|
46
|
+
-------
|
47
|
+
|
48
|
+
Firebot is released under the MIT Licence. Copyright © 2011 Marcelo Silveira.
|
data/Rakefile
ADDED
data/bin/firebot
ADDED
data/firebot.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "firebot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "firebot"
|
7
|
+
s.version = Firebot::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Marcelo Silveira"]
|
10
|
+
s.email = "marcelo@mhfs.com.br"
|
11
|
+
s.homepage = "https://github.com/mhfs/firebot"
|
12
|
+
s.summary = "Extensible Campfire bot to integrate with other applications/services"
|
13
|
+
s.description = "Extensible Campfire bot to integrate with other applications/services"
|
14
|
+
|
15
|
+
s.rubyforge_project = "firebot"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "twitter-stream", "~> 0.1.10"
|
23
|
+
s.add_dependency "faraday", "~> 0.5.7"
|
24
|
+
s.add_dependency "yajl-ruby", "~> 0.8.1"
|
25
|
+
s.add_dependency "daemons", "~> 1.1.0"
|
26
|
+
s.add_dependency "thor", "~> 0.14.6"
|
27
|
+
|
28
|
+
s.add_development_dependency "rspec", "~> 2.5.0"
|
29
|
+
s.add_development_dependency "fakeweb", "~> 1.3.0"
|
30
|
+
end
|
data/lib/firebot.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "twitter/json_stream"
|
2
|
+
require "faraday"
|
3
|
+
require "daemons"
|
4
|
+
require "thor"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
require "firebot/settings"
|
8
|
+
require "firebot/exceptions"
|
9
|
+
require "firebot/campfire"
|
10
|
+
require "firebot/runner"
|
11
|
+
require "firebot/listener"
|
12
|
+
require "firebot/cli"
|
13
|
+
require "firebot/version"
|
14
|
+
require "firebot/plugin"
|
15
|
+
|
16
|
+
module Firebot
|
17
|
+
def self.run
|
18
|
+
EventMachine.run do
|
19
|
+
Listener.connect(Settings.stream_settings)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.register_plugin(identifier, handler)
|
24
|
+
@plugins ||= {}
|
25
|
+
@plugins[identifier.to_s] = handler.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.plugins
|
29
|
+
@plugins
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require "firebot/plugins/ping_pong"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Firebot
|
2
|
+
module Campfire
|
3
|
+
def self.join_room
|
4
|
+
post :join
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.leave_room
|
8
|
+
post :leave
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.speak(message)
|
12
|
+
post :speak, {:message => {:body => message, :type => "TextMessage"}}
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.connection
|
18
|
+
@connection ||= Faraday.new(:url => account_host) do |builder|
|
19
|
+
builder.use Faraday::Request::Yajl
|
20
|
+
builder.adapter Faraday.default_adapter
|
21
|
+
builder.headers['Content-Type'] = 'application/json'
|
22
|
+
builder.basic_auth Settings[:token], "x"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.post(action, body = nil)
|
27
|
+
res = connection.post "/room/#{Settings[:room_id]}/#{action}.json", body
|
28
|
+
raise UnauthorizedException if res.status == 401
|
29
|
+
res
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.account_host
|
33
|
+
"https://#{Settings[:account]}.#{Settings[:host]}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/firebot/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Firebot
|
2
|
+
class CLI < Thor
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
desc "start", "Startup the Firebot daemon"
|
6
|
+
method_option :daemonize, :aliases => "-d",
|
7
|
+
:default => true, :type => :boolean, :banner => "true|false",
|
8
|
+
:desc => "Defines if the bot will run as a daemon or attached to the terminal"
|
9
|
+
def start
|
10
|
+
sanity_check!
|
11
|
+
command = options[:daemonize] ? "start" : "run"
|
12
|
+
daemon_exec(command)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "stop", "Stop the Firebot daemon"
|
16
|
+
def stop
|
17
|
+
daemon_exec("stop")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "create_config", "Create a sample config file in ~/.firebot"
|
21
|
+
def create_config
|
22
|
+
template("cli/config.tt", "~/.firebot")
|
23
|
+
say "Go tweak ~/.firebot"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.source_root
|
27
|
+
File.dirname(__FILE__)
|
28
|
+
end
|
29
|
+
|
30
|
+
no_tasks do
|
31
|
+
def sanity_check!
|
32
|
+
unless File.exist?(File.expand_path(Settings.config_path))
|
33
|
+
abort "No configuration file found in #{Settings.config_path}. Create one with `firebot create_config` and try again."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def daemon_exec(command)
|
38
|
+
Daemons.run_proc("firebot", { :ARGV => [command] }, &daemon_proc)
|
39
|
+
end
|
40
|
+
|
41
|
+
def daemon_proc
|
42
|
+
lambda do
|
43
|
+
Firebot.run
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Firebot
|
2
|
+
class Listener < Twitter::JSONStream
|
3
|
+
def self.connect(options = {})
|
4
|
+
Campfire.join_room
|
5
|
+
conn = super(options)
|
6
|
+
|
7
|
+
conn.each_item do |message|
|
8
|
+
Runner.execute(message)
|
9
|
+
end
|
10
|
+
|
11
|
+
conn.on_error do |message|
|
12
|
+
#TODO improve error handling
|
13
|
+
Campfire.leave_room
|
14
|
+
EventMachine.stop
|
15
|
+
end
|
16
|
+
|
17
|
+
conn.on_max_reconnects do |timeout, retries|
|
18
|
+
#TODO improve error handling
|
19
|
+
EventMachine.stop
|
20
|
+
end
|
21
|
+
|
22
|
+
conn
|
23
|
+
end
|
24
|
+
|
25
|
+
def unbind
|
26
|
+
Campfire.leave_room
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Firebot
|
2
|
+
class Plugin
|
3
|
+
class << self
|
4
|
+
attr_accessor :commands
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.trigger(identifier)
|
8
|
+
Firebot.register_plugin(identifier, self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.command(command, regex)
|
12
|
+
@commands ||= {}
|
13
|
+
@commands[regex] = command
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(cmd)
|
17
|
+
cmd.strip!
|
18
|
+
matched = false
|
19
|
+
self.class.commands.each do |regex, method|
|
20
|
+
if cmd =~ regex
|
21
|
+
send(method)
|
22
|
+
matched = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
reply(help) unless matched
|
26
|
+
end
|
27
|
+
|
28
|
+
def help
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
def reply(message)
|
33
|
+
Campfire.speak(message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Firebot
|
2
|
+
class PingPong < Plugin
|
3
|
+
trigger :pp
|
4
|
+
command :ping, /ping/
|
5
|
+
command :pong, /pong/
|
6
|
+
|
7
|
+
def help
|
8
|
+
"Usage: !pp ping or !pp pong"
|
9
|
+
end
|
10
|
+
|
11
|
+
def ping
|
12
|
+
reply("pong")
|
13
|
+
end
|
14
|
+
|
15
|
+
def pong
|
16
|
+
reply("ping")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Firebot
|
2
|
+
class Runner
|
3
|
+
COMMAND_MATCHER = /^!(\w+)/
|
4
|
+
|
5
|
+
attr_accessor :message
|
6
|
+
|
7
|
+
def self.execute(json_message)
|
8
|
+
msg = JSON.parse(json_message)
|
9
|
+
new(msg).run if msg["type"] == "TextMessage"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(message)
|
13
|
+
@message = message
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
if message["body"] =~ COMMAND_MATCHER
|
18
|
+
if Firebot.plugins[$1]
|
19
|
+
Firebot.plugins[$1].run(plugin_message(message["body"], $1))
|
20
|
+
else
|
21
|
+
Campfire.speak("No plugin respond to #{$1}.")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def plugin_message(full_message, prefix)
|
29
|
+
full_message.gsub(/^!#{prefix}/, "")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Firebot
|
2
|
+
module Settings
|
3
|
+
def self.all
|
4
|
+
@settings ||= begin
|
5
|
+
options = {
|
6
|
+
"stream_host" => "streaming.campfirenow.com",
|
7
|
+
"stream_port" => "80",
|
8
|
+
"host" => "campfirenow.com"
|
9
|
+
}
|
10
|
+
user_options = YAML.load(File.read(File.expand_path(config_path))).to_hash
|
11
|
+
options.merge!(user_options)
|
12
|
+
options["path"] = "/room/#{options["room_id"]}/live.json"
|
13
|
+
options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.[](key)
|
18
|
+
all[key.to_s]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config_path
|
22
|
+
@config_path ||= "~/.firebot"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.config_path=(path)
|
26
|
+
@config_path = path
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.stream_settings
|
30
|
+
{
|
31
|
+
:path => "/room/#{self[:room_id]}/live.json",
|
32
|
+
:host => self[:stream_host],
|
33
|
+
:port => self[:stream_port],
|
34
|
+
:auth => "#{self[:token]}:x"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Firebot::Campfire do
|
4
|
+
before do
|
5
|
+
@join_uri = "https://12345:x@test.campfirenow.com/room/123/join.json"
|
6
|
+
@leave_uri = "https://12345:x@test.campfirenow.com/room/123/leave.json"
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".join_room" do
|
10
|
+
it "should reach the join room endpoint" do
|
11
|
+
FakeWeb.register_uri(:post, @join_uri, :body => "", :status => ["200", "OK"])
|
12
|
+
|
13
|
+
res = Firebot::Campfire.join_room
|
14
|
+
res.status.should == 200
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an exception if connection doesn't succeed" do
|
18
|
+
FakeWeb.register_uri(:post, @join_uri, :body => "", :status => ["401", "Unauthorized"])
|
19
|
+
|
20
|
+
expect {
|
21
|
+
Firebot::Campfire.join_room
|
22
|
+
}.to raise_error(Firebot::UnauthorizedException)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context ".leave_room" do
|
27
|
+
it "should reach the leave room endpoint" do
|
28
|
+
FakeWeb.register_uri(:post, @leave_uri, :body => "", :status => ["200", "OK"])
|
29
|
+
|
30
|
+
res = Firebot::Campfire.leave_room
|
31
|
+
res.status.should == 200
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise an exception if connection doesn't succeed" do
|
35
|
+
FakeWeb.register_uri(:post, @leave_uri, :body => "", :status => ["401", "Unauthorized"])
|
36
|
+
|
37
|
+
expect {
|
38
|
+
Firebot::Campfire.leave_room
|
39
|
+
}.to raise_error(Firebot::UnauthorizedException)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Firebot::CLI do
|
4
|
+
context "#sanity_check!" do
|
5
|
+
it "should complain if config file is not in place" do
|
6
|
+
swap Firebot::Settings, :config_path => "path/to/nowhere" do
|
7
|
+
lambda do
|
8
|
+
cli = Firebot::CLI.new
|
9
|
+
cli.sanity_check!
|
10
|
+
end.should raise_error(SystemExit)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should let execution if settings path is correct" do
|
15
|
+
lambda do
|
16
|
+
cli = Firebot::CLI.new
|
17
|
+
cli.sanity_check!
|
18
|
+
end.should_not raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
Transfer-Encoding: chunked
|
4
|
+
Server: Jetty(6.1.17)
|
5
|
+
|
6
|
+
{"room_id":123,"created_at":"2011/03/10 03:07:51 +0000","body":"nice message","id":322347135,"user_id":321,"type":"TextMessage"}
|
7
|
+
|
8
|
+
{"room_id":123,"created_at":"2011/03/10 03:07:51 +0000","body":"nice message","id":322347135,"user_id":321,"type":"TextMessage"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Firebot::Listener do
|
4
|
+
before do
|
5
|
+
@join_uri = "https://12345:x@test.campfirenow.com/room/123/join.json"
|
6
|
+
@leave_uri = "https://12345:x@test.campfirenow.com/room/123/leave.json"
|
7
|
+
|
8
|
+
FakeWeb.register_uri(:post, @join_uri, :body => "", :status => ["200", "OK"])
|
9
|
+
FakeWeb.register_uri(:post, @leave_uri, :body => "", :status => ["200", "OK"])
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should listen do stream and trigger command execution" do
|
13
|
+
message_content = '{"room_id":123,"created_at":"2011/03/10 03:07:51 +0000","body":"nice message","id":322347135,"user_id":321,"type":"TextMessage"}'
|
14
|
+
Firebot::Runner.should_receive(:execute).with(message_content).twice
|
15
|
+
|
16
|
+
consume_stream
|
17
|
+
end
|
18
|
+
end
|
data/spec/runner_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Firebot::Settings do
|
4
|
+
context ".all" do
|
5
|
+
it "should return hash" do
|
6
|
+
Firebot::Settings.all.should be_instance_of(Hash)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context ".[]" do
|
11
|
+
it "should return setting key" do
|
12
|
+
Firebot::Settings[:host].should == "campfirenow.com"
|
13
|
+
Firebot::Settings[:room_id].should == "123"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "fakeweb"
|
2
|
+
require "firebot"
|
3
|
+
require "rspec/mocks"
|
4
|
+
|
5
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
|
6
|
+
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
|
9
|
+
Firebot::Settings.config_path = File.expand_path("spec/fixtures/config.yml")
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before(:each) { FakeWeb.clean_registry }
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class JSONServer < EM::Connection
|
2
|
+
SAMPLE_DATA = File.read(File.expand_path("../../fixtures/sample_response.txt", __FILE__))
|
3
|
+
|
4
|
+
def receive_data(data)
|
5
|
+
send_data(SAMPLE_DATA)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def consume_stream
|
10
|
+
host = "127.0.0.1"
|
11
|
+
port = 4321
|
12
|
+
EM.run {
|
13
|
+
EM.start_server host, port, JSONServer
|
14
|
+
Firebot::Listener.connect(Firebot::Settings.stream_settings)
|
15
|
+
EM.add_timer(0.01){ EM.stop }
|
16
|
+
}
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firebot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.0.1.pre
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcelo Silveira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-28 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: twitter-stream
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.10
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.5.7
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: yajl-ruby
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.1
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: daemons
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.1.0
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: thor
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.14.6
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.5.0
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: fakeweb
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.3.0
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
description: Extensible Campfire bot to integrate with other applications/services
|
94
|
+
email: marcelo@mhfs.com.br
|
95
|
+
executables:
|
96
|
+
- firebot
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .rspec
|
104
|
+
- Gemfile
|
105
|
+
- Gemfile.lock
|
106
|
+
- MIT-LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- bin/firebot
|
110
|
+
- firebot.gemspec
|
111
|
+
- lib/firebot.rb
|
112
|
+
- lib/firebot/campfire.rb
|
113
|
+
- lib/firebot/cli.rb
|
114
|
+
- lib/firebot/cli/config.tt
|
115
|
+
- lib/firebot/exceptions.rb
|
116
|
+
- lib/firebot/listener.rb
|
117
|
+
- lib/firebot/plugin.rb
|
118
|
+
- lib/firebot/plugins/ping_pong.rb
|
119
|
+
- lib/firebot/runner.rb
|
120
|
+
- lib/firebot/settings.rb
|
121
|
+
- lib/firebot/tasks.rb
|
122
|
+
- lib/firebot/version.rb
|
123
|
+
- spec/campfire_spec.rb
|
124
|
+
- spec/cli_spec.rb
|
125
|
+
- spec/fixtures/config.yml
|
126
|
+
- spec/fixtures/sample_response.txt
|
127
|
+
- spec/listener_spec.rb
|
128
|
+
- spec/runner_spec.rb
|
129
|
+
- spec/settings_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/attr_switcher.rb
|
132
|
+
- spec/support/em_helpers.rb
|
133
|
+
has_rdoc: true
|
134
|
+
homepage: https://github.com/mhfs/firebot
|
135
|
+
licenses: []
|
136
|
+
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: "0"
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 1.3.1
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project: firebot
|
157
|
+
rubygems_version: 1.6.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Extensible Campfire bot to integrate with other applications/services
|
161
|
+
test_files:
|
162
|
+
- spec/campfire_spec.rb
|
163
|
+
- spec/cli_spec.rb
|
164
|
+
- spec/fixtures/config.yml
|
165
|
+
- spec/fixtures/sample_response.txt
|
166
|
+
- spec/listener_spec.rb
|
167
|
+
- spec/runner_spec.rb
|
168
|
+
- spec/settings_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
- spec/support/attr_switcher.rb
|
171
|
+
- spec/support/em_helpers.rb
|