tweetstream 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tweetstream might be problematic. Click here for more details.

data/README.md CHANGED
@@ -15,38 +15,42 @@ Usage
15
15
 
16
16
  Using TweetStream is quite simple:
17
17
 
18
- require 'rubygems'
19
- require 'tweetstream'
20
-
21
- TweetStream.configure do |config|
22
- config.consumer_key = 'abcdefghijklmnopqrstuvwxyz'
23
- config.consumer_secret = '0123456789'
24
- config.oauth_token = 'abcdefghijklmnopqrstuvwxyz'
25
- config.oauth_token_secret = '0123456789'
26
- config.auth_method = :oauth
27
- config.parser = :yajl
28
- end
29
-
30
- # This will pull a sample of all tweets based on
31
- # your Twitter account's Streaming API role.
32
- TweetStream::Client.new.sample do |status|
33
- # The status object is a special Hash with
34
- # method access to its keys.
35
- puts "#{status.text}"
36
- end
18
+ ```ruby
19
+ require 'rubygems'
20
+ require 'tweetstream'
21
+
22
+ TweetStream.configure do |config|
23
+ config.consumer_key = 'abcdefghijklmnopqrstuvwxyz'
24
+ config.consumer_secret = '0123456789'
25
+ config.oauth_token = 'abcdefghijklmnopqrstuvwxyz'
26
+ config.oauth_token_secret = '0123456789'
27
+ config.auth_method = :oauth
28
+ config.parser = :yajl
29
+ end
30
+
31
+ # This will pull a sample of all tweets based on
32
+ # your Twitter account's Streaming API role.
33
+ TweetStream::Client.new.sample do |status|
34
+ # The status object is a special Hash with
35
+ # method access to its keys.
36
+ puts "#{status.text}"
37
+ end
38
+ ```
37
39
 
38
40
  You can also use it to track keywords or follow a given set of
39
41
  user ids:
40
42
 
41
- # Use 'track' to track a list of single-word keywords
42
- TweetStream::Client.new.track('term1', 'term2') do |status|
43
- puts "#{status.text}"
44
- end
43
+ ```ruby
44
+ # Use 'track' to track a list of single-word keywords
45
+ TweetStream::Client.new.track('term1', 'term2') do |status|
46
+ puts "#{status.text}"
47
+ end
45
48
 
46
- # Use 'follow' to follow a group of user ids (integers, not screen names)
47
- TweetStream::Client.new.follow(14252, 53235) do |status|
48
- puts "#{status.text}"
49
- end
49
+ # Use 'follow' to follow a group of user ids (integers, not screen names)
50
+ TweetStream::Client.new.follow(14252, 53235) do |status|
51
+ puts "#{status.text}"
52
+ end
53
+ ```
50
54
 
51
55
  The methods available to TweetStream::Client will be kept in parity
52
56
  with the methods available on the Streaming API wiki page.
@@ -56,26 +60,30 @@ Using the Twitter Userstream
56
60
 
57
61
  Using the Twitter userstream works similarly to the regular streaming, except you use the userstream method.
58
62
 
59
- # Use 'userstream' to get message from your stream
60
- TweetStream::Client.new.userstream do |status|
61
- puts status.text
62
- end
63
+ ```ruby
64
+ # Use 'userstream' to get message from your stream
65
+ TweetStream::Client.new.userstream do |status|
66
+ puts status.text
67
+ end
68
+ ```
63
69
 
64
70
  You also can use method hooks for both regular timeline statuses and direct messages.
65
71
 
66
- client = TweetStream::Client.new
72
+ ```ruby
73
+ client = TweetStream::Client.new
67
74
 
68
- client.on_direct_message do |direct_message|
69
- puts "direct message"
70
- puts direct_message.text
71
- end
75
+ client.on_direct_message do |direct_message|
76
+ puts "direct message"
77
+ puts direct_message.text
78
+ end
72
79
 
73
- client.on_timeline_status do |status|
74
- puts "timeline status"
75
- puts status.text
76
- end
80
+ client.on_timeline_status do |status|
81
+ puts "timeline status"
82
+ puts status.text
83
+ end
77
84
 
78
- client.userstream
85
+ client.userstream
86
+ ```
79
87
 
80
88
  Configuration and Changes in 1.1.0
81
89
  ----------------------------------
@@ -84,27 +92,33 @@ As of version 1.1.0.rc1 TweetStream supports OAuth. Please note that in order
84
92
  to support OAuth, the `TweetStream::Client` initializer no longer accepts a
85
93
  username/password. `TweetStream::Client` now accepts a hash:
86
94
 
