tweetstream 2.0.0 → 2.0.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ Version 2.0.1
2
+ =============
3
+
4
+ * Fixed Twitter gem objects
5
+ * Added on_unauthorized callback method (koenpunt)
6
+
1
7
  Version 2.0.0
2
8
  =============
3
9
 
@@ -5,7 +11,7 @@ Version 2.0.0
5
11
  * Switched to [em-twitter](https://github.com/spagalloco/em-twitter) for underlying streaming lib
6
12
  * Switched to Twitter gem objects instead of custom hashes, see [47e5cd3d21a9562b3d959bc231009af460b37567](https://github.com/intridea/tweetstream/commit/47e5cd3d21a9562b3d959bc231009af460b37567) for details (sferik)
7
13
  * Made OAuth the default authentication method
8
- * Removed on_interval callback
14
+ * Removed on_interval callback method
9
15
  * Removed parser configuration option
10
16
 
11
17
  Version 1.1.5
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'twitter', :github => 'jnunemaker/twitter'
4
+
3
5
  gemspec
@@ -220,6 +220,22 @@ module TweetStream
220
220
  end
221
221
  end
222
222
 
223
+ # Set a Proc to be run when an HTTP status 401 is encountered while
224
+ # connecting to Twitter. This could happen when system clock drift
225
+ # has occured.
226
+ #
227
+ # If no block is given, it will return the currently set
228
+ # unauthorized proc. When a block is given, the TweetStream::Client
229
+ # object is returned to allow for chaining.
230
+ def on_unauthorized(&block)
231
+ if block_given?
232
+ @on_unauthorized = block
233
+ self
234
+ else
235
+ @on_unauthorized
236
+ end
237
+ end
238
+
223
239
  # Set a Proc to be run when a direct message is encountered in the
224
240
  # processing of the stream.
225
241
  #
@@ -353,6 +369,7 @@ module TweetStream
353
369
  scrub_geo_proc = query_parameters.delete(:scrub_geo) || self.on_scrub_geo
354
370
  limit_proc = query_parameters.delete(:limit) || self.on_limit
355
371
  error_proc = query_parameters.delete(:error) || self.on_error
372
+ unauthorized_proc = query_parameters.delete(:unauthorized) || self.on_unauthorized
356
373
  reconnect_proc = query_parameters.delete(:reconnect) || self.on_reconnect
357
374
  inited_proc = query_parameters.delete(:inited) || self.on_inited
358
375
  direct_message_proc = query_parameters.delete(:direct_message) || self.on_direct_message
@@ -377,7 +394,7 @@ module TweetStream
377
394
  @stream = EM::Twitter::Client.connect(stream_params)
378
395
  @stream.each do |item|
379
396
  begin
380
- hash = MultiJson.decode(item)
397
+ hash = MultiJson.decode(item, :symbolize_keys => true)
381
398
  rescue MultiJson::DecodeError
382
399
  error_proc.call("MultiJson::DecodeError occured in stream: #{item}") if error_proc.is_a?(Proc)
383
400
  next
@@ -388,20 +405,20 @@ module TweetStream
388
405
  next
389
406
  end
390
407
 
391
- if hash['control'] && hash['control']['control_uri']
392
- @control_uri = hash['control']['control_uri']
408
+ if hash[:control] && hash[:control][:control_uri]
409
+ @control_uri = hash[:control][:control_uri]
393
410
  require 'tweetstream/site_stream_client'
394
411
  @control = TweetStream::SiteStreamClient.new(@control_uri, options)
395
412
  @control.on_error(&self.on_error)
396
- elsif hash['delete'] && hash['delete']['status']
397
- delete_proc.call(hash['delete']['status']['id'], hash['delete']['status']['user_id']) if delete_proc.is_a?(Proc)
398
- elsif hash['scrub_geo'] && hash['scrub_geo']['up_to_status_id']
399
- scrub_geo_proc.call(hash['scrub_geo']['up_to_status_id'], hash['scrub_geo']['user_id']) if scrub_geo_proc.is_a?(Proc)
400
- elsif hash['limit'] && hash['limit']['track']
401
- limit_proc.call(hash['limit']['track']) if limit_proc.is_a?(Proc)
402
- elsif hash['direct_message']
403
- yield_message_to direct_message_proc, Twitter::DirectMessage.new(hash['direct_message'])
404
- elsif hash['text'] && hash['user']
413
+ elsif hash[:delete] && hash[:delete][:status]
414
+ delete_proc.call(hash[:delete][:status][:id], hash[:delete][:status][:user_id]) if delete_proc.is_a?(Proc)
415
+ elsif hash[:scrub_geo] && hash[:scrub_geo][:up_to_status_id]
416
+ scrub_geo_proc.call(hash[:scrub_geo][:up_to_status_id], hash[:scrub_geo][:user_id]) if scrub_geo_proc.is_a?(Proc)
417
+ elsif hash[:limit] && hash[:limit][:track]
418
+ limit_proc.call(hash[:limit][:track]) if limit_proc.is_a?(Proc)
419
+ elsif hash[:direct_message]
420
+ yield_message_to direct_message_proc, Twitter::DirectMessage.new(hash[:direct_message])
421
+ elsif hash[:text] && hash[:user]
405
422
  @last_status = Twitter::Status.new(hash)
406
423
  yield_message_to timeline_status_proc, @last_status
407
424
 
@@ -415,7 +432,7 @@ module TweetStream
415
432
  yield @last_status, self
416
433
  end
417
434
  end
418
- elsif hash['for_user']
435
+ elsif hash[:for_user]
419
436
  @message = hash
420
437
 
421
438
  if block_given?
@@ -437,6 +454,10 @@ module TweetStream
437
454
  error_proc.call(message) if error_proc.is_a?(Proc)
438
455
  end
439
456
 
457
+ @stream.on_unauthorized do
458
+ unauthorized_proc.call if unauthorized_proc.is_a?(Proc)
459
+ end
460
+
440
461
  @stream.on_reconnect do |timeout, retries|
441
462
  reconnect_proc.call(timeout, retries) if reconnect_proc.is_a?(Proc)
442
463
  end
@@ -1,3 +1,3 @@
1
1
  module TweetStream
2
- VERSION = '2.0.0' unless defined?(TweetStream::VERSION)
2
+ VERSION = '2.0.1' unless defined?(TweetStream::VERSION)
3
3
  end
@@ -57,7 +57,8 @@ describe TweetStream::Client do
57
57
  :on_max_reconnects => true,
58
58
  :on_reconnect => true,
59
59
  :connection_completed => true,
60
- :on_no_data_received => true
60
+ :on_no_data_received => true,
61
+ :on_unauthorized => true
61
62
  )
62
63
  EM.stub!(:run).and_yield
63
64
  EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -147,7 +148,7 @@ describe TweetStream::Client do
147
148
  yielded_hash = hash
148
149
  end.track('abc')
149
150
  yielded_hash.should_not be_nil
150
- yielded_hash['id'].should == 1234
151
+ yielded_hash[:id].should == 1234
151
152
  end
152
153
  it 'yields itself if block has an arity of 2' do
153
154
  hash = {:id => 1234}
@@ -325,7 +326,7 @@ describe TweetStream::Client do
325
326
  end
326
327
  end
327
328
 
328
- %w(on_delete on_limit on_inited on_reconnect on_no_data_received).each do |proc_setter|
329
+ %w(on_delete on_limit on_inited on_reconnect on_no_data_received on_unauthorized).each do |proc_setter|
329
330
  describe "##{proc_setter}" do
330
331
  it 'should set when a block is given' do
331
332
  proc = Proc.new{|a,b| puts a }
@@ -371,6 +372,7 @@ describe TweetStream::Client do
371
372
  :on_reconnect => true,
372
373
  :connection_completed => true,
373
374
  :on_no_data_received => true,
375
+ :on_unauthorized => true,
374
376
  :stop => true
375
377
  )
