streambot 0.5.0.beta5 → 0.5.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 +67 -39
- data/VERSION +1 -1
- data/lib/streambot/tracker.rb +13 -6
- metadata +7 -11
- data/lib/streambot/filter.rb +0 -35
data/README.rdoc
CHANGED
@@ -1,80 +1,108 @@
|
|
1
|
-
=
|
2
|
-
|
3
|
-
streambot is using tweetstream[http://github.com/intridea/tweetstream] for simple access to twitter streaming api
|
4
|
-
|
5
|
-
== Installation
|
1
|
+
= Installation
|
6
2
|
|
7
3
|
the streambot gem is available on rubygems.org[http://rubygems.org/gems/streambot]
|
8
4
|
to get streambot installed, you simply need to run
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
gem install streambot
|
6
|
+
== stable release
|
13
7
|
|
14
|
-
|
8
|
+
gem install streambot
|
15
9
|
|
16
|
-
|
10
|
+
== beta release
|
17
11
|
|
18
|
-
|
12
|
+
gem install streambot --pre
|
19
13
|
|
20
|
-
|
14
|
+
= Documentation
|
21
15
|
|
22
|
-
|
16
|
+
The full rdoc is available on rdoc.info[http://rdoc.info/projects/gr4y/streambot]
|
23
17
|
|
24
|
-
|
25
|
-
"oauth" => {"key" => "consumer key", "secret" => "consumer secret"},
|
26
|
-
"http" => {"username" => "username", "password" => "password"}
|
27
|
-
}
|
28
|
-
@blacklist = ['mac_rt','apple_rt']
|
29
|
-
bot = StreamBot::Tracker.new(@params, @blacklist, 'apple','ipad','iphone os 4','steve jobs')
|
30
|
-
bot.start
|
18
|
+
= Usage
|
31
19
|
|
32
|
-
|
20
|
+
require 'streambot'
|
33
21
|
|
34
|
-
|
22
|
+
@params = {"auth_type" => "oauth",
|
23
|
+
"oauth" => {"key" => "consumer key", "secret" => "consumer secret"},
|
24
|
+
"http" => {"username" => "username", "password" => "password"}
|
25
|
+
}
|
26
|
+
@blacklist = ['mac_rt','apple_rt']
|
27
|
+
bot = StreamBot::Tracker.new(@params, @blacklist, 'apple','ipad','iphone os 4','steve jobs')
|
28
|
+
bot.start
|
35
29
|
|
36
|
-
|
30
|
+
= Configuration
|
37
31
|
|
38
|
-
Twitter
|
32
|
+
Twitter has finally removed the http basic authentication for the REST API.
|
33
|
+
The Streaming API, which the tracker is using, still works with http basic authentication only.
|
34
|
+
So we still need both, the oauth credentials for retweeting and the http basic authentication credentials for tracking.
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
==== auth_type
|
36
|
+
== auth_type
|
43
37
|
The auth type is the authentication mechanism you want to use for retweeting.
|
44
38
|
*oauth* or *http*
|
45
39
|
|
46
|
-
|
40
|
+
=== oauth
|
47
41
|
*Warning!* You need to register an application of the type desktop application on http://dev.twitter.com first!
|
48
42
|
|
49
43
|
*key*:: The consumer key Twitter provides you
|
50
44
|
*secret*:: The consumer secret Twitter provides you
|
51
45
|
|
52
|
-
|
46
|
+
=== http
|
53
47
|
*username*:: Your login username
|
54
48
|
*password*:: Your login password
|
55
49
|
|
56
|
-
|
50
|
+
=== filters
|
51
|
+
When a filter is matching on an status, then it won't be retweeted.
|
57
52
|
|
58
53
|
*key*:: this should just hold an description of your filter
|
59
|
-
*type*::
|
54
|
+
*type*:: the type,
|
60
55
|
*value*:: a string, thats the content that should be filtered
|
61
56
|
|
57
|
+
----
|
58
|
+
These types are actually supported:
|
59
|
+
|
60
|
+
*USER*:: The users screenname/nickname *NOT* realname
|
61
|
+
*SOURCE*:: The client which the user is using
|
62
|
+
*LANGUAGE*:: The language that's set in users profile
|
63
|
+
*TIMEZONE*:: The timezone that's set in users profile
|
64
|
+
*CONTENT*:: A word the status text could include
|
65
|
+
----
|
66
|
+
|
62
67
|
I wrote this stuff into my config.yml and load the params with
|
63
68
|
|
64
69
|
require 'yaml'
|
65
70
|
@params = YAML.load_file('config.yml')
|
66
71
|
|
67
|
-
==
|
68
|
-
|
69
|
-
|
72
|
+
== Callbacks
|
73
|
+
|
74
|
+
Since version 0.5.0 streambot has an simple callback mechanism.
|
75
|
+
|
76
|
+
*before_start*:: is fired before the tracker is running
|
77
|
+
*before_match*:: is fired before we start the filtering
|
78
|
+
*match_filter*:: is fired when an filter has matched
|
79
|
+
*before_retweet*:: is fired before retweeting
|
80
|
+
|
81
|
+
=== Examples
|
82
|
+
==== before_match
|
83
|
+
|
84
|
+
Before filtering we just want to print the status id to the console
|
85
|
+
|
86
|
+
bot = StreamBot::Tracker.new(@params, nil,'nowplaying')
|
87
|
+
bot.before_match do
|
88
|
+
status = bot.instance_variable_get("@status")
|
89
|
+
puts status.id
|
90
|
+
end
|
91
|
+
bot.start
|
92
|
+
|
93
|
+
That's just an example. You can do anything you want to do here.
|
94
|
+
|
95
|
+
= Contribution
|
96
|
+
== Testing
|
97
|
+
|
70
98
|
All Tests should inherit from StreamBot::BaseTest
|
71
|
-
|
72
|
-
|
99
|
+
|
100
|
+
== Feature Requests / Issues
|
73
101
|
|
74
102
|
If you ran into some errors? Then don't be shy and file an issue in the issue-tracker[http://github.com/gr4y/streambot/issues]
|
75
103
|
Maybe you have a feature request then file an issue too.
|
76
|
-
|
77
|
-
|
104
|
+
|
105
|
+
== Note on Patches/Pull Requests
|
78
106
|
|
79
107
|
You want to add a feature or you want to patch streambot?
|
80
108
|
* Fork the project.
|
@@ -85,6 +113,6 @@ You want to add a feature or you want to patch streambot?
|
|
85
113
|
(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)
|
86
114
|
* Send me a pull request. Bonus points for topic branches.
|
87
115
|
|
88
|
-
|
116
|
+
= Copyright
|
89
117
|
|
90
118
|
Copyright (c) 2010 Sascha Wessel. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/streambot/tracker.rb
CHANGED
@@ -34,26 +34,33 @@ module StreamBot
|
|
34
34
|
# make status an instance variable for callbacks
|
35
35
|
@status = status
|
36
36
|
username = status.user.screen_name
|
37
|
+
matched = false
|
37
38
|
# if status.user is NOT in blacklist or filters don't match then retweet it
|
38
39
|
before_match
|
39
|
-
matched = false
|
40
40
|
if (@blacklist.nil? || !@blacklist.include?(username)) && !@filters.nil?
|
41
41
|
@filters.each do |key, value|
|
42
42
|
matched = match?(status, value)
|
43
43
|
if matched == true
|
44
44
|
match_filter
|
45
45
|
LOG.debug("Tracker#start - filter #{key} matched!")
|
46
|
+
break
|
46
47
|
end
|
47
48
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@retweet.retweet(status.id)
|
52
|
-
end
|
49
|
+
end
|
50
|
+
if matched == false
|
51
|
+
retweet(status)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
56
|
+
# retweet the status
|
57
|
+
def retweet(status)
|
58
|
+
before_retweet
|
59
|
+
id = status.id
|
60
|
+
LOG.debug("Tracker#retweet - retweet ##{id} from @#{status.user.screen_name}")
|
61
|
+
@retweet.retweet(id)
|
62
|
+
end
|
63
|
+
|
57
64
|
# returns true if an filter is matching
|
58
65
|
def match?(status, filter)
|
59
66
|
@type = filter["type"]
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streambot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.5.0.beta5
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Sascha Wessel
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-28 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -107,7 +106,6 @@ files:
|
|
107
106
|
- VERSION
|
108
107
|
- lib/streambot.rb
|
109
108
|
- lib/streambot/callbacks.rb
|
110
|
-
- lib/streambot/filter.rb
|
111
109
|
- lib/streambot/handler.rb
|
112
110
|
- lib/streambot/http.rb
|
113
111
|
- lib/streambot/oauth.rb
|
@@ -142,13 +140,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
141
|
none: false
|
144
142
|
requirements:
|
145
|
-
- - "
|
143
|
+
- - ">="
|
146
144
|
- !ruby/object:Gem::Version
|
147
145
|
segments:
|
148
|
-
-
|
149
|
-
|
150
|
-
- 1
|
151
|
-
version: 1.3.1
|
146
|
+
- 0
|
147
|
+
version: "0"
|
152
148
|
requirements: []
|
153
149
|
|
154
150
|
rubyforge_project:
|
data/lib/streambot/filter.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module StreamBot
|
2
|
-
class Filter
|
3
|
-
USER="USER"
|
4
|
-
CONTENT="CONTENT"
|
5
|
-
LANGUAGE="LANGUAGE"
|
6
|
-
TIMEZOME="TIMEZONE"
|
7
|
-
|
8
|
-
def initialize(filters=nil, blacklist=nil)
|
9
|
-
@filters = filters
|
10
|
-
if (!@blacklist.nil?)
|
11
|
-
warn "blacklisting is deprecated and will be removed in 0.6.0"
|
12
|
-
end
|
13
|
-
@blacklist = blacklist
|
14
|
-
end
|
15
|
-
|
16
|
-
def match?(status)
|
17
|
-
username = status.user.screen_name
|
18
|
-
if (@blacklist.nil? || !@blacklist.include?(username)) && !@filters.nil?
|
19
|
-
@filters.each do |key, value|
|
20
|
-
@type = filter["type"]
|
21
|
-
@value = filter["value"]
|
22
|
-
if @type == USER then
|
23
|
-
status.user.screen_name.eql?(@value)
|
24
|
-
elsif @type == CONTENT then
|
25
|
-
status.text.include?(@value)
|
26
|
-
elsif @type == LANGUAGE then
|
27
|
-
status.user.lang.eql?(@value)
|
28
|
-
elsif @type == TIMEZONE then
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|