twitter-stream 0.1.12 → 0.1.13
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.
Potentially problematic release.
This version of twitter-stream might be problematic. Click here for more details.
- data/.gemtest +0 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/Rakefile +5 -21
- data/lib/twitter/json_stream.rb +14 -3
- data/spec/twitter/json_stream_spec.rb +52 -33
- data/twitter-stream.gemspec +16 -45
- metadata +28 -25
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,28 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
3
6
|
gem 'rspec', '>= 2.5.0'
|
4
7
|
require 'rspec/core/rake_task'
|
5
8
|
|
6
9
|
desc "Run all specs"
|
7
|
-
RSpec::Core::RakeTask.new(:spec)
|
8
|
-
# t.spec_files = FileList['spec/**/*.rb']
|
9
|
-
t.rspec_opts = %w(-fs --color)
|
10
|
-
end
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
11
|
task :default => :spec
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gemspec|
|
16
|
-
gemspec.name = "twitter-stream"
|
17
|
-
gemspec.summary = "Twitter realtime API client"
|
18
|
-
gemspec.description = "Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only."
|
19
|
-
gemspec.email = "voloko@gmail.com"
|
20
|
-
gemspec.homepage = "http://github.com/voloko/twitter-stream"
|
21
|
-
gemspec.authors = ["Vladimir Kolesnikov"]
|
22
|
-
gemspec.add_dependency("eventmachine", [">= 0.12.8"])
|
23
|
-
gemspec.add_dependency("roauth", [">= 0.0.2"])
|
24
|
-
gemspec.add_development_dependency("rspec", [">= 1.2.8"])
|
25
|
-
end
|
26
|
-
rescue LoadError
|
27
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
28
|
-
end
|
12
|
+
task :test => :spec
|
data/lib/twitter/json_stream.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'eventmachine'
|
2
2
|
require 'em/buftok'
|
3
3
|
require 'uri'
|
4
|
-
require '
|
4
|
+
require 'simple_oauth'
|
5
5
|
|
6
6
|
module Twitter
|
7
7
|
class JSONStream < EventMachine::Connection
|
@@ -284,8 +284,19 @@ module Twitter
|
|
284
284
|
# :access_secret => [access secret]
|
285
285
|
# }
|
286
286
|
def oauth_header
|
287
|
-
uri = uri_base + @options[:path]
|
288
|
-
|
287
|
+
uri = uri_base + @options[:path].to_s
|
288
|
+
|
289
|
+
# The hash SimpleOAuth accepts is slightly different from that of
|
290
|
+
# ROAuth. To preserve backward compatability, fix the cache here
|
291
|
+
# so that the arguments passed in don't need to change.
|
292
|
+
oauth = {
|
293
|
+
:consumer_key => @options[:oauth][:consumer_key],
|
294
|
+
:consumer_secret => @options[:oauth][:consumer_secret],
|
295
|
+
:token => @options[:oauth][:access_key],
|
296
|
+
:token_secret => @options[:oauth][:access_secret]
|
297
|
+
}
|
298
|
+
|
299
|
+
SimpleOAuth::Header.new(@options[:method], uri, params, oauth)
|
289
300
|
end
|
290
301
|
|
291
302
|
# Scheme (https if ssl, http otherwise) and host part of URL
|
@@ -21,15 +21,33 @@ end
|
|
21
21
|
|
22
22
|
|
23
23
|
describe JSONStream do
|
24
|
-
|
24
|
+
|
25
|
+
context "authentication" do
|
26
|
+
it "should connect with basic auth credentials" do
|
27
|
+
connect_stream :auth => "username:password"
|
28
|
+
$recieved_data.should include('Authorization: Basic')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should connect with oauth credentials" do
|
32
|
+
oauth = {
|
33
|
+
:consumer_key => '1234567890',
|
34
|
+
:consumer_secret => 'abcdefghijklmnopqrstuvwxyz',
|
35
|
+
:access_key => 'ohai',
|
36
|
+
:access_secret => 'ohno'
|
37
|
+
}
|
38
|
+
connect_stream :oauth => oauth
|
39
|
+
$recieved_data.should include('Authorization: OAuth')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
25
43
|
context "on create" do
|
26
|
-
|
44
|
+
|
27
45
|
it "should return stream" do
|
28
46
|
EM.should_receive(:connect).and_return('TEST INSTANCE')
|
29
47
|
stream = JSONStream.connect {}
|
30
48
|
stream.should == 'TEST INSTANCE'
|
31
49
|
end
|
32
|
-
|
50
|
+
|
33
51
|
it "should define default properties" do
|
34
52
|
EM.should_receive(:connect).with do |host, port, handler, opts|
|
35
53
|
host.should == 'stream.twitter.com'
|
@@ -39,7 +57,7 @@ describe JSONStream do
|
|
39
57
|
end
|
40
58
|
stream = JSONStream.connect {}
|
41
59
|
end
|
42
|
-
|
60
|
+
|
43
61
|
it "should connect to the proxy if provided" do
|
44
62
|
EM.should_receive(:connect).with do |host, port, handler, opts|
|
45
63
|
host.should == 'my-proxy'
|
@@ -50,8 +68,9 @@ describe JSONStream do
|
|
50
68
|
end
|
51
69
|
stream = JSONStream.connect(:proxy => "http://my-proxy:8080") {}
|
52
70
|
end
|
71
|
+
|
53
72
|
end
|
54
|
-
|
73
|
+
|
55
74
|
context "on valid stream" do
|
56
75
|
attr_reader :stream
|
57
76
|
before :each do
|
@@ -59,34 +78,34 @@ describe JSONStream do
|
|
59
78
|
$recieved_data = ''
|
60
79
|
$close_connection = false
|
61
80
|
end
|
62
|
-
|
81
|
+
|
63
82
|
it "should add no params" do
|
64
83
|
connect_stream
|
65
84
|
$recieved_data.should include('/1/statuses/filter.json HTTP')
|
66
85
|
end
|
67
|
-
|
86
|
+
|
68
87
|
it "should add custom params" do
|
69
88
|
connect_stream :params => {:name => 'test'}
|
70
89
|
$recieved_data.should include('?name=test')
|
71
90
|
end
|
72
|
-
|
91
|
+
|
73
92
|
it "should parse headers" do
|
74
93
|
connect_stream
|
75
94
|
stream.code.should == 200
|
76
95
|
stream.headers[0].downcase.should include('content-type')
|
77
96
|
end
|
78
|
-
|
97
|
+
|
79
98
|
it "should parse headers even after connection close" do
|
80
99
|
connect_stream
|
81
100
|
stream.code.should == 200
|
82
101
|
stream.headers[0].downcase.should include('content-type')
|
83
102
|
end
|
84
|
-
|
103
|
+
|
85
104
|
it "should extract records" do
|
86
105
|
connect_stream :user_agent => 'TEST_USER_AGENT'
|
87
106
|
$recieved_data.upcase.should include('USER-AGENT: TEST_USER_AGENT')
|
88
107
|
end
|
89
|
-
|
108
|
+
|
90
109
|
it "should send correct user agent" do
|
91
110
|
connect_stream
|
92
111
|
end
|
@@ -98,27 +117,27 @@ describe JSONStream do
|
|
98
117
|
stream.should_receive(:reconnect)
|
99
118
|
end
|
100
119
|
end
|
101
|
-
|
120
|
+
|
102
121
|
it "should reconnect with 0.25 at base" do
|
103
122
|
connect_stream do
|
104
123
|
stream.should_receive(:reconnect_after).with(0.25)
|
105
124
|
end
|
106
125
|
end
|
107
|
-
|
126
|
+
|
108
127
|
it "should reconnect with linear timeout" do
|
109
128
|
connect_stream do
|
110
129
|
stream.nf_last_reconnect = 1
|
111
130
|
stream.should_receive(:reconnect_after).with(1.25)
|
112
131
|
end
|
113
132
|
end
|
114
|
-
|
133
|
+
|
115
134
|
it "should stop reconnecting after 100 times" do
|
116
135
|
connect_stream do
|
117
136
|
stream.reconnect_retries = 100
|
118
137
|
stream.should_not_receive(:reconnect_after)
|
119
138
|
end
|
120
139
|
end
|
121
|
-
|
140
|
+
|
122
141
|
it "should notify after reconnect limit is reached" do
|
123
142
|
timeout, retries = nil, nil
|
124
143
|
connect_stream do
|
@@ -129,66 +148,66 @@ describe JSONStream do
|
|
129
148
|
end
|
130
149
|
timeout.should == 0.25
|
131
150
|
retries.should == 101
|
132
|
-
end
|
151
|
+
end
|
133
152
|
end
|
134
|
-
|
153
|
+
|
135
154
|
context "on network failure" do
|
136
155
|
attr_reader :stream
|
137
156
|
before :each do
|
138
157
|
$data_to_send = ''
|
139
158
|
$close_connection = true
|
140
159
|
end
|
141
|
-
|
160
|
+
|
142
161
|
it "should timeout on inactivity" do
|
143
162
|
connect_stream :stop_in => 1.5 do
|
144
|
-
stream.should_receive(:reconnect)
|
163
|
+
stream.should_receive(:reconnect)
|
145
164
|
end
|
146
|
-
end
|
147
|
-
|
165
|
+
end
|
166
|
+
|
148
167
|
it_should_behave_like "network failure"
|
149
168
|
end
|
150
|
-
|
169
|
+
|
151
170
|
context "on server unavailable" do
|
152
|
-
|
171
|
+
|
153
172
|
attr_reader :stream
|
154
|
-
|
155
|
-
# This is to make it so the network failure specs which call connect_stream
|
156
|
-
# can be reused. This way calls to connect_stream won't actually create a
|
173
|
+
|
174
|
+
# This is to make it so the network failure specs which call connect_stream
|
175
|
+
# can be reused. This way calls to connect_stream won't actually create a
|
157
176
|
# server to listen in.
|
158
177
|
def connect_stream_without_server(opts={},&block)
|
159
178
|
connect_stream_default(opts.merge(:start_server=>false),&block)
|
160
179
|
end
|
161
180
|
alias_method :connect_stream_default, :connect_stream
|
162
181
|
alias_method :connect_stream, :connect_stream_without_server
|
163
|
-
|
182
|
+
|
164
183
|
it_should_behave_like "network failure"
|
165
|
-
end
|
166
|
-
|
184
|
+
end
|
185
|
+
|
167
186
|
context "on application failure" do
|
168
187
|
attr_reader :stream
|
169
188
|
before :each do
|
170
189
|
$data_to_send = 'HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm="Firehose"\r\n\r\n1'
|
171
190
|
$close_connection = true
|
172
191
|
end
|
173
|
-
|
192
|
+
|
174
193
|
it "should reconnect on application failure 10 at base" do
|
175
194
|
connect_stream do
|
176
195
|
stream.should_receive(:reconnect_after).with(10)
|
177
196
|
end
|
178
197
|
end
|
179
|
-
|
198
|
+
|
180
199
|
it "should reconnect with exponential timeout" do
|
181
200
|
connect_stream do
|
182
201
|
stream.af_last_reconnect = 160
|
183
202
|
stream.should_receive(:reconnect_after).with(320)
|
184
203
|
end
|
185
204
|
end
|
186
|
-
|
205
|
+
|
187
206
|
it "should not try to reconnect after limit is reached" do
|
188
207
|
connect_stream do
|
189
208
|
stream.af_last_reconnect = 320
|
190
209
|
stream.should_not_receive(:reconnect_after)
|
191
210
|
end
|
192
211
|
end
|
193
|
-
end
|
212
|
+
end
|
194
213
|
end
|
data/twitter-stream.gemspec
CHANGED
@@ -1,60 +1,31 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
3
|
Gem::Specification.new do |s|
|
7
4
|
s.name = %q{twitter-stream}
|
8
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.13"
|
9
6
|
|
10
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
8
|
s.authors = ["Vladimir Kolesnikov"]
|
12
9
|
s.date = %q{2010-10-05}
|
13
10
|
s.description = %q{Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only.}
|
14
|
-
s.
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.markdown"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"README.markdown",
|
21
|
-
"Rakefile",
|
22
|
-
"VERSION",
|
23
|
-
"examples/reader.rb",
|
24
|
-
"fixtures/twitter/basic_http.txt",
|
25
|
-
"lib/twitter/json_stream.rb",
|
26
|
-
"spec/spec_helper.rb",
|
27
|
-
"spec/twitter/json_stream.rb",
|
28
|
-
"twitter-stream.gemspec"
|
29
|
-
]
|
11
|
+
s.summary = %q{Twitter realtime API client}
|
30
12
|
s.homepage = %q{http://github.com/voloko/twitter-stream}
|
13
|
+
s.email = %q{voloko@gmail.com}
|
14
|
+
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.rubygems_version = %q{1.3.6}
|
17
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
|
18
|
+
|
31
19
|
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
-
s.
|
33
|
-
s.rubygems_version = %q{1.3.7}
|
34
|
-
s.summary = %q{Twitter realtime API client}
|
35
|
-
s.test_files = [
|
36
|
-
"spec/spec_helper.rb",
|
37
|
-
"spec/twitter/json_stream.rb",
|
38
|
-
"examples/reader.rb"
|
39
|
-
]
|
20
|
+
s.extra_rdoc_files = ["README.markdown"]
|
40
21
|
|
41
|
-
|
42
|
-
|
43
|
-
|
22
|
+
s.add_runtime_dependency('eventmachine', "~> 0.12.8")
|
23
|
+
s.add_runtime_dependency('simple_oauth', '~> 0.1.4')
|
24
|
+
s.add_development_dependency('rspec', "~> 2.5.0")
|
44
25
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<eventmachine>, [">= 0.12.8"])
|
51
|
-
s.add_dependency(%q<roauth>, [">= 0.0.2"])
|
52
|
-
s.add_dependency(%q<rspec>, [">= 1.2.8"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<eventmachine>, [">= 0.12.8"])
|
56
|
-
s.add_dependency(%q<roauth>, [">= 0.0.2"])
|
57
|
-
s.add_dependency(%q<rspec>, [">= 1.2.8"])
|
58
|
-
end
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
29
|
+
s.require_paths = ["lib"]
|
59
30
|
end
|
60
31
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 13
|
10
|
+
version: 0.1.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vladimir Kolesnikov
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2010-10-05 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: eventmachine
|
@@ -24,7 +23,7 @@ dependencies:
|
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
|
-
- -
|
26
|
+
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
hash: 63
|
30
29
|
segments:
|
@@ -35,19 +34,19 @@ dependencies:
|
|
35
34
|
type: :runtime
|
36
35
|
version_requirements: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
37
|
+
name: simple_oauth
|
39
38
|
prerelease: false
|
40
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
41
|
requirements:
|
43
|
-
- -
|
42
|
+
- - ~>
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
44
|
+
hash: 19
|
46
45
|
segments:
|
47
46
|
- 0
|
48
|
-
-
|
49
|
-
-
|
50
|
-
version: 0.
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
version: 0.1.4
|
51
50
|
type: :runtime
|
52
51
|
version_requirements: *id002
|
53
52
|
- !ruby/object:Gem::Dependency
|
@@ -56,14 +55,14 @@ dependencies:
|
|
56
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
56
|
none: false
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - ~>
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
60
|
+
hash: 27
|
62
61
|
segments:
|
63
|
-
- 1
|
64
62
|
- 2
|
65
|
-
-
|
66
|
-
|
63
|
+
- 5
|
64
|
+
- 0
|
65
|
+
version: 2.5.0
|
67
66
|
type: :development
|
68
67
|
version_requirements: *id003
|
69
68
|
description: Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only.
|
@@ -75,6 +74,10 @@ extensions: []
|
|
75
74
|
extra_rdoc_files:
|
76
75
|
- README.markdown
|
77
76
|
files:
|
77
|
+
- .gemtest
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
78
81
|
- README.markdown
|
79
82
|
- Rakefile
|
80
83
|
- VERSION
|
@@ -84,13 +87,12 @@ files:
|
|
84
87
|
- spec/spec_helper.rb
|
85
88
|
- spec/twitter/json_stream_spec.rb
|
86
89
|
- twitter-stream.gemspec
|
87
|
-
has_rdoc: true
|
88
90
|
homepage: http://github.com/voloko/twitter-stream
|
89
91
|
licenses: []
|
90
92
|
|
91
93
|
post_install_message:
|
92
|
-
rdoc_options:
|
93
|
-
|
94
|
+
rdoc_options:
|
95
|
+
- --charset=UTF-8
|
94
96
|
require_paths:
|
95
97
|
- lib
|
96
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -107,18 +109,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
requirements:
|
108
110
|
- - ">="
|
109
111
|
- !ruby/object:Gem::Version
|
110
|
-
hash:
|
112
|
+
hash: 23
|
111
113
|
segments:
|
112
|
-
-
|
113
|
-
|
114
|
+
- 1
|
115
|
+
- 3
|
116
|
+
- 6
|
117
|
+
version: 1.3.6
|
114
118
|
requirements: []
|
115
119
|
|
116
120
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 1.7.2
|
118
122
|
signing_key:
|
119
123
|
specification_version: 3
|
120
124
|
summary: Twitter realtime API client
|
121
125
|
test_files:
|
122
|
-
- examples/reader.rb
|
123
126
|
- spec/spec_helper.rb
|
124
127
|
- spec/twitter/json_stream_spec.rb
|