87
- TweetStream::Client.new(:username => 'you', :password => 'pass')
95
+ ```ruby
96
+ TweetStream::Client.new(:username => 'you', :password => 'pass')
97
+ ```
88
98
 
89
99
  Alternatively, you can configure TweetStream via the configure method:
90
100
 
91
- TweetStream.configure do |config|
92
- config.consumer_key = 'cVcIw5zoLFE2a4BdDsmmA'
93
- config.consumer_secret = 'yYgVgvTT9uCFAi2IuscbYTCqwJZ1sdQxzISvLhNWUA'
94
- config.oauth_token = '4618-H3gU7mjDQ7MtFkAwHhCqD91Cp4RqDTp1AKwGzpHGL3I'
95
- config.oauth_token_secret = 'xmc9kFgOXpMdQ590Tho2gV7fE71v5OmBrX8qPGh7Y'
96
- config.auth_method = :oauth
97
- config.parser = :yajl
98
- end
101
+ ```ruby
102
+ TweetStream.configure do |config|
103
+ config.consumer_key = 'cVcIw5zoLFE2a4BdDsmmA'
104
+ config.consumer_secret = 'yYgVgvTT9uCFAi2IuscbYTCqwJZ1sdQxzISvLhNWUA'
105
+ config.oauth_token = '4618-H3gU7mjDQ7MtFkAwHhCqD91Cp4RqDTp1AKwGzpHGL3I'
106
+ config.oauth_token_secret = 'xmc9kFgOXpMdQ590Tho2gV7fE71v5OmBrX8qPGh7Y'
107
+ config.auth_method = :oauth
108
+ config.parser = :yajl
109
+ end
110
+ ```
99
111
 
100
112
  If you are using Basic Auth:
101
113
 
102
- TweetStream.configure do |config|
103
- config.username = 'username'
104
- config.password = 'password'
105
- config.auth_method = :basic
106
- config.parser = :yajl
107
- end
114
+ ```ruby
115
+ TweetStream.configure do |config|
116
+ config.username = 'username'
117
+ config.password = 'password'
118
+ config.auth_method = :basic
119
+ config.parser = :yajl
120
+ end
121
+ ```
108
122
 
109
123
  TweetStream assumes OAuth by default. If you are using Basic Auth, it is recommended
110
124
  that you update your code to use OAuth as Twitter is likely to phase out Basic Auth
@@ -116,10 +130,12 @@ Swappable JSON Parsing
116
130
  As of version 1.1, TweetStream supports swappable JSON backends via MultiJson. You can
117
131
  specify a parser during configuration:
118
132
 
119
- # Parse tweets using Yajl-Ruby
120
- TweetStream.configure do |config|
121
- config.parser = :yajl
122
- end.
133
+ ```ruby
134
+ # Parse tweets using Yajl-Ruby
135
+ TweetStream.configure do |config|
136
+ config.parser = :yajl
137
+ end
138
+ ```
123
139
 
124
140
  Available options are `:yajl`, `:json_gem`, `:json_pure`, and `:ok_json`.
125
141
 
@@ -131,37 +147,43 @@ Specifically, it does so when a status is deleted or rate limitations
131
147
  have caused some tweets not to appear in the stream. To handle these,
132
148
  you can use the on_delete and on_limit methods. Example:
133
149
 
134
- @client = TweetStream::Client.new
150
+ ```ruby
151
+ @client = TweetStream::Client.new
135
152
 
136
- @client.on_delete do |status_id, user_id|
137
- Tweet.delete(status_id)
138
- end
153
+ @client.on_delete do |status_id, user_id|
154
+ Tweet.delete(status_id)
155
+ end
139
156
 
140
- @client.on_limit do |skip_count|
141
- # do something
142
- end
157
+ @client.on_limit do |skip_count|
158
+ # do something
159
+ end
143
160
 
144
- @client.track('intridea')
161
+ @client.track('intridea')
162
+ ```
145
163
 
146
164
  The on_delete and on_limit methods can also be chained, like so:
147
165
 
148
- TweetStream::Client.new.on_delete{ |status_id, user_id|
149
- Tweet.delete(status_id)
150
- }.on_limit { |skip_count|
151
- # do something
152
- }.track('intridea') do |status|
153
- # do something with the status like normal
154
- end
166
+ ```ruby
167
+ TweetStream::Client.new.on_delete{ |status_id, user_id|
168
+ Tweet.delete(status_id)
169
+ }.on_limit { |skip_count|
170
+ # do something
171
+ }.track('intridea') do |status|
172
+ # do something with the status like normal
173
+ end
174
+ ```
155
175
 
