campfire_bot 0.0.0 → 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/README.rdoc CHANGED
@@ -11,18 +11,20 @@ This is a Campfire bot heavily inspired by http://github.com/ichverstehe/isaac
11
11
  require "rubygems"
12
12
  require "campfire_bot"
13
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
14
+ Campfire::Bot.config do |bot|
15
+ # Login
16
+ bot.login do |l|
17
+ l.username = "username"
18
+ l.password = "password"
19
+ l.subdomain = "subdomain"
20
+ l.room = "room"
21
+ end
22
+
23
+ # Events
24
+ bot.on(/^How are you?/) do
25
+ msg("Im very well thank-you")
26
+ end
27
+ end.start
26
28
 
27
29
  == Note on Patches/Pull Requests
28
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{campfire_bot}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["reddavis"]
12
+ s.date = %q{2010-07-10}
13
+ s.description = %q{Create bots in your Campfires}
14
+ s.email = %q{reddavis@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "campfire_bot.gemspec",
27
+ "examples/basic.rb",
28
+ "lib/campfire_bot.rb",
29
+ "spec/campfire_bot_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/reddavis/campfire_bot}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Create bots in your Campfires}
38
+ s.test_files = [
39
+ "spec/campfire_bot_spec.rb",
40
+ "spec/spec_helper.rb",
41
+ "examples/basic.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_runtime_dependency(%q<tinder>, [">= 1.4.0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<tinder>, [">= 1.4.0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<tinder>, [">= 1.4.0"])
58
+ end
59
+ end
60
+
data/examples/basic.rb CHANGED
@@ -1,13 +1,17 @@
1
1
  require 'rubygems'
2
2
  require File.expand_path(File.dirname(__FILE__) + "/../lib/campfire_bot")
3
3
 
4
- config do |c|
5
- c.username = "username"
6
- c.password = "password"
7
- c.subdomain = "subdomain"
8
- c.room = "room"
9
- end
4
+ Campfire::Bot.config do |bot|
5
+ # Login
6
+ bot.login do |l|
7
+ l.username = "username"
8
+ l.password = "password"
9
+ l.subdomain = "subdomain"
10
+ l.room = "room"
11
+ end
10
12
 
11
- on(/^hello/) do
12
- msg("Hello to you to")
13
- end
13
+ # Events
14
+ bot.on(/^How are you?/) do
15
+ msg("Im very well thank-you")
16
+ end
17
+ end.start
data/lib/campfire_bot.rb CHANGED
@@ -1,19 +1,54 @@
1
- $:.unshift(File.expand_path(File.dirname(__FILE__)))
2
- require 'campfire_bot/bot'
1
+ require 'rubygems'
2
+ require "tinder"
3
3
 
4
- $bot = Campfire::Bot.new
4
+ module Campfire
5
+ class Bot
6
+ class << self
7
+ def config
8
+ @bot = new
9
+ yield(@bot)
10
+ @bot
11
+ end
12
+ end
13
+
14
+ def initialize
15
+ @events = []
16
+ end
17
+
18
+ def login(&block)
19
+ config = Config.new
20
+ block.call(config)
21
+ @campfire = Tinder::Campfire.new(config.subdomain, :username => config.username, :password => config.password).find_room_by_name(config.room)
22
+ end
23
+
24
+ def start
25
+ raise "You need to configure me" unless @campfire
26
+ @campfire.listen do |line|
27
+ evaluate(line[:body]) if line[:body]
28
+ end
29
+ end
5
30
 
6
- %w(on config msg).each do |method|
7
- eval(<<-EOF)
8
- def #{method}(*args, &block)
9
- $bot.#{method}(*args, &block)
31
+ def msg(text)
32
+ @campfire.speak(text)
10
33
  end
11
- EOF
12
- end
13
34
 
14
- at_exit do
15
- unless defined?(Rspec)
16
- raise $! if $!
17
- $bot.start
35
+ def on(regex, &block)
36
+ @events << Event.new(regex, block)
37
+ end
38
+
39
+ def evaluate(message)
40
+ if event = find_event(message)
41
+ event.action.call
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def find_event(command)
48
+ @events.find {|event| command.match(event.regex)}
49
+ end
18
50
  end
51
+
52
+ class Event < Struct.new(:regex, :action); end
53
+ class Config < Struct.new(:username, :password, :subdomain, :room); end
19
54
  end
@@ -7,7 +7,7 @@ describe "CampfireBot" do
7
7
  campfire.stub!(:find_room_by_name).and_return(@room)
8
8
  @campfire = Tinder::Campfire.stub!(:new).and_return(campfire)
9
9
  @bot = Campfire::Bot.new
10
- @bot.config {}
10
+ @bot.login {}
11
11
  end
12
12
 
13
13
  describe "Sending a message" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - reddavis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-02 00:00:00 +01:00
17
+ date: 2010-07-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -61,9 +61,9 @@ files:
61
61
  - README.rdoc
62
62
  - Rakefile
63
63
  - VERSION
64
+ - campfire_bot.gemspec
64
65
  - examples/basic.rb
65
66
  - lib/campfire_bot.rb
66
- - lib/campfire_bot/bot.rb
67
67
  - spec/campfire_bot_spec.rb
68
68
  - spec/spec.opts
69
69
  - spec/spec_helper.rb
@@ -1,45 +0,0 @@
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