streambot 0.5.4 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -37
- data/Rakefile +15 -34
- data/VERSION +1 -1
- data/lib/streambot.rb +6 -4
- data/lib/streambot/array_path.rb +15 -0
- data/lib/streambot/event.rb +19 -0
- data/lib/streambot/event_handler.rb +32 -0
- data/lib/streambot/retweet.rb +1 -1
- data/lib/streambot/tracker.rb +60 -69
- data/spec/retweet_spec.rb +13 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/tracker_spec.rb +34 -0
- metadata +51 -58
- data/lib/streambot/callbacks.rb +0 -29
- data/test/streambot/base_test.rb +0 -34
- data/test/streambot/test_oauth.rb +0 -31
- data/test/streambot/test_retweet.rb +0 -34
data/README.rdoc
CHANGED
@@ -7,7 +7,7 @@ to get streambot installed, you simply need to run
|
|
7
7
|
|
8
8
|
gem install streambot
|
9
9
|
|
10
|
-
==
|
10
|
+
== development release
|
11
11
|
|
12
12
|
gem install streambot --pre
|
13
13
|
|
@@ -19,10 +19,10 @@ The full rdoc is available on rdoc.info[http://rdoc.info/projects/gr4y/streambot
|
|
19
19
|
|
20
20
|
require 'streambot'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
bot = StreamBot::Tracker.new(@params
|
22
|
+
@params = { 'auth' => { 'username' => 'your username', 'password' => 'your password' },
|
23
|
+
'oauth' => { 'key' => 'your consumer key', 'secret' => 'your consumer secret' },
|
24
|
+
'keywords' => ['nowplaying'] }
|
25
|
+
bot = StreamBot::Tracker.new(@params)
|
26
26
|
bot.start
|
27
27
|
|
28
28
|
= Configuration
|
@@ -38,54 +38,54 @@ You need to register an application of the type desktop application on http://de
|
|
38
38
|
*key*:: The consumer key Twitter provides you
|
39
39
|
*secret*:: The consumer secret Twitter provides you
|
40
40
|
|
41
|
-
===
|
41
|
+
=== auth
|
42
42
|
*username*:: Your login username
|
43
43
|
*password*:: Your login password
|
44
44
|
|
45
|
-
===
|
46
|
-
|
45
|
+
=== keywords
|
46
|
+
:: the list of keywords as an array
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
*value*:: a string, thats the content that should be filtered
|
51
|
-
|
52
|
-
----
|
53
|
-
These types are actually supported:
|
54
|
-
|
55
|
-
*USER*:: The users screenname/nickname *NOT* realname
|
56
|
-
*SOURCE*:: The client which the user is using
|
57
|
-
*LANGUAGE*:: The language that's set in users profile
|
58
|
-
*TIMEZONE*:: The timezone that's set in users profile
|
59
|
-
*CONTENT*:: A word the status text could include
|
60
|
-
----
|
48
|
+
=== filters_config
|
49
|
+
:: the path to the filters.yml file
|
61
50
|
|
62
51
|
I wrote this stuff into my config.yml and load the params with
|
63
52
|
|
64
53
|
require 'yaml'
|
65
54
|
@params = YAML.load_file('config.yml')
|
66
55
|
|
67
|
-
|
56
|
+
= Callbacks
|
68
57
|
|
69
|
-
|
58
|
+
*on_error*:: this callback is fired when an error occures
|
70
59
|
|
71
|
-
|
72
|
-
*before_match*:: is fired before we start the filtering
|
73
|
-
*match_filter*:: is fired when an filter has matched
|
74
|
-
*before_retweet*:: is fired before retweeting
|
60
|
+
= Filters
|
75
61
|
|
76
|
-
|
77
|
-
==== before_match
|
62
|
+
You need to configure the *filters_config* in the params and set the path to the YAML file. At the moment this needs to be an YAML file, cause the tracker is reading this file, every time a new status comes in via the client. I decided to read it on each status, cause I don't wanted to restart the Tracker every time I made a change to the filters.
|
78
63
|
|
79
|
-
|
64
|
+
For example we want to filter all tweets with the source "web", we need to define the following line in our *filters.yml*
|
80
65
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
66
|
+
"source": "web"
|
67
|
+
|
68
|
+
The Tracker checks if the field "source" of the incoming status *includes* OR *is equal* to "web". If you want to filter more than one source, you simply need to write it this way:
|
69
|
+
|
70
|
+
"source": ["web", "TweetDeck"]
|
71
|
+
|
72
|
+
You can define all fields inside the status object. You want to filter tweets by me, so you need to define
|
87
73
|
|
88
|
-
|
74
|
+
"user/screen_name": "gr4y"
|
75
|
+
|
76
|
+
You can even filter all tweets of users with an evil background color.
|
77
|
+
|
78
|
+
"user/profile_background_color": "666666"
|
79
|
+
|
80
|
+
= Example
|
81
|
+
|
82
|
+
@params = YAML.load_file('config.yml')
|
83
|
+
@client = StreamBot::Tracker.new(@params)
|
84
|
+
|
85
|
+
@client.on_error do |msg, stacktrace|
|
86
|
+
puts msg
|
87
|
+
puts stacktrace
|
88
|
+
end
|
89
89
|
|
90
90
|
= Contribution
|
91
91
|
== Testing
|
data/Rakefile
CHANGED
@@ -10,47 +10,22 @@ begin
|
|
10
10
|
gem.email = "swessel@gr4yweb.de"
|
11
11
|
gem.homepage = "http://github.com/gr4y/streambot"
|
12
12
|
gem.authors = ["Sascha Wessel"]
|
13
|
-
gem.post_install_message = File.exist?('USAGE.rdoc') ? File.read('USAGE.rdoc') : ""
|
14
13
|
gem.require_path = 'lib'
|
15
14
|
gem.files = %w(Rakefile) + Dir.glob("{lib}/**/*") + %w(VERSION)
|
16
|
-
|
17
|
-
|
18
|
-
gem.
|
19
|
-
|
20
|
-
gem.add_development_dependency "
|
21
|
-
gem.add_development_dependency "
|
22
|
-
gem.add_development_dependency "
|
23
|
-
|
24
|
-
|
15
|
+
# the runtime dependencies
|
16
|
+
gem.add_runtime_dependency "twistream", "~> 0.2.3"
|
17
|
+
gem.add_runtime_dependency "oauth","~> 0.4.0"
|
18
|
+
# the development dependencies
|
19
|
+
gem.add_development_dependency "bundler", "~> 1.0.0"
|
20
|
+
gem.add_development_dependency "rspec", [">= 2.4.0"]
|
21
|
+
gem.add_development_dependency "webmock","~> 1.0.0"
|
22
|
+
gem.add_development_dependency "rcov","~> 0.9.8"
|
23
|
+
gem.add_development_dependency "reek","~> 1.2.8"
|
25
24
|
end
|
26
25
|
rescue LoadError
|
27
26
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
28
27
|
end
|
29
28
|
|
30
|
-
require 'rake/testtask'
|
31
|
-
Rake::TestTask.new(:test) do |test|
|
32
|
-
test.libs << 'lib' << 'test'
|
33
|
-
test.pattern = 'test/**/test_*.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'rcov/rcovtask'
|
39
|
-
Rcov::RcovTask.new do |test|
|
40
|
-
test.libs << 'test'
|
41
|
-
test.pattern = 'test/**/test_*.rb'
|
42
|
-
test.verbose = true
|
43
|
-
end
|
44
|
-
rescue LoadError
|
45
|
-
task :rcov do
|
46
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
task :build_gem => [:test,:rdoc,:build]
|
51
|
-
task :install_gem => [:build_gem,:install]
|
52
|
-
task :default => [:check_dependencies,:rcov,:reek,:build_gem]
|
53
|
-
|
54
29
|
require 'rake/rdoctask'
|
55
30
|
Rake::RDocTask.new do |rdoc|
|
56
31
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
@@ -65,3 +40,9 @@ Reek::Rake::Task.new do |t|
|
|
65
40
|
t.fail_on_error = false
|
66
41
|
t.verbose = true
|
67
42
|
end
|
43
|
+
|
44
|
+
require 'rspec/core/rake_task'
|
45
|
+
RSpec::Core::RakeTask.new(:spec)
|
46
|
+
|
47
|
+
task :test => [:check_dependencies, :spec]
|
48
|
+
task :default => [:test, :reek, :build]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.rc1
|
data/lib/streambot.rb
CHANGED
@@ -2,19 +2,21 @@ require 'rubygems'
|
|
2
2
|
require 'open-uri'
|
3
3
|
require 'net/http'
|
4
4
|
require 'oauth'
|
5
|
-
require '
|
5
|
+
require 'twistream'
|
6
6
|
require 'logger'
|
7
7
|
require 'yaml'
|
8
8
|
|
9
|
-
require 'streambot/
|
9
|
+
require 'streambot/event'
|
10
|
+
require 'streambot/event_handler'
|
10
11
|
require 'streambot/retweet'
|
11
12
|
require 'streambot/handler'
|
12
13
|
require 'streambot/oauth'
|
14
|
+
require 'streambot/array_path'
|
13
15
|
require 'streambot/tracker'
|
14
16
|
|
15
|
-
module StreamBot
|
17
|
+
module StreamBot
|
16
18
|
LOG = Logger.new(STDOUT)
|
17
19
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
18
20
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
19
|
-
VERSION = ::File.exist?(
|
21
|
+
VERSION = ::File.exist?('VERSION') ? ::File.read('VERSION') : ""
|
20
22
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StreamBot
|
2
|
+
# ArrayPath like XPath, but for Arrays
|
3
|
+
class ArrayPath
|
4
|
+
|
5
|
+
def self.get_path(object, path)
|
6
|
+
# raise "#{object} is not an array" if !object.is_a?(Array)
|
7
|
+
segments = path.chomp.split("/")
|
8
|
+
segments.each do |segment|
|
9
|
+
object = object[segment]
|
10
|
+
end
|
11
|
+
object
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module StreamBot
|
2
|
+
# event class
|
3
|
+
class Event
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def handle(method=nil, & block)
|
11
|
+
@handler = method if method
|
12
|
+
@handler = block if block
|
13
|
+
end
|
14
|
+
|
15
|
+
def trigger(* args)
|
16
|
+
@handler.call(* args) if !@handler.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module StreamBot
|
2
|
+
module EventHandler
|
3
|
+
|
4
|
+
# register an event with the given name
|
5
|
+
def event(name)
|
6
|
+
register_event(name)
|
7
|
+
end
|
8
|
+
|
9
|
+
# register several events with the given names
|
10
|
+
def events(* names)
|
11
|
+
names.each do |name|
|
12
|
+
event(name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
# the real event registration
|
18
|
+
def register_event(name)
|
19
|
+
class_eval do
|
20
|
+
variable =:"@#{name}"
|
21
|
+
define_method(name) do
|
22
|
+
event = instance_variable_get(variable)
|
23
|
+
if event == nil
|
24
|
+
event = StreamBot::Event.new(name)
|
25
|
+
instance_variable_set(variable, event)
|
26
|
+
end
|
27
|
+
event
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/streambot/retweet.rb
CHANGED
data/lib/streambot/tracker.rb
CHANGED
@@ -1,88 +1,79 @@
|
|
1
1
|
module StreamBot
|
2
|
+
|
2
3
|
# The Tracker class that provides a start and a stop method
|
3
4
|
# This class has serveral callback methods
|
4
5
|
class Tracker
|
5
|
-
extend StreamBot::
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# initializing retweet
|
17
|
-
@retweet = StreamBot::Retweet.new(params)
|
18
|
-
# get string with keywords comma separated keywords
|
19
|
-
@keywords=keywords.join(',')
|
20
|
-
# set blacklist array if not nil
|
21
|
-
@blacklist=blacklist
|
22
|
-
if !@blacklist.nil?
|
23
|
-
warn "blacklisting is deprecated and will be removed with streambot 0.6.0"
|
6
|
+
extend StreamBot::EventHandler
|
7
|
+
events :on_error, :on_match
|
8
|
+
attr_accessor :auth, :params
|
9
|
+
|
10
|
+
# initializes the tracker
|
11
|
+
def initialize(params)
|
12
|
+
self.params = params
|
13
|
+
@retweet = StreamBot::Retweet.new(self.params)
|
14
|
+
@client = TwiStream::Client.new(authentication)
|
15
|
+
@client.on_error do |msg, trace|
|
16
|
+
on_error.trigger(msg, trace)
|
24
17
|
end
|
25
|
-
@filters = params['filters']
|
26
18
|
end
|
27
19
|
|
28
|
-
# start the
|
20
|
+
# start the tracker
|
29
21
|
def start
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
matched = false
|
38
|
-
# if status.user is NOT in blacklist or filters don't match then retweet it
|
39
|
-
before_match
|
40
|
-
if (@blacklist.nil? || !@blacklist.include?(username)) && !@filters.nil?
|
41
|
-
@filters.each do |key, value|
|
42
|
-
matched = match?(status, value)
|
43
|
-
if matched == true
|
44
|
-
match_filter
|
45
|
-
LOG.debug("Tracker#start - filter #{key} matched!")
|
46
|
-
break
|
47
|
-
end
|
22
|
+
keywords = self.params["keywords"]
|
23
|
+
@client.filter_by_keywords(keywords) do |status|
|
24
|
+
if retweet?(status)
|
25
|
+
# one thread per retweet,
|
26
|
+
# cause it's much, much faster
|
27
|
+
@thread = Thread.new do
|
28
|
+
@retweet.retweet(status["id"])
|
48
29
|
end
|
49
30
|
end
|
50
|
-
if matched == false
|
51
|
-
retweet(status)
|
52
|
-
end
|
53
31
|
end
|
54
32
|
end
|
55
|
-
|
56
|
-
#
|
57
|
-
def
|
58
|
-
|
59
|
-
id = status.id
|
60
|
-
LOG.debug("Tracker#retweet - retweet ##{id} from @#{status.user.screen_name}")
|
61
|
-
@retweet.retweet(id)
|
33
|
+
|
34
|
+
# stop the tracker
|
35
|
+
def stop
|
36
|
+
@client.stop
|
62
37
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
38
|
+
|
39
|
+
private
|
40
|
+
# returns the authentication object
|
41
|
+
def authentication
|
42
|
+
auth = self.params["auth"]
|
43
|
+
{:user => auth["username"], :pass => auth["password"]}
|
44
|
+
end
|
45
|
+
|
46
|
+
# load the YAML file that is specified in the params
|
47
|
+
def load_filters
|
48
|
+
filters_config = self.params["filters_config" ]
|
49
|
+
if !filters_config.nil? && File.exists?(filters_config)
|
50
|
+
begin
|
51
|
+
YAML::load_file(filters_config)
|
52
|
+
rescue
|
53
|
+
on_error.trigger($!, $@)
|
54
|
+
end
|
80
55
|
end
|
81
56
|
end
|
82
57
|
|
83
|
-
#
|
84
|
-
def
|
85
|
-
|
58
|
+
# decide if the status is retweetable
|
59
|
+
def retweet?(status)
|
60
|
+
filters = load_filters
|
61
|
+
retweet = true
|
62
|
+
if !filters.nil?
|
63
|
+
filters.each_pair do |path, value|
|
64
|
+
array = []
|
65
|
+
array << value
|
66
|
+
array.flatten.each do |aValue|
|
67
|
+
path_value = ArrayPath.get_path(status, path)
|
68
|
+
if path_value.eql?(aValue) || path_value.include?(aValue)
|
69
|
+
LOG.info "filter matched on #{path} with #{aValue} in status ##{status['id']}"
|
70
|
+
on_match.trigger(status)
|
71
|
+
retweet = false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
retweet
|
86
77
|
end
|
87
78
|
end
|
88
79
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StreamBot::Tracker do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
params = YAML.load_file('spec/params.yml')
|
7
|
+
@tracker = StreamBot::Tracker.new(params)
|
8
|
+
@tracker.on_error do |msg, trace|
|
9
|
+
puts "#{msg}: #{trace}"
|
10
|
+
end
|
11
|
+
@tracker.on_match do |status, filter_path, filter_value|
|
12
|
+
puts "filter matched on #{filter_path} with #{filter_value} in status ##{status['id']}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#start" do
|
17
|
+
it "should start" do
|
18
|
+
@tracker.start
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "wait" do
|
23
|
+
it "should sleep for 60 seconds" do
|
24
|
+
sleep 60
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#stop" do
|
29
|
+
it "should stop" do
|
30
|
+
@tracker.stop
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streambot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 4
|
9
|
-
version: 0.5.4
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.0.0.rc1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Sascha Wessel
|
@@ -14,22 +10,18 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-02-07 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
17
|
+
name: twistream
|
22
18
|
prerelease: false
|
23
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
20
|
none: false
|
25
21
|
requirements:
|
26
|
-
- -
|
22
|
+
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 1
|
30
|
-
- 0
|
31
|
-
- 4
|
32
|
-
version: 1.0.4
|
24
|
+
version: 0.2.3
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
@@ -38,60 +30,66 @@ dependencies:
|
|
38
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
31
|
none: false
|
40
32
|
requirements:
|
41
|
-
- -
|
33
|
+
- - ~>
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 4
|
46
|
-
- 0
|
47
35
|
version: 0.4.0
|
48
36
|
type: :runtime
|
49
37
|
version_requirements: *id002
|
50
38
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
39
|
+
name: bundler
|
52
40
|
prerelease: false
|
53
41
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
42
|
none: false
|
55
43
|
requirements:
|
56
|
-
- -
|
44
|
+
- - ~>
|
57
45
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 0
|
61
|
-
- 0
|
62
46
|
version: 1.0.0
|
63
47
|
type: :development
|
64
48
|
version_requirements: *id003
|
65
49
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
50
|
+
name: rspec
|
67
51
|
prerelease: false
|
68
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
53
|
none: false
|
70
54
|
requirements:
|
71
55
|
- - ">="
|
72
56
|
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
- 0
|
75
|
-
- 9
|
76
|
-
- 8
|
77
|
-
version: 0.9.8
|
57
|
+
version: 2.4.0
|
78
58
|
type: :development
|
79
59
|
version_requirements: *id004
|
80
60
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
61
|
+
name: webmock
|
82
62
|
prerelease: false
|
83
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
64
|
none: false
|
85
65
|
requirements:
|
86
|
-
- -
|
66
|
+
- - ~>
|
87
67
|
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
- 1
|
90
|
-
- 2
|
91
|
-
- 8
|
92
|
-
version: 1.2.8
|
68
|
+
version: 1.0.0
|
93
69
|
type: :development
|
94
70
|
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rcov
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.9.8
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: reek
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.2.8
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
95
93
|
description: a simple gem that tracks several keywords via twitter streaming api and re-publish it on twitter
|
96
94
|
email: swessel@gr4yweb.de
|
97
95
|
executables: []
|
@@ -105,26 +103,25 @@ files:
|
|
105
103
|
- Rakefile
|
106
104
|
- VERSION
|
107
105
|
- lib/streambot.rb
|
108
|
-
- lib/streambot/
|
106
|
+
- lib/streambot/array_path.rb
|
107
|
+
- lib/streambot/event.rb
|
108
|
+
- lib/streambot/event_handler.rb
|
109
109
|
- lib/streambot/handler.rb
|
110
110
|
- lib/streambot/oauth.rb
|
111
111
|
- lib/streambot/retweet.rb
|
112
112
|
- lib/streambot/tracker.rb
|
113
113
|
- LICENSE
|
114
114
|
- README.rdoc
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
115
|
+
- spec/retweet_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/tracker_spec.rb
|
118
118
|
has_rdoc: true
|
119
119
|
homepage: http://github.com/gr4y/streambot
|
120
120
|
licenses: []
|
121
121
|
|
122
|
-
post_install_message:
|
123
|
-
|
124
|
-
|
125
|
-
code is available on github[http://github.com/gr4y/streambot] "
|
126
|
-
rdoc_options:
|
127
|
-
- --charset=UTF-8
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
|
128
125
|
require_paths:
|
129
126
|
- lib
|
130
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -132,25 +129,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
129
|
requirements:
|
133
130
|
- - ">="
|
134
131
|
- !ruby/object:Gem::Version
|
135
|
-
segments:
|
136
|
-
- 0
|
137
132
|
version: "0"
|
138
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
134
|
none: false
|
140
135
|
requirements:
|
141
|
-
- - "
|
136
|
+
- - ">"
|
142
137
|
- !ruby/object:Gem::Version
|
143
|
-
|
144
|
-
- 0
|
145
|
-
version: "0"
|
138
|
+
version: 1.3.1
|
146
139
|
requirements: []
|
147
140
|
|
148
141
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.5.0
|
150
143
|
signing_key:
|
151
144
|
specification_version: 3
|
152
145
|
summary: retweeting tweets with specified keywords on twitter
|
153
146
|
test_files:
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
147
|
+
- spec/retweet_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/tracker_spec.rb
|
data/lib/streambot/callbacks.rb
DELETED
@@ -1,29 +0,0 @@
|
|
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
|
data/test/streambot/base_test.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'webmock'
|
4
|
-
require 'yaml'
|
5
|
-
include WebMock
|
6
|
-
|
7
|
-
require 'streambot'
|
8
|
-
|
9
|
-
module StreamBot
|
10
|
-
# The base of all tests in this projet
|
11
|
-
#
|
12
|
-
# class TestName < StreamBot::BaseTest
|
13
|
-
#
|
14
|
-
# def setup
|
15
|
-
# super
|
16
|
-
# # implementation goes here
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
class BaseTest < Test::Unit::TestCase
|
20
|
-
|
21
|
-
# reading config.yml and assign all keys to instance
|
22
|
-
def read_config
|
23
|
-
yml_config = YAML.load_file(File.dirname(__FILE__) + "/config.yml")
|
24
|
-
yml_config.each do |key, value|
|
25
|
-
instance_variable_set("@#{key}", value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# :nodoc:
|
30
|
-
def setup
|
31
|
-
self.read_config
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'streambot/base_test'
|
2
|
-
|
3
|
-
module StreamBot
|
4
|
-
# test for http wrapper class
|
5
|
-
class TestOAuth < StreamBot::BaseTest
|
6
|
-
# setup
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
WebMock.allow_net_connect!
|
10
|
-
@oauth = StreamBot::OAuth.new(@params['oauth'])
|
11
|
-
stub_request(:post,"http://api.twitter.com/statuses/update.json").to_return(:body=>"response")
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_verify_credentials
|
15
|
-
json = @oauth.get('/account/verify_credentials.json')
|
16
|
-
assert_not_nil(json)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_post
|
20
|
-
WebMock.disable_net_connect!
|
21
|
-
json = @oauth.post('/statuses/update.json',{:status => 'test'})
|
22
|
-
assert_not_nil(json)
|
23
|
-
assert_equal("response",json)
|
24
|
-
end
|
25
|
-
|
26
|
-
# nil all variables
|
27
|
-
def teardown
|
28
|
-
@oauth = nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'streambot/base_test'
|
2
|
-
|
3
|
-
module StreamBot
|
4
|
-
# the test for testing retweet functionality
|
5
|
-
class TestRetweet < StreamBot::BaseTest
|
6
|
-
# setup the test
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
@retweet = StreamBot::Retweet.new(@params)
|
10
|
-
if @params['auth_type'] == "oauth"
|
11
|
-
stub_request(:post, "http://api.twitter.com/statuses/retweet/12355936428.json").to_return(:body => "response")
|
12
|
-
elsif @params['auth_type'] == "http"
|
13
|
-
stub_request(:post, "http://#{@params['http']['username']}:#{@params['http']['password']}@api.twitter.com/statuses/retweet/12355936428.json").to_return(:body => "response")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# retweet
|
18
|
-
def test_retweet
|
19
|
-
# no permission to access web!
|
20
|
-
WebMock.disable_net_connect!
|
21
|
-
# retweet the given id
|
22
|
-
response = @retweet.retweet(@id)
|
23
|
-
# assertion
|
24
|
-
assert_not_nil(response)
|
25
|
-
assert_equal("response", response)
|
26
|
-
end
|
27
|
-
|
28
|
-
# teardown the test
|
29
|
-
# nil all instance variables
|
30
|
-
def teardown
|
31
|
-
@id, @retweet = nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|