376
378
  EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -406,7 +408,8 @@ describe TweetStream::Client do
406
408
  :on_max_reconnects => true,
407
409
  :on_reconnect => true,
408
410
  :connection_completed => true,
409
- :on_no_data_received => true
411
+ :on_no_data_received => true,
412
+ :on_unauthorized => true
410
413
  )
411
414
  EM.stub!(:run).and_yield
412
415
  EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -449,7 +452,8 @@ describe TweetStream::Client do
449
452
  :on_max_reconnects => true,
450
453
  :on_reconnect => true,
451
454
  :connection_completed => true,
452
- :on_no_data_received => true
455
+ :on_no_data_received => true,
456
+ :on_unauthorized => true
453
457
  )
454
458
  EM.stub!(:run).and_yield
455
459
  EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -548,9 +552,9 @@ describe TweetStream::Client do
548
552
  yielded_status = message
549
553
  end
550
554
  yielded_status.should_not be_nil
551
- yielded_status['for_user'].should == '12345'
552
- yielded_status['message']['user']['screen_name'].should == 'monkey'
553
- yielded_status['message']['text'].should == 'Oo oo aa aa'
555
+ yielded_status[:for_user].should == '12345'
556
+ yielded_status[:message][:user][:screen_name].should == 'monkey'
557
+ yielded_status[:message][:text].should == 'Oo oo aa aa'
554
558
  end
