twitter-stream 0.1.15 → 0.1.16

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

Potentially problematic release.


This version of twitter-stream might be problematic. Click here for more details.

@@ -32,6 +32,11 @@ JSON format only.
32
32
  stream.on_max_reconnects do |timeout, retries|
33
33
  # Something is wrong on your side. Send yourself an email.
34
34
  end
35
+
36
+ stream.on_no_data do
37
+ # Twitter has stopped sending any data on the currently active
38
+ # connection, reconnecting is probably in order
39
+ end
35
40
  }
36
41
 
37
42
 
@@ -20,6 +20,8 @@ module Twitter
20
20
  RECONNECT_MAX = 320
21
21
  RETRIES_MAX = 10
22
22
 
23
+ NO_DATA_TIMEOUT = 90
24
+
23
25
  DEFAULT_OPTIONS = {
24
26
  :method => 'GET',
25
27
  :path => '/',
@@ -44,6 +46,7 @@ module Twitter
44
46
  attr_accessor :nf_last_reconnect
45
47
  attr_accessor :af_last_reconnect
46
48
  attr_accessor :reconnect_retries
49
+ attr_accessor :last_data_received_at
47
50
  attr_accessor :proxy
48
51
 
49
52
  def self.connect options = {}
@@ -72,6 +75,7 @@ module Twitter
72
75
  @immediate_reconnect = false
73
76
  @on_inited_callback = options.delete(:on_inited)
74
77
  @proxy = URI.parse(options[:proxy]) if options[:proxy]
78
+ @last_data_received_at = nil
75
79
  end
76
80
 
77
81
  def each_item &block
@@ -86,6 +90,12 @@ module Twitter
86
90
  @reconnect_callback = block
87
91
  end
88
92
 
93
+ # Called when no data has been received for NO_DATA_TIMEOUT seconds.
94
+ # Reconnecting is probably in order as per the Twitter recommendations
95
+ def on_no_data &block
96
+ @no_data_callback = block
97
+ end
98
+
89
99
  def on_max_reconnects &block
90
100
  @max_reconnects_callback = block
91
101
  end
@@ -111,12 +121,13 @@ module Twitter
111
121
  end
112
122
  schedule_reconnect if @options[:auto_reconnect] && !@gracefully_closed
113
123
  @close_callback.call if @close_callback
114
-
124
+ @state = :init
115
125
  end
116
126
 
117
127
  # Receives raw data from the HTTP connection and pushes it into the
118
128
  # HTTP parser which then drives subsequent callbacks.
119
129
  def receive_data(data)
130
+ @last_data_received_at = Time.now
120
131
  @parser << data
121
132
  end
122
133
 
@@ -128,9 +139,20 @@ module Twitter
128
139
  def post_init
129
140
  reset_state
130
141
  @on_inited_callback.call if @on_inited_callback
142
+ @reconnect_timer = EventMachine.add_periodic_timer(5) do
143
+ if @gracefully_closed
144
+ @reconnect_timer.cancel
145
+ elsif @last_data_received_at && Time.now - @last_data_received_at > NO_DATA_TIMEOUT
146
+ no_data
147
+ end
148
+ end
131
149
  end
132
150
 
133
151
  protected
152
+ def no_data
153
+ @no_data_callback.call if @no_data_callback
154
+ end
155
+
134
156
  def schedule_reconnect
135
157
  timeout = reconnect_timeout
136
158
  @reconnect_retries += 1
@@ -208,7 +230,7 @@ module Twitter
208
230
  parse_stream_line(line)
209
231
  end
210
232
  @stream = ''
211
- rescue Exception => e
233
+ rescue => e
212
234
  receive_error("#{e.class}: " + [e.message, e.backtrace].flatten.join("\n\t"))
213
235
  close_connection
214
236
  return
@@ -134,6 +134,23 @@ describe JSONStream do
134
134
  end
135
135
  end
136
136
 
137
+ it "should swallow StandardError exceptions when delivering items" do
138
+ expect do
139
+ connect_stream :ssl => false do
140
+ stream.each_item { |item| raise StandardError, 'error message' }
141
+ end
142
+ end.to_not raise_error
143
+ end
144
+
145
+
146
+ it "propagates out runtime errors when delivering items" do
147
+ expect do
148
+ connect_stream :ssl => false do
149
+ stream.each_item { |item| raise Exception, 'error message' }
150
+ end
151
+ end.to raise_error(Exception, 'error message')
152
+ end
153
+
137
154
  it "should send correct user agent" do
138
155
  connect_stream
139
156
  end
@@ -213,6 +230,22 @@ describe JSONStream do
213
230
  it_should_behave_like "network failure"
214
231
  end
215
232
 
233
+ context "on no data received" do
234
+ attr_reader :stream
235
+ before :each do
236
+ $data_to_send = ''
237
+ $close_connection = false
238
+ end
239
+
240
+ it "should call no data callback after no data received for 90 seconds" do
241
+ connect_stream :stop_in => 6 do
242
+ stream.last_data_received_at = Time.now - 88
243
+ stream.should_receive(:no_data).once
244
+ end
245
+ end
246
+
247
+ end
248
+
216
249
  context "on server unavailable" do
217
250
 
218
251
  attr_reader :stream
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{twitter-stream}
5
- s.version = "0.1.15"
5
+ s.version = "0.1.16"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Vladimir Kolesnikov"]
metadata CHANGED
@@ -1,74 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: twitter-stream
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.15
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 16
9
+ version: 0.1.16
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Vladimir Kolesnikov
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-04-10 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-04-10 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: eventmachine
16
- requirement: &70312242841020 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 12
30
+ - 8
21
31
  version: 0.12.8
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70312242841020
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: simple_oauth
27
- requirement: &70312242839900 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
30
39
  - - ~>
31
- - !ruby/object:Gem::Version
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 1
44
+ - 4
32
45
  version: 0.1.4
33
46
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70312242839900
36
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
37
49
  name: http_parser.rb
38
- requirement: &70312242838600 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
41
53
  - - ~>
42
- - !ruby/object:Gem::Version
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 5
58
+ - 1
43
59
  version: 0.5.1
44
60
  type: :runtime
45
- prerelease: false
46
- version_requirements: *70312242838600
47
- - !ruby/object:Gem::Dependency
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &70312242837520 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
52
67
  - - ~>
53
- - !ruby/object:Gem::Version
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 5
72
+ - 0
54
73
  version: 2.5.0
55
74
  type: :development
56
- prerelease: false
57
- version_requirements: *70312242837520
58
- description: Simple Ruby client library for twitter streaming API. Uses EventMachine
59
- for connection handling. Adheres to twitter's reconnection guidline. JSON format
60
- only.
75
+ version_requirements: *id004
76
+ description: Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only.
61
77
  email: voloko@gmail.com
62
78
  executables: []
79
+
63
80
  extensions: []
64
- extra_rdoc_files:
81
+
82
+ extra_rdoc_files:
65
83
  - README.markdown
66
84
  - LICENSE
67
- files:
85
+ files:
68
86
  - .gemtest
69
87
  - .gitignore
70
88
  - .rspec
71
89
  - Gemfile
90
+ - LICENSE
72
91
  - README.markdown
73
92
  - Rakefile
74
93
  - VERSION
@@ -78,32 +97,38 @@ files:
78
97
  - spec/spec_helper.rb
79
98
  - spec/twitter/json_stream_spec.rb
80
99
  - twitter-stream.gemspec
81
- - LICENSE
100
+ has_rdoc: true
82
101
  homepage: http://github.com/voloko/twitter-stream
83
102
  licenses: []
103
+
84
104
  post_install_message:
85
- rdoc_options:
105
+ rdoc_options:
86
106
  - --charset=UTF-8
87
- require_paths:
107
+ require_paths:
88
108
  - lib
89
- required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ! '>='
99
- - !ruby/object:Gem::Version
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 1
122
+ - 3
123
+ - 6
100
124
  version: 1.3.6
101
125
  requirements: []
126
+
102
127
  rubyforge_project:
103
- rubygems_version: 1.8.15
128
+ rubygems_version: 1.3.6
104
129
  signing_key:
105
130
  specification_version: 3
106
131
  summary: Twitter realtime API client
107
- test_files:
132
+ test_files:
108
133
  - spec/spec_helper.rb
109
134
  - spec/twitter/json_stream_spec.rb