156
176
  You can also provide `:delete` and/or `:limit`
157
177
  options when you make your method call:
158
178
 
159
- TweetStream::Client.new.track('intridea',
160
- :delete => Proc.new{ |status_id, user_id| # do something },
161
- :limit => Proc.new{ |skip_count| # do something }
162
- ) do |status|
163
- # do something with the status like normal
164
- end
179
+ ```ruby
180
+ TweetStream::Client.new.track('intridea',
181
+ :delete => Proc.new{ |status_id, user_id| # do something },
182
+ :limit => Proc.new{ |skip_count| # do something }
183
+ ) do |status|
184
+ # do something with the status like normal
185
+ end
186
+ ```
165
187
 
166
188
  Twitter recommends honoring deletions as quickly as possible, and
167
189
  you would likely be wise to integrate this functionality into your
@@ -177,16 +199,28 @@ by you in `on_error` will be called. Note that this does not
177
199
  indicate something is actually wrong, just that Twitter is momentarily
178
200
  down. It could be for routine maintenance, etc.
179
201
 
180
- TweetStream::Client.new.on_error do |message|
181
- # Log your error message somewhere
182
- end.track('term') do |status|
183
- # Do things when nothing's wrong
184
- end
202
+ ```ruby
203
+ TweetStream::Client.new.on_error do |message|
204
+ # Log your error message somewhere
205
+ end.track('term') do |status|
206
+ # Do things when nothing's wrong
207
+ end
208
+ ```
185
209
 
186
210
  However, if the maximum number of reconnect attempts has been reached,
187
211
  TweetStream will raise a `TweetStream::ReconnectError` with
188
212
  information about the timeout and number of retries attempted.
189
213
 
214
+ On reconnect, the block specified by you in `on_reconnect` will be called:
215
+
216
+ ```ruby
217
+ TweetStream::Client.new.on_reconnect do |timeout, retries|
218
+ # Do something with the reconnect
219
+ end.track('term') do |status|
220
+ # Do things when nothing's wrong
221
+ end
222
+ ```
223
+
190
224
  Terminating a TweetStream
191
225
  -------------------------
192
226
 
@@ -195,12 +229,14 @@ track or follow tweet streams. In the case that you need to terminate
195
229
  a stream, you may add a second argument to your block that will yield
196
230
  the client itself:
197
231
 
198
- # Stop after collecting 10 statuses
199
- @statuses = []
200
- TweetStream::Client.new.sample do |status, client|
201
- @statuses << status
202
- client.stop if @statuses.size >= 10
203
- end
232
+ ```ruby
233
+ # Stop after collecting 10 statuses
234
+ @statuses = []
235
+ TweetStream::Client.new.sample do |status, client|
236
+ @statuses << status
237
+ client.stop if @statuses.size >= 10
238
+ end
239
+ ```
204
240
 
205
241
  When `stop` is called, TweetStream will return from the block
206
242
  the last successfully yielded status, allowing you to make note of
@@ -212,10 +248,12 @@ Daemonizing
212
248
  It is also possible to create a daemonized script quite easily
213
249
  using the TweetStream library:
214
250
 
215
- # The third argument is an optional process name
216
- TweetStream::Daemon.new('tracker').track('term1', 'term2') do |status|
217
- # do something in the background
218
- end
251
+ ```ruby
252
+ # The third argument is an optional process name
253
+ TweetStream::Daemon.new('tracker').track('term1', 'term2') do |status|
254
+ # do something in the background
255
+ end
256
+ ```
219
257
 
220
258
  If you put the above into a script and run the script with `ruby scriptname.rb`,
221
259
  you will see a list of daemonization commands such as start, stop, and run.
@@ -254,6 +254,22 @@ module TweetStream
254
254
  end
255
255
  end
256
256
 
257
+ # Set a Proc to be run on reconnect.
258
+ #
259
+ # @client = TweetStream::Client.new
260
+ # @client.on_reconnect do |timeout, retries|
261
+ # # Make note of the reconnection
262
+ # end
263
+ #
264
+ def on_reconnect(&block)
265
+ if block_given?
266
+ @on_reconnect = block
267
+ self
268
+ else
269
+ @on_reconnect
270
+ end
271
+ end
272
+
257
273
  # Set a Proc to be run when connection established.
258
274
  # Called in EventMachine::Connection#post_init
259
275
  #
@@ -294,6 +310,7 @@ module TweetStream
294
310
  delete_proc = query_parameters.delete(:delete) || self.on_delete
295
311
  limit_proc = query_parameters.delete(:limit) || self.on_limit
296
312
  error_proc = query_parameters.delete(:error) || self.on_error
313
+ reconnect_proc = query_parameters.delete(:reconnect) || self.on_reconnect
297
314
  inited_proc = query_parameters.delete(:inited) || self.on_inited
298
315
  direct_message_proc = query_parameters.delete(:direct_message) || self.on_direct_message
299
316
  timeline_status_proc = query_parameters.delete(:timeline_status) || self.on_timeline_status
@@ -374,6 +391,10 @@ module TweetStream
374
391
  error_proc.call(message) if error_proc.is_a?(Proc)
375
392
  end
376
393
 
394
+ @stream.on_reconnect do |timeout, retries|
395
+ reconnect_proc.call(timeout, retries) if reconnect_proc.is_a?(Proc)
396
+ end
397
+
377
398
  @stream.on_max_reconnects do |timeout, retries|
378
399
  raise TweetStream::ReconnectError.new(timeout, retries)
379
400
  end
@@ -1,3 +1,3 @@
1
1
  module TweetStream
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
3
3
  end
@@ -54,6 +54,7 @@ describe TweetStream::Client do
54
54
  :each_item => true,
55
55
  :on_error => true,
56
56
  :on_max_reconnects => true,
57
+ :on_reconnect => true,
57
58
  :connection_completed => true
58
59
  )
59
60
  EM.stub!(:run).and_yield
@@ -287,7 +288,7 @@ describe TweetStream::Client do
287
288
  end
288
289
  end
289
290
 
290
- %w(on_delete on_limit on_inited).each do |proc_setter|
291
+ %w(on_delete on_limit on_inited on_reconnect).each do |proc_setter|
291
292
  describe "##{proc_setter}" do
292
293
  it 'should set when a block is given' do
293
294
  proc = Proc.new{|a,b| puts a }
@@ -369,6 +370,7 @@ describe TweetStream::Client do
369
370
  :each_item => true,
370
371
  :on_error => true,
371
372
  :on_max_reconnects => true,
373
+ :on_reconnect => true,
372
374
  :connection_completed => true
373
375
  )