555
559
  it 'yields itself if block has an arity of 2' do
556
560
  @stream.should_receive(:each).and_yield(@ss_message.to_json)
@@ -15,7 +15,8 @@ describe TweetStream do
15
15
  :on_max_reconnects => true,
16
16
  :on_reconnect => true,
17
17
  :connection_completed => true,
18
- :on_no_data_received => true
18
+ :on_no_data_received => true,
19
+ :on_unauthorized => true
19
20
  )
20
21
  EM.stub!(:run).and_yield
21
22
  EM::Twitter::Client.stub!(:connect).and_return(@stream)
data/tweetstream.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'http://github.com/intridea/tweetstream'
13
13
 
14
14
  s.add_dependency 'em-twitter', '~> 0.1'
15
- s.add_dependency 'twitter', '~> 2.2'
15
+ s.add_dependency 'twitter', '~> 3.0.0.rc.1'
16
16
  s.add_dependency 'daemons', '~> 1.1'
17
17
  s.add_dependency 'multi_json', '~> 1.3'
18
18
  s.add_dependency 'em-http-request', '~> 1.0.2'
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: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-01 00:00:00.000000000 Z
13
+ date: 2012-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: em-twitter
17
- requirement: &70257167536020 !ruby/object:Gem::Requirement
17
+ requirement: &70341058157740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,21 +22,21 @@ dependencies:
22
22
  version: '0.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70257167536020
25
+ version_requirements: *70341058157740
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: twitter
28
- requirement: &70257167535420 !ruby/object:Gem::Requirement
28
+ requirement: &70341058157100 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '2.2'
33
+ version: 3.0.0.rc.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70257167535420
36
+ version_requirements: *70341058157100
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: daemons
39
- requirement: &70257167534760 !ruby/object:Gem::Requirement
39
+ requirement: &70341058156560 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.1'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70257167534760
47
+ version_requirements: *70341058156560
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: multi_json
50
- requirement: &70257167534140 !ruby/object:Gem::Requirement
50
+ requirement: &70341058155840 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '1.3'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70257167534140
58
+ version_requirements: *70341058155840
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: em-http-request
61
- requirement: &70257167533360 !ruby/object:Gem::Requirement
61
+ requirement: &70341058154820 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.0.2
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70257167533360
69
+ version_requirements: *70341058154820
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: guard-rspec
72
- requirement: &70257167532700 !ruby/object:Gem::Requirement
72
+ requirement: &70341058153760 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70257167532700
80
+ version_requirements: *70341058153760
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: json
83
- requirement: &70257167538780 !ruby/object:Gem::Requirement
83
+ requirement: &70341058152780 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70257167538780
91
+ version_requirements: *70341058152780
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: pry
94
- requirement: &70257167515140 !ruby/object:Gem::Requirement
94
+ requirement: &70341058152120 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70257167515140
102
+ version_requirements: *70341058152120
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
- requirement: &70257167514640 !ruby/object:Gem::Requirement
105
+ requirement: &70341058151700 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70257167514640
113
+ version_requirements: *70341058151700
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rdiscount
116
- requirement: &70257167514040 !ruby/object:Gem::Requirement
116
+ requirement: &70341058151240 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70257167514040
124
+ version_requirements: *70341058151240
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
- requirement: &70257167513580 !ruby/object:Gem::Requirement
127
+ requirement: &70341058150560 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70257167513580
135
+ version_requirements: *70341058150560
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: simplecov
138
- requirement: &70257167513160 !ruby/object:Gem::Requirement
138
+ requirement: &70341058133520 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70257167513160
146
+ version_requirements: *70341058133520
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: webmock
149
- requirement: &70257167512660 !ruby/object:Gem::Requirement
149
+ requirement: &70341058132360 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *70257167512660
157
+ version_requirements: *70341058132360
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: yajl-ruby
160
- requirement: &70257167512080 !ruby/object:Gem::Requirement
160
+ requirement: &70341058130880 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: '0'
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *70257167512080
168
+ version_requirements: *70341058130880
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: yard
171
- requirement: &70257167511540 !ruby/object:Gem::Requirement
171
+ requirement: &70341058129920 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ! '>='
@@ -176,7 +176,7 @@ dependencies:
176
176
  version: '0'
177
177
  type: :development
178
178
  prerelease: false
179
- version_requirements: *70257167511540
179
+ version_requirements: *70341058129920
180
180
  description: TweetStream allows you to easily consume the Twitter Streaming API utilizing
181
181
  the YAJL Ruby gem.
182
182
  email: