streambot 0.4.0 → 0.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,9 +6,17 @@ streambot is using tweetstream[http://github.com/intridea/tweetstream] for simpl
6
6
 
7
7
  the streambot gem is available on rubygems.org[http://rubygems.org/gems/streambot]
8
8
  to get streambot installed, you simply need to run
9
-
10
- gem install streambot
11
-
9
+
10
+ === stable release
11
+
12
+ gem install streambot
13
+
14
+ === beta release
15
+
16
+ if you are insane and want to try out the actual beta release then run
17
+
18
+ gem install streambot --pre
19
+
12
20
  == Usage
13
21
 
14
22
  require 'streambot'
@@ -21,11 +29,15 @@ to get streambot installed, you simply need to run
21
29
  bot = StreamBot::Tracker.new(@params, @blacklist, 'apple','ipad','iphone os 4','steve jobs')
22
30
  bot.start
23
31
 
32
+ === Documentation
33
+
34
+ The full rdoc is available on rdoc.info[http://rdoc.info/projects/gr4y/streambot]
35
+
24
36
  === Configuration
25
37
 
26
- Twitter is shutting down http basic authentication with June 30th 2010. But only for the REST API. The Streaming API which the tracker is using still works with http basic authentication only.
38
+ Twitter is shutting down http basic authentication with August 16th 2010. But only for the REST API. The Streaming API which the tracker is using still works with http basic authentication only.
27
39
 
28
- So we still need the http basic authentication credentials for tracking the keywords after June 30th, but only for tracking and not for retweeting. So I introduced a new way of configuration, the params attribute that you need to pass into Tracker. Actually I don't know what happens when twitter is shutting down the http basic authentication.
40
+ So we still need the http basic authentication credentials for tracking the keywords after August 16th, but only for tracking and not for retweeting. So I introduced a new way of configuration, the params attribute that you need to pass into Tracker. Actually I don't know what happens when twitter is shutting down the http basic authentication.
29
41
 
30
42
  ==== auth_type
31
43
  The auth type is the authentication mechanism you want to use for retweeting.
@@ -41,6 +53,12 @@ The auth type is the authentication mechanism you want to use for retweeting.
41
53
  *username*:: Your login username
42
54
  *password*:: Your login password
43
55
 
56
+ ==== filters
57
+
58
+ *key*:: this should just hold an description of your filter
59
+ *type*:: USER, CONTENT or LANGUAGE
60
+ *value*:: a string, thats the content that should be filtered
61
+
44
62
  I wrote this stuff into my config.yml and load the params with
45
63
 
46
64
  require 'yaml'
data/Rakefile CHANGED
@@ -48,6 +48,7 @@ rescue LoadError
48
48
  end
49
49
 
50
50
  task :build_gem => [:test,:rdoc,:build]
51
+ task :install_gem => [:build_gem,:install]
51
52
  task :default => [:check_dependencies,:rcov,:reek,:build_gem]
52
53
 
53
54
  require 'rake/rdoctask'
@@ -0,0 +1,29 @@
1
+ module StreamBot
2
+ module Callbacks
3
+ def callback(name)
4
+ register_callback(name)
5
+ end
6
+
7
+ def callbacks(* names)
8
+ names.each do |name|
9
+ register_callback(name)
10
+ end
11
+ end
12
+
13
+ def is_registered?(name)
14
+ @callbacks.include?(name)
15
+ end
16
+
17
+ def register_callback(name)
18
+ class_eval <<-EOF
19
+ def #{name} (*args,&block)
20
+ if block
21
+ @#{name} = block
22
+ elsif @#{name}
23
+ @#{name}.call(*args)
24
+ end
25
+ end
26
+ EOF
27
+ end
28
+ end
29
+ end
@@ -1,36 +1,75 @@
1
1
  module StreamBot
2
- # The Tracker class that provides a start and a stop method
2
+ # The Tracker class that provides a start and a stop method
3
+ # This class has serveral callback methods
3
4
  class Tracker
5
+ extend StreamBot::Callbacks
6
+ callbacks :before_start, :before_match, :match_filter, :before_retweet
4
7
  # the initialization method aka the constructor
5
- def initialize(params, blacklist, *keywords)
8
+ def initialize(params, blacklist, * keywords)
6
9
  LOG.debug("Tracker#initialize")
7
10
  http_auth = params['http']
8
- @stream = TweetStream::Client.new(http_auth['username'],http_auth['password'])
11
+ @stream = TweetStream::Client.new(http_auth['username'], http_auth['password'])
12
+ @stream.on_error do |message|
13
+ LOG.error "#{message}"
14
+ @stream.stop
15
+ end
9
16
  # initializing retweet
10
17
  @retweet = StreamBot::Retweet.new(params)
11
18
  # get string with keywords comma separated keywords
12
19
  @keywords=keywords.join(',')
13
20
  # set blacklist array if not nil
14
21
  @blacklist=blacklist
22
+ if !@blacklist.nil?
23
+ warn "blacklisting is deprecated and will be removed with streambot 0.6.0"
24
+ end
25
+ @filters = params['filters']
15
26
  end
16
-
27
+
17
28
  # start the bot
18
29
  def start
30
+ before_start
19
31
  LOG.debug("Tracker#start")
20
32
  # starting to track the keywords via tweetstream
21
33
  @stream.track(@keywords) do |status|
34
+ # make status an instance variable for callbacks
35
+ @status = status
22
36
  username = status.user.screen_name
23
- # if status.user is NOT in blacklist then retweet it
24
- if !@blacklist.include?(username)
25
- LOG.debug("Tracker#start - retweet ##{status.id} from @#{username}")
26
- @retweet.retweet(status.id)
37
+ # if status.user is NOT in blacklist or filters don't match then retweet it
38
+ before_match
39
+ matched = false
40
+ if (@blacklist.nil? || !@blacklist.include?(username)) && !@filters.nil?
41
+ @filters.each do |key, value|
42
+ matched = match?(status, value)
43
+ if matched
44
+ match_filter
45
+ LOG.debug("Tracker#start - filter #{key} matched!")
46
+ end
47
+ end
48
+ if !matched
49
+ before_retweet
50
+ LOG.debug("Tracker#start - retweet ##{status.id} from @#{username}")
51
+ @retweet.retweet(status.id)
52
+ end
27
53
  end
28
- end
29
- end
30
-
54
+ end
55
+ end
56
+
57
+ # returns true if an filter is matching
58
+ def match?(status, filter)
59
+ @type = filter["type"]
60
+ @value = filter["value"]
61
+ if @type == "USER" then
62
+ status.user.screen_name.eql?(@value)
63
+ elsif @type == "CONTENT" then
64
+ status.text.include?(@value)
65
+ elsif @type == "LANGUAGE" then
66
+ status.user.lang.eql?(@value)
67
+ end
68
+ end
69
+
31
70
  # stop the bot
32
71
  def stop
33
72
  @stream.stop
34
73
  end
35
74
  end
36
- end
75
+ end
data/lib/streambot.rb CHANGED
@@ -6,11 +6,12 @@ require 'tweetstream'
6
6
  require 'logger'
7
7
  require 'yaml'
8
8
 
9
- require 'streambot/tracker'
9
+ require 'streambot/callbacks'
10
10
  require 'streambot/retweet'
11
11
  require 'streambot/handler'
12
12
  require 'streambot/http'
13
13
  require 'streambot/oauth'
14
+ require 'streambot/tracker'
14
15
 
15
16
  module StreamBot
16
17
  LOG = Logger.new(STDOUT)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streambot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
4
+ prerelease: true
6
5
  segments:
7
6
  - 0
8
- - 4
7
+ - 5
9
8
  - 0
10
- version: 0.4.0
9
+ - beta3
10
+ version: 0.5.0.beta3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sascha Wessel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-06 00:00:00 +02:00
18
+ date: 2010-08-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,7 +26,6 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 31
30
29
  segments:
31
30
  - 1
32
31
  - 0
@@ -42,7 +41,6 @@ dependencies:
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
- hash: 15
46
44
  segments:
47
45
  - 0
48
46
  - 4
@@ -58,7 +56,6 @@ dependencies:
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
- hash: 23
62
59
  segments:
63
60
  - 1
64
61
  - 0
@@ -74,7 +71,6 @@ dependencies:
74
71
  requirements:
75
72
  - - ">="
76
73
  - !ruby/object:Gem::Version
77
- hash: 43
78
74
  segments:
79
75
  - 0
80
76
  - 9
@@ -90,7 +86,6 @@ dependencies:
90
86
  requirements:
91
87
  - - ">="
92
88
  - !ruby/object:Gem::Version
93
- hash: 15
94
89
  segments:
95
90
  - 1
96
91
  - 2
@@ -110,6 +105,7 @@ extra_rdoc_files:
110
105
  files:
111
106
  - Rakefile
112
107
  - lib/streambot.rb
108
+ - lib/streambot/callbacks.rb
113
109
  - lib/streambot/handler.rb
114
110
  - lib/streambot/http.rb
115
111
  - lib/streambot/oauth.rb
@@ -138,19 +134,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
134
  requirements:
139
135
  - - ">="
140
136
  - !ruby/object:Gem::Version
141
- hash: 3
142
137
  segments:
143
138
  - 0
144
139
  version: "0"
145
140
  required_rubygems_version: !ruby/object:Gem::Requirement
146
141
  none: false
147
142
  requirements:
148
- - - ">="
143
+ - - ">"
149
144
  - !ruby/object:Gem::Version
150
- hash: 3
151
145
  segments:
152
- - 0
153
- version: "0"
146
+ - 1
147
+ - 3
148
+ - 1
149
+ version: 1.3.1
154
150
  requirements: []
155
151
 
156
152
  rubyforge_project: