twibot 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Rakefile +1 -1
- data/Readme.rdoc +1 -0
- data/lib/twibot/bot.rb +24 -18
- data/lib/twibot.rb +1 -1
- data/test/test_bot.rb +4 -4
- data/test/test_helper.rb +2 -1
- data/twibot.gemspec +38 -0
- metadata +4 -3
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ task :default => 'test:run'
|
|
21
21
|
PROJ.name = 'twibot'
|
22
22
|
PROJ.authors = 'Christian Johansen'
|
23
23
|
PROJ.email = 'christian@cjohansen.no'
|
24
|
-
PROJ.url = 'http://github.com/
|
24
|
+
PROJ.url = 'http://github.com/bjeanes/twibot/'
|
25
25
|
PROJ.version = Twibot::VERSION
|
26
26
|
PROJ.rubyforge.name = 'twibot'
|
27
27
|
PROJ.readme_file = 'Readme.rdoc'
|
data/Readme.rdoc
CHANGED
@@ -148,6 +148,7 @@ reaches max_interval, where it will stay until Twibot finds anything.
|
|
148
148
|
* Ben Vandgrift (Twitter downtime error handling) - http://neovore.com/
|
149
149
|
* Jens Ohlig (warnings)
|
150
150
|
* Wilco van Duinkerken (bug fixes) - http://www.sparkboxx.com/
|
151
|
+
* Bodaniel Jeanes (configure block fix) - http://bjeanes.github.com/
|
151
152
|
|
152
153
|
== License
|
153
154
|
|
data/lib/twibot/bot.rb
CHANGED
@@ -15,21 +15,26 @@ module Twibot
|
|
15
15
|
@prompt = prompt
|
16
16
|
@conf = nil
|
17
17
|
@config = options || Twibot::Config.default << Twibot::FileConfig.new << Twibot::CliConfig.new
|
18
|
-
@twitter = Twitter::Client.new :login => config[:login], :password => config[:password]
|
19
18
|
@log = nil
|
20
19
|
@abort = false
|
20
|
+
rescue Exception => krash
|
21
|
+
raise SystemExit.new(krash.message)
|
22
|
+
end
|
21
23
|
|
22
|
-
|
24
|
+
def prompt?
|
25
|
+
@prompt
|
26
|
+
end
|
27
|
+
|
28
|
+
def processed
|
29
|
+
@processed ||= {
|
23
30
|
:message => nil,
|
24
31
|
:reply => nil,
|
25
32
|
:tweet => nil
|
26
33
|
}
|
27
|
-
rescue Exception => krash
|
28
|
-
raise SystemExit.new(krash.message)
|
29
34
|
end
|
30
35
|
|
31
|
-
def
|
32
|
-
@
|
36
|
+
def twitter
|
37
|
+
@twitter ||= Twitter::Client.new :login => config[:login], :password => config[:password]
|
33
38
|
end
|
34
39
|
|
35
40
|
#
|
@@ -44,21 +49,21 @@ module Twibot
|
|
44
49
|
end
|
45
50
|
|
46
51
|
# Make sure we don't process messages and tweets received prior to bot launch
|
47
|
-
messages =
|
48
|
-
|
52
|
+
messages = twitter.messages(:received, { :count => 1 })
|
53
|
+
processed[:message] = messages.first.id if messages.length > 0
|
49
54
|
|
50
55
|
handle_tweets = !@handlers.nil? && @handlers[:tweet].length + @handlers[:reply].length > 0
|
51
56
|
tweets = []
|
52
57
|
|
53
58
|
begin
|
54
|
-
tweets = handle_tweets ?
|
59
|
+
tweets = handle_tweets ? twitter.timeline_for(config[:timeline_for], { :count => 1 }) : []
|
55
60
|
rescue Twitter::RESTError => e
|
56
61
|
log.error("Failed to connect to Twitter. It's likely down for a bit:")
|
57
62
|
log.error(e.to_s)
|
58
63
|
end
|
59
64
|
|
60
|
-
|
61
|
-
|
65
|
+
processed[:tweet] = tweets.first.id if tweets.length > 0
|
66
|
+
processed[:reply] = tweets.first.id if tweets.length > 0
|
62
67
|
|
63
68
|
poll
|
64
69
|
end
|
@@ -91,9 +96,9 @@ module Twibot
|
|
91
96
|
type = :message
|
92
97
|
return false unless handlers[type].length > 0
|
93
98
|
options = {}
|
94
|
-
options[:since_id] =
|
99
|
+
options[:since_id] = processed[type] if processed[type]
|
95
100
|
begin
|
96
|
-
dispatch_messages(type,
|
101
|
+
dispatch_messages(type, twitter.messages(:received, options), %w{message messages})
|
97
102
|
rescue Twitter::RESTError => e
|
98
103
|
log.error("Failed to connect to Twitter. It's likely down for a bit:")
|
99
104
|
log.error(e.to_s)
|
@@ -108,9 +113,9 @@ module Twibot
|
|
108
113
|
type = :tweet
|
109
114
|
return false unless handlers[type].length > 0
|
110
115
|
options = {}
|
111
|
-
options[:since_id] =
|
116
|
+
options[:since_id] = processed[type] if processed[type]
|
112
117
|
begin
|
113
|
-
dispatch_messages(type,
|
118
|
+
dispatch_messages(type, twitter.timeline_for(config.to_hash[:timeline_for] || :public, options), %w{tweet tweets})
|
114
119
|
rescue Twitter::RESTError => e
|
115
120
|
log.error("Failed to connect to Twitter. It's likely down for a bit:")
|
116
121
|
log.error(e.to_s)
|
@@ -125,9 +130,9 @@ module Twibot
|
|
125
130
|
type = :reply
|
126
131
|
return false unless handlers[type].length > 0
|
127
132
|
options = {}
|
128
|
-
options[:since_id] =
|
133
|
+
options[:since_id] = processed[type] if processed[type]
|
129
134
|
begin
|
130
|
-
dispatch_messages(type,
|
135
|
+
dispatch_messages(type, twitter.status(:replies, options), %w{reply replies})
|
131
136
|
rescue Twitter::RESTError => e
|
132
137
|
log.error("Failed to connect to Twitter. It's likely down for a bit:")
|
133
138
|
log.error(e.to_s)
|
@@ -142,7 +147,7 @@ module Twibot
|
|
142
147
|
def dispatch_messages(type, messages, labels)
|
143
148
|
messages.each { |message| dispatch(type, message) }
|
144
149
|
# Avoid picking up messages over again
|
145
|
-
|
150
|
+
processed[type] = messages.first.id if messages.length > 0
|
146
151
|
|
147
152
|
num = messages.length
|
148
153
|
log.info "Received #{num} #{num == 1 ? labels[0] : labels[1]}"
|
@@ -166,6 +171,7 @@ module Twibot
|
|
166
171
|
def configure
|
167
172
|
yield @config
|
168
173
|
@conf = nil
|
174
|
+
@twitter = nil
|
169
175
|
end
|
170
176
|
|
171
177
|
private
|
data/lib/twibot.rb
CHANGED
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'hash')
|
|
7
7
|
module Twibot
|
8
8
|
|
9
9
|
# :stopdoc:
|
10
|
-
VERSION = '0.1.
|
10
|
+
VERSION = '0.1.6'
|
11
11
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
12
12
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
13
13
|
# :startdoc:
|
data/test/test_bot.rb
CHANGED
@@ -76,13 +76,13 @@ class TestBot < Test::Unit::TestCase
|
|
76
76
|
should "receive tweet" do
|
77
77
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
78
78
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
79
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:
|
79
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:public, {}).returns([tweet("cjno", "Hei der!")])
|
80
80
|
|
81
81
|
assert_equal 1, bot.receive_tweets
|
82
82
|
end
|
83
83
|
|
84
84
|
should "receive friend tweets if configured" do
|
85
|
-
bot = Twibot::Bot.new(Twibot::Config.new({:log_level => "error", :
|
85
|
+
bot = Twibot::Bot.new(Twibot::Config.new({:log_level => "error", :timeline_for => :friends}))
|
86
86
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
87
87
|
Twitter::Client.any_instance.expects(:timeline_for).with(:friends, {}).returns([tweet("cjno", "Hei der!")])
|
88
88
|
|
@@ -92,10 +92,10 @@ class TestBot < Test::Unit::TestCase
|
|
92
92
|
should "remember received tweets" do
|
93
93
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
94
94
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
95
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:
|
95
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:public, {}).returns([tweet("cjno", "Hei der!")])
|
96
96
|
assert_equal 1, bot.receive_tweets
|
97
97
|
|
98
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:
|
98
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:public, { :since_id => 1 }).returns([])
|
99
99
|
assert_equal 0, bot.receive_tweets
|
100
100
|
end
|
101
101
|
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'test/unit'
|
2
3
|
require 'shoulda'
|
3
4
|
require 'mocha'
|
4
|
-
require File.join(File.dirname(__FILE__), '
|
5
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'twibot')
|
5
6
|
|
6
7
|
module Test::Unit::Assertions
|
7
8
|
def assert_hashes_equal(expected, actual, message = nil)
|
data/twibot.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{twibot}
|
5
|
+
s.version = "0.1.6"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Christian Johansen"]
|
9
|
+
s.date = %q{2009-04-13}
|
10
|
+
s.description = %q{Twibot (pronounced like "Abbot"), is a Ruby microframework for creating Twitter bots, heavily inspired by Sinatra.}
|
11
|
+
s.email = %q{christian@cjohansen.no}
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Readme.rdoc"]
|
13
|
+
s.files = ["History.txt", "Rakefile", "Readme.rdoc", "lib/hash.rb", "lib/twibot.rb", "lib/twibot/bot.rb", "lib/twibot/config.rb", "lib/twibot/handlers.rb", "lib/twibot/macros.rb", "lib/twibot/tweets.rb", "test/test_bot.rb", "test/test_config.rb", "test/test_handler.rb", "test/test_hash.rb", "test/test_helper.rb", "test/test_twibot.rb", "twibot.gemspec"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/bjeanes/twibot/}
|
16
|
+
s.rdoc_options = ["--main", "Readme.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{twibot}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Twibot (pronounced like "Abbot"), is a Ruby microframework for creating Twitter bots, heavily inspired by Sinatra}
|
21
|
+
s.test_files = ["test/test_helper.rb", "test/test_config.rb", "test/test_hash.rb", "test/test_twibot.rb", "test/test_bot.rb", "test/test_handler.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<mbbx6spp-twitter4r>, [">= 0.3.1"])
|
29
|
+
s.add_development_dependency(%q<bones>, [">= 2.4.0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<mbbx6spp-twitter4r>, [">= 0.3.1"])
|
32
|
+
s.add_dependency(%q<bones>, [">= 2.4.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<mbbx6spp-twitter4r>, [">= 0.3.1"])
|
36
|
+
s.add_dependency(%q<bones>, [">= 2.4.0"])
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twibot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Johansen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-13 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -70,8 +70,9 @@ files:
|
|
70
70
|
- test/test_hash.rb
|
71
71
|
- test/test_helper.rb
|
72
72
|
- test/test_twibot.rb
|
73
|
+
- twibot.gemspec
|
73
74
|
has_rdoc: true
|
74
|
-
homepage: http://github.com/
|
75
|
+
homepage: http://github.com/bjeanes/twibot/
|
75
76
|
post_install_message:
|
76
77
|
rdoc_options:
|
77
78
|
- --main
|