374
376
  EM.stub!(:run).and_yield
@@ -13,6 +13,7 @@ describe TweetStream do
13
13
  :each_item => true,
14
14
  :on_error => true,
15
15
  :on_max_reconnects => true,
16
+ :on_reconnect => true,
16
17
  :connection_completed => true
17
18
  )
18
19
  EM.stub!(:run).and_yield
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-21 00:00:00.000000000Z
12
+ date: 2011-11-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twitter-stream
16
- requirement: &2153351480 !ruby/object:Gem::Requirement
16
+ requirement: &2156592560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.1.14
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153351480
24
+ version_requirements: *2156592560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: daemons
27
- requirement: &2153351020 !ruby/object:Gem::Requirement
27
+ requirement: &2156592100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153351020
35
+ version_requirements: *2156592100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2153350560 !ruby/object:Gem::Requirement
38
+ requirement: &2156591640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153350560
46
+ version_requirements: *2156591640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &2153350100 !ruby/object:Gem::Requirement
49
+ requirement: &2156591180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.9'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153350100
57
+ version_requirements: *2156591180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &2153349640 !ruby/object:Gem::Requirement
60
+ requirement: &2156579120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.5.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153349640
68
+ version_requirements: *2156579120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &2153349180 !ruby/object:Gem::Requirement
71
+ requirement: &2156578620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.7'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153349180
79
+ version_requirements: *2156578620
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rdiscount
82
- requirement: &2153348720 !ruby/object:Gem::Requirement
82
+ requirement: &2156578160 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '1.6'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153348720
90
+ version_requirements: *2156578160
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &2153348260 !ruby/object:Gem::Requirement
93
+ requirement: &2156577520 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '2.7'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153348260
101
+ version_requirements: *2156577520
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: yajl-ruby
104
- requirement: &2153347800 !ruby/object:Gem::Requirement
104
+ requirement: &2156576840 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '1.0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2153347800
112
+ version_requirements: *2156576840
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: json
115
- requirement: &2153347340 !ruby/object:Gem::Requirement
115
+ requirement: &2156576120 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.5.1
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2153347340
123
+ version_requirements: *2156576120
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: guard-rspec
126
- requirement: &2153346840 !ruby/object:Gem::Requirement
126
+ requirement: &2156575520 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: 0.4.3
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2153346840
134
+ version_requirements: *2156575520
135
135
  description: TweetStream allows you to easily consume the Twitter Streaming API utilizing
136
136
  the YAJL Ruby gem.
137
137
  email: