twitter-stream 0.1.7 → 0.1.8
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/VERSION +1 -1
- data/lib/twitter/json_stream.rb +43 -38
- data/twitter-stream.gemspec +4 -4
- metadata +15 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/lib/twitter/json_stream.rb
CHANGED
@@ -6,19 +6,19 @@ require 'roauth'
|
|
6
6
|
module Twitter
|
7
7
|
class JSONStream < EventMachine::Connection
|
8
8
|
MAX_LINE_LENGTH = 1024*1024
|
9
|
-
|
9
|
+
|
10
10
|
# network failure reconnections
|
11
|
-
NF_RECONNECT_START = 0.25
|
11
|
+
NF_RECONNECT_START = 0.25
|
12
12
|
NF_RECONNECT_ADD = 0.25
|
13
13
|
NF_RECONNECT_MAX = 16
|
14
|
-
|
14
|
+
|
15
15
|
# app failure reconnections
|
16
16
|
AF_RECONNECT_START = 10
|
17
17
|
AF_RECONNECT_MUL = 2
|
18
|
-
|
18
|
+
|
19
19
|
RECONNECT_MAX = 320
|
20
20
|
RETRIES_MAX = 10
|
21
|
-
|
21
|
+
|
22
22
|
DEFAULT_OPTIONS = {
|
23
23
|
:method => 'GET',
|
24
24
|
:path => '/',
|
@@ -42,7 +42,7 @@ module Twitter
|
|
42
42
|
attr_accessor :af_last_reconnect
|
43
43
|
attr_accessor :reconnect_retries
|
44
44
|
attr_accessor :proxy
|
45
|
-
|
45
|
+
|
46
46
|
def self.connect options = {}
|
47
47
|
options[:port] = 443 if options[:ssl] && !options.has_key?(:port)
|
48
48
|
options = DEFAULT_OPTIONS.merge(options)
|
@@ -74,15 +74,15 @@ module Twitter
|
|
74
74
|
def each_item &block
|
75
75
|
@each_item_callback = block
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def on_error &block
|
79
79
|
@error_callback = block
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def on_reconnect &block
|
83
83
|
@reconnect_callback = block
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def on_max_reconnects &block
|
87
87
|
@max_reconnects_callback = block
|
88
88
|
end
|
@@ -97,7 +97,7 @@ module Twitter
|
|
97
97
|
@gracefully_closed = false
|
98
98
|
close_connection
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def unbind
|
102
102
|
receive_line(@buffer.flush) unless @buffer.empty?
|
103
103
|
schedule_reconnect unless @gracefully_closed
|
@@ -114,26 +114,26 @@ module Twitter
|
|
114
114
|
return
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def connection_completed
|
119
119
|
send_request
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def post_init
|
123
123
|
reset_state
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
protected
|
127
127
|
def schedule_reconnect
|
128
128
|
timeout = reconnect_timeout
|
129
129
|
@reconnect_retries += 1
|
130
130
|
if timeout <= RECONNECT_MAX && @reconnect_retries <= RETRIES_MAX
|
131
|
-
reconnect_after(timeout)
|
131
|
+
reconnect_after(timeout)
|
132
132
|
else
|
133
133
|
@max_reconnects_callback.call(timeout, @reconnect_retries) if @max_reconnects_callback
|
134
134
|
end
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def reconnect_after timeout
|
138
138
|
@reconnect_callback.call(timeout, @reconnect_retries) if @reconnect_callback
|
139
139
|
|
@@ -145,13 +145,13 @@ module Twitter
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
def reconnect_timeout
|
150
150
|
if @immediate_reconnect
|
151
151
|
@immediate_reconnect = false
|
152
152
|
return 0
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
if (@code == 0) # network failure
|
156
156
|
if @nf_last_reconnect
|
157
157
|
@nf_last_reconnect += NF_RECONNECT_ADD
|
@@ -168,7 +168,7 @@ module Twitter
|
|
168
168
|
@af_last_reconnect
|
169
169
|
end
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
def reset_state
|
173
173
|
set_comm_inactivity_timeout @options[:timeout] if @options[:timeout] > 0
|
174
174
|
@code = 0
|
@@ -180,32 +180,33 @@ module Twitter
|
|
180
180
|
def send_request
|
181
181
|
data = []
|
182
182
|
request_uri = @options[:path]
|
183
|
-
|
183
|
+
|
184
184
|
if @proxy
|
185
185
|
# proxies need the request to be for the full url
|
186
186
|
request_uri = "http#{'s' if @options[:ssl]}://#{@options[:host]}:#{@options[:port]}#{request_uri}"
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
content = @options[:content]
|
190
|
-
|
190
|
+
|
191
191
|
if !@options[:filters].empty?
|
192
192
|
if @options[:method].to_s.upcase == 'GET'
|
193
|
-
request_uri << "?#{
|
193
|
+
request_uri << "?#{query}"
|
194
194
|
else
|
195
|
-
content =
|
195
|
+
content = query
|
196
196
|
end
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
data << "#{@options[:method]} #{request_uri} HTTP/1.1"
|
200
200
|
data << "Host: #{@options[:host]}"
|
201
|
+
data << 'Accept: */*'
|
201
202
|
data << "User-Agent: #{@options[:user_agent]}" if @options[:user_agent]
|
202
|
-
|
203
|
+
|
203
204
|
if @options[:auth]
|
204
205
|
data << "Authorization: Basic #{[@options[:auth]].pack('m').delete("\r\n")}"
|
205
206
|
elsif @options[:oauth]
|
206
207
|
data << "Authorization: #{oauth_header}"
|
207
208
|
end
|
208
|
-
|
209
|
+
|
209
210
|
if @proxy && @proxy.user
|
210
211
|
data << "Proxy-Authorization: Basic " + ["#{@proxy.user}:#{@proxy.password}"].pack('m').delete("\r\n")
|
211
212
|
end
|
@@ -214,7 +215,7 @@ module Twitter
|
|
214
215
|
data << "Content-length: #{content.length}"
|
215
216
|
end
|
216
217
|
data << "\r\n"
|
217
|
-
|
218
|
+
|
218
219
|
send_data data.join("\r\n") << content
|
219
220
|
end
|
220
221
|
|
@@ -262,12 +263,12 @@ module Twitter
|
|
262
263
|
close_connection
|
263
264
|
end
|
264
265
|
end
|
265
|
-
|
266
|
+
|
266
267
|
def reset_timeouts
|
267
268
|
@nf_last_reconnect = @af_last_reconnect = nil
|
268
269
|
@reconnect_retries = 0
|
269
270
|
end
|
270
|
-
|
271
|
+
|
271
272
|
# :filters => %w(miama lebron jesus)
|
272
273
|
# :oauth => {
|
273
274
|
# :consumer_key => [key],
|
@@ -277,17 +278,21 @@ module Twitter
|
|
277
278
|
# }
|
278
279
|
def oauth_header
|
279
280
|
uri = "http://#{@options[:host]}#{@options[:path]}"
|
280
|
-
|
281
|
-
params = {
|
282
|
-
'track' => @options[:filters].join(',')
|
283
|
-
}
|
284
|
-
|
285
281
|
::ROAuth.header(@options[:oauth], uri, params, @options[:method])
|
286
282
|
end
|
287
|
-
|
288
|
-
|
289
|
-
|
283
|
+
|
284
|
+
# Normalized query hash of escaped string keys and escaped string values
|
285
|
+
# nil values are skipped
|
286
|
+
def params
|
287
|
+
{ 'track' => escape(@options[:filters].join(",")) }
|
290
288
|
end
|
291
289
|
|
292
|
-
|
290
|
+
def query
|
291
|
+
params.map{|pair| pair.join("=")}.sort.join("&")
|
292
|
+
end
|
293
|
+
|
294
|
+
def escape str
|
295
|
+
URI.escape(str.to_s, /[^a-zA-Z0-9\-\.\_\~]/)
|
296
|
+
end
|
297
|
+
end
|
293
298
|
end
|
data/twitter-stream.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{twitter-stream}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Vladimir Kolesnikov"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-13}
|
13
13
|
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
14
|
s.email = %q{voloko@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.homepage = %q{http://github.com/voloko/twitter-stream}
|
31
31
|
s.rdoc_options = ["--charset=UTF-8"]
|
32
32
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.3.
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
34
|
s.summary = %q{Twitter realtime API client}
|
35
35
|
s.test_files = [
|
36
36
|
"spec/spec_helper.rb",
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
|
-
if Gem::Version.new(Gem::
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
46
|
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.8"])
|
47
47
|
s.add_runtime_dependency(%q<roauth>, [">= 0.0.2"])
|
48
48
|
s.add_development_dependency(%q<rspec>, [">= 1.2.8"])
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Vladimir Kolesnikov
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-13 00:00:00 +04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: eventmachine
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 63
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 12
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: roauth
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
- 0
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: rspec
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
55
62
|
segments:
|
56
63
|
- 1
|
57
64
|
- 2
|
@@ -88,23 +95,27 @@ rdoc_options:
|
|
88
95
|
require_paths:
|
89
96
|
- lib
|
90
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
91
99
|
requirements:
|
92
100
|
- - ">="
|
93
101
|
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
94
103
|
segments:
|
95
104
|
- 0
|
96
105
|
version: "0"
|
97
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
98
108
|
requirements:
|
99
109
|
- - ">="
|
100
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
101
112
|
segments:
|
102
113
|
- 0
|
103
114
|
version: "0"
|
104
115
|
requirements: []
|
105
116
|
|
106
117
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.3.
|
118
|
+
rubygems_version: 1.3.7
|
108
119
|
signing_key:
|
109
120
|
specification_version: 3
|
110
121
|
summary: Twitter realtime API client
|