streambot 1.0.0.rc3 → 1.0.0.rc4

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
@@ -53,9 +53,51 @@ I wrote this stuff into my config.yml and load the params with
53
53
  require 'yaml'
54
54
  @params = YAML.load_file('config.yml')
55
55
 
56
- = Callbacks
56
+ = Events / Callbacks
57
57
 
58
- *on_error*:: this callback is fired when an error occures
58
+ To receive something from an event, you need to call the receive method on the event and pass a block into this method
59
+
60
+ tracker.event_name.receive do |params|
61
+ # ...
62
+ end
63
+
64
+ == on_error
65
+
66
+ is fired when an error occures
67
+
68
+ tracker.on_error.receive do |message, trace|
69
+ # print the error message and the stacktrace to STDOUT
70
+ puts message
71
+ puts trace
72
+ # and stop the tracker
73
+ tracker.stop
74
+ end
75
+
76
+ == on_match
77
+
78
+ is fired wenn an filter matched on an status
79
+
80
+ tracker.on_match.receive do |status, filter_path, filter_value|
81
+ puts "filter matched on #{filter_path} with #{filter_value} in status ##{status['id']}"
82
+ end
83
+
84
+ == before_retweet
85
+
86
+ is fired before the tracker retweets a status
87
+
88
+ tracker.before_retweet.receive do |status|
89
+ # print the status to STDOUT
90
+ puts status
91
+ end
92
+
93
+ == after_retweet
94
+
95
+ is fired after the tracker has retweeted a status
96
+
97
+ tracker.after_retweet.receive do |status|
98
+ # save the status with active record
99
+ Retweet.new(status)
100
+ end
59
101
 
60
102
  = Filters
61
103
 
@@ -77,16 +119,6 @@ You can even filter all tweets of users with an evil background color.
77
119
 
78
120
  "user/profile_background_color": "666666"
79
121
 
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
-
90
122
  = Contribution
91
123
  == Testing
92
124
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.rc3
1
+ 1.0.0.rc4
@@ -4,16 +4,19 @@ module StreamBot
4
4
  attr_reader :name
5
5
 
6
6
  def initialize(name)
7
+ LOG.debug "initialize: #{name}"
7
8
  @name = name
8
9
  end
9
10
 
10
- def handle(method=nil, & block)
11
- @handler = method if method
12
- @handler = block if block
11
+ def receive(method=nil, & block)
12
+ LOG.debug "receive: #{self.name}"
13
+ @handler = method if !method.nil?
14
+ @handler = block if !block.nil?
13
15
  end
14
16
 
15
17
  def trigger(* args)
16
- @handler.call(* args) if !@handler.nil?
18
+ LOG.debug "trigger: #{self.name}"
19
+ @handler.call(*args) if !@handler.nil?
17
20
  end
18
21
  end
19
22
  end
@@ -12,20 +12,24 @@ module StreamBot
12
12
  event(name)
13
13
  end
14
14
  end
15
-
15
+
16
16
  private
17
17
  # the real event registration
18
18
  def register_event(name)
19
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
20
+ define_event_method(name);
21
+ end
22
+ end
23
+
24
+ def define_event_method(name)
25
+ variable =:"@#{name}"
26
+ define_method(name) do
27
+ event = instance_variable_get(variable)
28
+ if event == nil
29
+ event = StreamBot::Event.new(name)
30
+ instance_variable_set(variable, event)
28
31
  end
32
+ event
29
33
  end
30
34
  end
31
35
  end
@@ -8,6 +8,7 @@ module StreamBot
8
8
 
9
9
  # retweets the status with given id
10
10
  def retweet(id)
11
+ LOG.info "retweet status ##{id}"
11
12
  @handler.post("/statuses/retweet/#{id}.json", nil)
12
13
  end
13
14
  end
@@ -4,7 +4,7 @@ module StreamBot
4
4
  # This class has serveral callback methods
5
5
  class Tracker
6
6
  extend StreamBot::EventHandler
7
- events :on_error, :on_match
7
+ events :on_error, :on_match, :before_retweet, :after_retweet
8
8
  attr_accessor :auth, :params
9
9
 
10
10
  # initializes the tracker
@@ -24,10 +24,11 @@ module StreamBot
24
24
  if retweet?(status)
25
25
  # one thread per retweet,
26
26
  # cause it's much, much faster
27
+ before_retweet.trigger(status)
27
28
  @thread = Thread.new do
28
29
  @retweet.retweet(status["id"])
29
30
  end
30
- @thread.join
31
+ after_retweet.trigger(status)
31
32
  end
32
33
  end
33
34
  end
@@ -64,11 +65,10 @@ module StreamBot
64
65
  filters.each_pair do |path, value|
65
66
  array = []
66
67
  array << value
67
- array.flatten.each do |aValue|
68
- path_value = ArrayPath.get_path(status, path)
69
- if path_value.eql?(aValue) || path_value.include?(aValue)
70
- LOG.info "filter matched on #{path} with #{aValue} in status ##{status['id']}"
71
- on_match.trigger(status)
68
+ array.flatten.each do |filter_value|
69
+ path_value = StreamBot::ArrayPath.get_path(status, path)
70
+ if path_value.eql?(filter_value) || path_value.include?(filter_value)
71
+ on_match.trigger(status, path, filter_value)
72
72
  retweet = false
73
73
  end
74
74
  end
data/spec/tracker_spec.rb CHANGED
@@ -5,10 +5,10 @@ describe StreamBot::Tracker do
5
5
  before :all do
6
6
  params = YAML.load_file('spec/params.yml')
7
7
  @tracker = StreamBot::Tracker.new(params)
8
- @tracker.on_error do |msg, trace|
8
+ @tracker.on_error.receive do |msg, trace|
9
9
  puts "#{msg}: #{trace}"
10
10
  end
11
- @tracker.on_match do |status, filter_path, filter_value|
11
+ @tracker.on_match.receive do |status, filter_path, filter_value|
12
12
  puts "filter matched on #{filter_path} with #{filter_value} in status ##{status['id']}"
13
13
  end
14
14
  end
@@ -23,7 +23,7 @@ describe StreamBot::Tracker do
23
23
 
24
24
  describe "wait" do
25
25
  it "should sleep for 60 seconds" do
26
- sleep 10
26
+ sleep 60
27
27
  end
28
28
  end
29
29
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: streambot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.rc3
5
+ version: 1.0.0.rc4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sascha Wessel
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-09 00:00:00 +01:00
13
+ date: 2011-02-11 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency