em-twitter 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/em-twitter.gemspec +2 -2
- data/lib/em-twitter/connection.rb +12 -11
- data/lib/em-twitter/version.rb +1 -1
- data/spec/em-twitter/client_spec.rb +8 -8
- data/spec/em-twitter/connection_reconnect_spec.rb +4 -4
- data/spec/em-twitter/connection_spec.rb +11 -11
- data/spec/em-twitter/request_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- metadata +19 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2faa76054df9c4e28303d85150d33ed50b315aa5
|
4
|
+
data.tar.gz: 6595037bb4b9d0c4d5d782ba6023bcf4fc3e60d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01a1887b81e5855f5f79ea161772ff30ab924c78703e996fd7cbbbfd5727f0b929e8e98faa2ad482a4bc2d4dbd6ef4edc0dff4f8f2831cea9eb55267abc37da7
|
7
|
+
data.tar.gz: 2b483b9d83d4acf3b451ee028130ead5cdb36202e74c842c0612d0688a126ec6d6979de0580bf89ad75fd405e73ba6ccdfd2a04bf03bd65686a417b2cb781307
|
data/em-twitter.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.summary = spec.description
|
16
16
|
|
17
17
|
spec.add_dependency 'eventmachine', '~> 1.0'
|
18
|
-
spec.add_dependency 'http_parser.rb', '
|
19
|
-
spec.add_dependency 'simple_oauth', '~> 0.
|
18
|
+
spec.add_dependency 'http_parser.rb', ['>= 0.6.0.beta.2', '< 0.7']
|
19
|
+
spec.add_dependency 'simple_oauth', '~> 0.2'
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
22
22
|
|
@@ -137,7 +137,7 @@ module EventMachine
|
|
137
137
|
protected
|
138
138
|
|
139
139
|
def handle_stream(data)
|
140
|
-
@last_response << @decoder.decode(data)
|
140
|
+
@last_response << (@decoder ||= BaseDecoder.new).decode(data)
|
141
141
|
|
142
142
|
if @last_response.complete?
|
143
143
|
invoke_callback(@client.each_item_callback, @last_response.body)
|
@@ -149,8 +149,7 @@ module EventMachine
|
|
149
149
|
@response_code = @parser.status_code
|
150
150
|
@headers = headers
|
151
151
|
|
152
|
-
@decoder = BaseDecoder.new
|
153
|
-
|
152
|
+
# @decoder = BaseDecoder.new
|
154
153
|
# TODO: Complete gzip support
|
155
154
|
# detect gzip encoding and use a decoder for response bodies
|
156
155
|
# gzip needs to be detected with the Content-Encoding header
|
@@ -299,14 +298,16 @@ module EventMachine
|
|
299
298
|
# Resets the internals of the connection on initial connection and
|
300
299
|
# on reconnections. Clears the response buffer and resets internal state
|
301
300
|
def reset_connection
|
302
|
-
@buffer
|
303
|
-
@parser
|
304
|
-
@
|
305
|
-
@
|
306
|
-
|
307
|
-
@
|
308
|
-
|
309
|
-
@
|
301
|
+
@buffer = BufferedTokenizer.new("\r", MAX_LINE_LENGTH)
|
302
|
+
@parser = Http::Parser.new(self)
|
303
|
+
@parser.on_body = method(:on_body)
|
304
|
+
@parser.on_headers_complete = method(:on_headers_complete)
|
305
|
+
@last_response = Response.new
|
306
|
+
@response_code = 0
|
307
|
+
|
308
|
+
@gracefully_closed = false
|
309
|
+
@immediate_reconnect = false
|
310
|
+
@auto_reconnect = @options[:auto_reconnect]
|
310
311
|
end
|
311
312
|
|
312
313
|
end
|
data/lib/em-twitter/version.rb
CHANGED
@@ -13,13 +13,13 @@ describe EM::Twitter::Client do
|
|
13
13
|
|
14
14
|
describe ".connect" do
|
15
15
|
before do
|
16
|
-
conn =
|
17
|
-
conn.
|
18
|
-
EM.
|
16
|
+
conn = double('EventMachine::Connection')
|
17
|
+
allow(conn).to receive(:start_tls).and_return(nil)
|
18
|
+
allow(EM).to receive(:connect).and_return(conn)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "connects to the configured host/port" do
|
22
|
-
EventMachine.
|
22
|
+
expect(EventMachine).to receive(:connect).with(
|
23
23
|
test_options[:host],
|
24
24
|
test_options[:port],
|
25
25
|
EventMachine::Twitter::Connection,
|
@@ -31,7 +31,7 @@ describe EM::Twitter::Client do
|
|
31
31
|
|
32
32
|
context "when using a proxy" do
|
33
33
|
it "connects to the proxy server" do
|
34
|
-
EventMachine.
|
34
|
+
expect(EventMachine).to receive(:connect).with(
|
35
35
|
"my-proxy",
|
36
36
|
8080,
|
37
37
|
EventMachine::Twitter::Connection,
|
@@ -43,9 +43,9 @@ describe EM::Twitter::Client do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "doesn't trigger SSL until connection is established" do
|
46
|
-
connection =
|
47
|
-
EM.
|
48
|
-
EM.
|
46
|
+
connection = double('EventMachine::Connection')
|
47
|
+
expect(EM).to receive(:connect).and_return(connection)
|
48
|
+
expect(EM).not_to receive(:start_tls)
|
49
49
|
client = EM::Twitter::Client.connect(:ssl => { :key => "/path/to/key.pem", :cert => "/path/to/cert.pem" })
|
50
50
|
end
|
51
51
|
end
|
@@ -32,7 +32,7 @@ describe "EM::Twitter::Connection reconnections" do
|
|
32
32
|
after { Mockingbird.teardown }
|
33
33
|
|
34
34
|
it "resets the network failure reconnector" do
|
35
|
-
Reconnectors::NetworkFailure.
|
35
|
+
expect_any_instance_of(Reconnectors::NetworkFailure).to receive(:reset)
|
36
36
|
EM.run do
|
37
37
|
EM::Timer.new(1) { EM.stop }
|
38
38
|
client = Client.connect(default_options)
|
@@ -40,7 +40,7 @@ describe "EM::Twitter::Connection reconnections" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "resets the application failure reconnector" do
|
43
|
-
Reconnectors::ApplicationFailure.
|
43
|
+
expect_any_instance_of(Reconnectors::ApplicationFailure).to receive(:reset)
|
44
44
|
EM.run do
|
45
45
|
EM::Timer.new(1) { EM.stop }
|
46
46
|
client = Client.connect(default_options)
|
@@ -120,7 +120,7 @@ describe "EM::Twitter::Connection reconnections" do
|
|
120
120
|
it "does not reconnect when auto_reconnect is false" do
|
121
121
|
EM.run do
|
122
122
|
client = Client.connect(default_options.merge(:auto_reconnect => false))
|
123
|
-
client.
|
123
|
+
expect(client).not_to receive(:reconnect)
|
124
124
|
client.on_close { EM.stop }
|
125
125
|
end
|
126
126
|
end
|
@@ -152,7 +152,7 @@ describe "EM::Twitter::Connection reconnections" do
|
|
152
152
|
it "reconnects the current connection" do
|
153
153
|
EM.run_block do
|
154
154
|
client = Client.connect(default_options)
|
155
|
-
client.connection.
|
155
|
+
expect(client.connection).to receive(:reconnect).once
|
156
156
|
client.reconnect
|
157
157
|
end
|
158
158
|
end
|
@@ -14,7 +14,7 @@ describe EM::Twitter::Connection do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "sets the inactivity timeout" do
|
17
|
-
EM.
|
17
|
+
expect(EM).to receive(:set_comm_inactivity_timeout)
|
18
18
|
EM.run_block do
|
19
19
|
client = EM::Twitter::Client.connect(default_options.merge(:timeout => 2))
|
20
20
|
end
|
@@ -109,7 +109,7 @@ describe EM::Twitter::Connection do
|
|
109
109
|
called = false
|
110
110
|
EM.run do
|
111
111
|
client = EM::Twitter::Client.connect(default_options)
|
112
|
-
client.connection.
|
112
|
+
allow(client.connection).to receive(:stalled?).and_return(true)
|
113
113
|
client.on_no_data_received do
|
114
114
|
called = true
|
115
115
|
EM.stop
|
@@ -123,8 +123,8 @@ describe EM::Twitter::Connection do
|
|
123
123
|
called = false
|
124
124
|
EM.run do
|
125
125
|
client = EM::Twitter::Client.connect(default_options)
|
126
|
-
client.connection.
|
127
|
-
client.connection.
|
126
|
+
expect(client.connection).to receive(:close_connection).once
|
127
|
+
allow(client.connection).to receive(:stalled?).and_return(true)
|
128
128
|
client.on_no_data_received do
|
129
129
|
called = true
|
130
130
|
EM.stop
|
@@ -141,7 +141,7 @@ describe EM::Twitter::Connection do
|
|
141
141
|
# this is kind of sneaky, using a stub on gracefully_closed?
|
142
142
|
# to set a nil response the first time around to mimic a null
|
143
143
|
# response object
|
144
|
-
client.connection.
|
144
|
+
allow(client.connection).to receive(:gracefully_closed?) do
|
145
145
|
resp = client.connection.instance_variable_get(:@last_response)
|
146
146
|
client.connection.instance_variable_set(:@last_response, nil) if resp.timestamp.nil?
|
147
147
|
false
|
@@ -174,7 +174,7 @@ describe EM::Twitter::Connection do
|
|
174
174
|
it "closes the connection" do
|
175
175
|
EM.run_block do
|
176
176
|
client = EM::Twitter::Client.connect(default_options)
|
177
|
-
client.connection.
|
177
|
+
expect(client.connection).to receive(:close_connection).once
|
178
178
|
client.stop
|
179
179
|
end
|
180
180
|
end
|
@@ -210,7 +210,7 @@ describe EM::Twitter::Connection do
|
|
210
210
|
it "updates the options hash" do
|
211
211
|
EM.run_block do
|
212
212
|
client = EM::Twitter::Client.connect(default_options)
|
213
|
-
client.connection.update(:params => {
|
213
|
+
client.connection.update(:params => {:track => 'rangers'})
|
214
214
|
expect(client.connection.options[:params]).to eq({:track => 'rangers'})
|
215
215
|
end
|
216
216
|
end
|
@@ -218,18 +218,18 @@ describe EM::Twitter::Connection do
|
|
218
218
|
it "reconnects after updating" do
|
219
219
|
EM.run_block do
|
220
220
|
client = EM::Twitter::Client.connect(default_options)
|
221
|
-
client.connection.
|
222
|
-
client.connection.update(:params => {
|
221
|
+
expect(client.connection).to receive(:immediate_reconnect).once
|
222
|
+
client.connection.update(:params => {:track => 'rangers'})
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
226
|
it "uses the new options when reconnecting" do
|
227
227
|
EM.run_block do
|
228
228
|
client = EM::Twitter::Client.connect(default_options)
|
229
|
-
client.connection.
|
229
|
+
expect(client.connection).to receive(:send_data) do |request|
|
230
230
|
expect(request.to_s).to include('track=rangers')
|
231
231
|
end
|
232
|
-
client.connection.update(:params => {
|
232
|
+
client.connection.update(:params => {:track => 'rangers'})
|
233
233
|
end
|
234
234
|
end
|
235
235
|
end
|
@@ -17,7 +17,7 @@ describe EM::Twitter::Request do
|
|
17
17
|
it 'passes params on POST requests' do
|
18
18
|
options = default_options.merge(:method => 'POST', :host => 'stream.twitter.com', :port => 443)
|
19
19
|
req = EM::Twitter::Request.new(options)
|
20
|
-
SimpleOAuth::Header.
|
20
|
+
expect(SimpleOAuth::Header).to receive(:new).
|
21
21
|
with('POST', "http://stream.twitter.com/1/statuses/filter.json", {"track"=>"nfl"}, kind_of(Hash))
|
22
22
|
|
23
23
|
req.send(:oauth_header)
|
@@ -26,7 +26,7 @@ describe EM::Twitter::Request do
|
|
26
26
|
it 'passes params on the querystring for GET requests' do
|
27
27
|
options = default_options.merge(:method => 'GET', :host => 'stream.twitter.com', :port => 443)
|
28
28
|
req = EM::Twitter::Request.new(options)
|
29
|
-
SimpleOAuth::Header.
|
29
|
+
expect(SimpleOAuth::Header).to receive(:new).
|
30
30
|
with('GET', "http://stream.twitter.com/1/statuses/filter.json?track=nfl", {}, kind_of(Hash))
|
31
31
|
|
32
32
|
req.send(:oauth_header)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steve Agalloco
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: eventmachine
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,39 +27,40 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: http_parser.rb
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.0.beta.2
|
34
|
+
- - <
|
36
35
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0.
|
36
|
+
version: '0.7'
|
38
37
|
type: :runtime
|
39
38
|
prerelease: false
|
40
39
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
40
|
requirements:
|
43
|
-
- -
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.0.beta.2
|
44
|
+
- - <
|
44
45
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0.
|
46
|
+
version: '0.7'
|
46
47
|
- !ruby/object:Gem::Dependency
|
47
48
|
name: simple_oauth
|
48
49
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
53
|
+
version: '0.2'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
58
|
- - ~>
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
60
|
+
version: '0.2'
|
62
61
|
- !ruby/object:Gem::Dependency
|
63
62
|
name: bundler
|
64
63
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
64
|
requirements:
|
67
65
|
- - ~>
|
68
66
|
- !ruby/object:Gem::Version
|
@@ -70,7 +68,6 @@ dependencies:
|
|
70
68
|
type: :development
|
71
69
|
prerelease: false
|
72
70
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
71
|
requirements:
|
75
72
|
- - ~>
|
76
73
|
- !ruby/object:Gem::Version
|
@@ -116,33 +113,26 @@ files:
|
|
116
113
|
homepage: https://github.com/spagalloco/em-twitter
|
117
114
|
licenses:
|
118
115
|
- MIT
|
116
|
+
metadata: {}
|
119
117
|
post_install_message:
|
120
118
|
rdoc_options: []
|
121
119
|
require_paths:
|
122
120
|
- lib
|
123
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
122
|
requirements:
|
126
|
-
- -
|
123
|
+
- - '>='
|
127
124
|
- !ruby/object:Gem::Version
|
128
125
|
version: '0'
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
hash: -324934599838712109
|
132
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
127
|
requirements:
|
135
|
-
- -
|
128
|
+
- - '>='
|
136
129
|
- !ruby/object:Gem::Version
|
137
130
|
version: '0'
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
hash: -324934599838712109
|
141
131
|
requirements: []
|
142
132
|
rubyforge_project:
|
143
|
-
rubygems_version:
|
133
|
+
rubygems_version: 2.0.3
|
144
134
|
signing_key:
|
145
|
-
specification_version:
|
135
|
+
specification_version: 4
|
146
136
|
summary: Twitter Streaming API client for EventMachine
|
147
137
|
test_files: []
|
148
138
|
has_rdoc:
|