campfire_bot 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 reddavis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a 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
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = Campfire Bot
2
+
3
+ This is a Campfire bot heavily inspired by http://github.com/ichverstehe/isaac
4
+
5
+ == How To Install
6
+
7
+ sudo gem install campfire_bot
8
+
9
+ == How To User
10
+
11
+ require "rubygems"
12
+ require "campfire_bot"
13
+
14
+ # Configuration
15
+ config do |c|
16
+ c.username = "username"
17
+ c.password = "password"
18
+ c.subdomain = "subdomain"
19
+ c.room = "room"
20
+ end
21
+
22
+ # Events
23
+ on(/^How are you?/) do
24
+ msg("Im very well thank-you")
25
+ end
26
+
27
+ == Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history.
34
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ == Todo
38
+
39
+ * Use Campfire keys
40
+
41
+ == Copyright
42
+
43
+ Copyright (c) 2010 Red Davis. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "campfire_bot"
8
+ gem.summary = %Q{Create bots in your Campfires}
9
+ gem.description = %Q{Create bots in your Campfires}
10
+ gem.email = "reddavis@gmail.com"
11
+ gem.homepage = "http://github.com/reddavis/campfire_bot"
12
+ gem.authors = ["reddavis"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "tinder", ">= 1.4.0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "campfire_bot #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/examples/basic.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/campfire_bot")
3
+
4
+ config do |c|
5
+ c.username = "username"
6
+ c.password = "password"
7
+ c.subdomain = "subdomain"
8
+ c.room = "room"
9
+ end
10
+
11
+ on(/^hello/) do
12
+ msg("Hello to you to")
13
+ end
@@ -0,0 +1,45 @@
1
+ require "tinder"
2
+
3
+ module Campfire
4
+ class Bot
5
+ def initialize
6
+ @events = []
7
+ end
8
+
9
+ def config(&block)
10
+ config = Config.new
11
+ block.call(config)
12
+ @campfire = Tinder::Campfire.new(config.subdomain, :username => config.username, :password => config.password).find_room_by_name(config.room)
13
+ end
14
+
15
+ def start
16
+ raise "You need to configure me" unless @campfire
17
+ @campfire.listen do |line|
18
+ evaluate(line[:body]) if line[:body]
19
+ end
20
+ end
21
+
22
+ def msg(text)
23
+ @campfire.speak(text)
24
+ end
25
+
26
+ def on(regex, &block)
27
+ @events << Event.new(regex, block)
28
+ end
29
+
30
+ def evaluate(message)
31
+ if event = find_event(message)
32
+ event.action.call
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def find_event(command)
39
+ @events.find {|event| command.match(event.regex)}
40
+ end
41
+ end
42
+
43
+ class Event < Struct.new(:regex, :action); end
44
+ class Config < Struct.new(:username, :password, :subdomain, :room); end
45
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
2
+ require 'campfire_bot/bot'
3
+
4
+ $bot = Campfire::Bot.new
5
+
6
+ %w(on config msg).each do |method|
7
+ eval(<<-EOF)
8
+ def #{method}(*args, &block)
9
+ $bot.#{method}(*args, &block)
10
+ end
11
+ EOF
12
+ end
13
+
14
+ at_exit do
15
+ unless defined?(Rspec)
16
+ raise $! if $!
17
+ $bot.start
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CampfireBot" do
4
+ before do
5
+ @room = mock("room")
6
+ campfire = mock("campfire")
7
+ campfire.stub!(:find_room_by_name).and_return(@room)
8
+ @campfire = Tinder::Campfire.stub!(:new).and_return(campfire)
9
+ @bot = Campfire::Bot.new
10
+ @bot.config {}
11
+ end
12
+
13
+ describe "Sending a message" do
14
+ it "should send a message" do
15
+ @room.should_receive(:speak)
16
+ @bot.msg("hello")
17
+ end
18
+ end
19
+
20
+ describe "Starting without configuring" do
21
+ it "should raise an exception" do
22
+ lambda do
23
+ Campfire::Bot.new.start
24
+ end.should raise_error(RuntimeError)
25
+ end
26
+ end
27
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ ## Need some more tests ##
5
+
6
+ require 'rubygems'
7
+ require 'campfire_bot'
8
+ require 'spec'
9
+ require 'spec/autorun'
10
+
11
+ Spec::Runner.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: campfire_bot
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - reddavis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-02 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: tinder
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 4
44
+ - 0
45
+ version: 1.4.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Create bots in your Campfires
49
+ email: reddavis@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - examples/basic.rb
65
+ - lib/campfire_bot.rb
66
+ - lib/campfire_bot/bot.rb
67
+ - spec/campfire_bot_spec.rb
68
+ - spec/spec.opts
69
+ - spec/spec_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/reddavis/campfire_bot
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.6
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Create bots in your Campfires
100
+ test_files:
101
+ - spec/campfire_bot_spec.rb
102
+ - spec/spec_helper.rb
103
+ - examples/basic.rb