benburkert-hosebird 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/hosebird.gemspec +3 -3
- data/lib/hosebird/autoload/twitter.rb +1 -0
- data/lib/hosebird/stream.rb +35 -13
- metadata +3 -3
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.email = "ben@benburkert.com"
|
10
10
|
gem.homepage = "http://github.com/benburkert/hosebird"
|
11
11
|
gem.authors = ["Ben Burkert"]
|
12
|
-
gem.requirements = %w[aikidoka eventmachine extlib json twitter]
|
12
|
+
gem.requirements = %w[flyingmachine-aikidoka eventmachine extlib json twitter]
|
13
13
|
end
|
14
14
|
|
15
15
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/hosebird.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{hosebird}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Burkert"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-19}
|
10
10
|
s.email = %q{ben@benburkert.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.homepage = %q{http://github.com/benburkert/hosebird}
|
38
38
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
39
|
s.require_paths = ["lib"]
|
40
|
-
s.requirements = ["aikidoka", "eventmachine", "extlib", "json", "twitter"]
|
40
|
+
s.requirements = ["flyingmachine-aikidoka", "eventmachine", "extlib", "json", "twitter"]
|
41
41
|
s.rubygems_version = %q{1.3.3}
|
42
42
|
s.summary = %q{A libary for Twitter's new Streaming API codename Hosebird.}
|
43
43
|
s.test_files = [
|
data/lib/hosebird/stream.rb
CHANGED
@@ -4,12 +4,20 @@ module Hosebird
|
|
4
4
|
|
5
5
|
HOST = 'stream.twitter.com'
|
6
6
|
PORT = 80
|
7
|
-
KEEP_ALIVE = /\
|
7
|
+
KEEP_ALIVE = /\A3[\r][\n][\n][\r][\n]/
|
8
|
+
DECHUNKER = /\A[0-F]+[\r][\n]/
|
8
9
|
NEWLINE = /[\n]/
|
9
10
|
CRLF = /[\r][\n]/
|
10
11
|
EOF = /[\r][\n]\Z/
|
11
|
-
|
12
|
-
|
12
|
+
|
13
|
+
# %r{\AHTTP/1.1[\s]200[\s]OK[\r][\n](?:[a-zA-Z0-9/\\\:(.\-) ]+[\r][\n])+[\r][\n]}
|
14
|
+
RESPONSE_HEADER = <<-HTTP.gsub(NEWLINE, "\r\n")
|
15
|
+
HTTP/1.1 200 OK
|
16
|
+
Content-Type: application/json
|
17
|
+
Transfer-Encoding: chunked
|
18
|
+
Server: Jetty(6.1.14)
|
19
|
+
|
20
|
+
HTTP
|
13
21
|
|
14
22
|
class_inheritable_accessor :url
|
15
23
|
|
@@ -55,7 +63,12 @@ module Hosebird
|
|
55
63
|
end
|
56
64
|
|
57
65
|
def extract_json(lines)
|
58
|
-
lines.map {|line|
|
66
|
+
# lines.map {|line| Yajl::Stream.parse(StringIO.new(line)).to_mash rescue nil }.compact
|
67
|
+
lines.map {|line| JSON.parse(line).to_mash rescue nil }.compact
|
68
|
+
end
|
69
|
+
|
70
|
+
def keep_alive?(data)
|
71
|
+
data =~ KEEP_ALIVE
|
59
72
|
end
|
60
73
|
|
61
74
|
def post_init
|
@@ -64,17 +77,21 @@ module Hosebird
|
|
64
77
|
end
|
65
78
|
|
66
79
|
def receive_data(data)
|
67
|
-
|
80
|
+
data.gsub!(RESPONSE_HEADER, '')
|
68
81
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
82
|
+
unless keep_alive?(data)
|
83
|
+
@buffer << unchunk(data)
|
84
|
+
|
85
|
+
if @buffer =~ EOF
|
86
|
+
lines = @buffer.split(CRLF)
|
87
|
+
@buffer = ''
|
88
|
+
else
|
89
|
+
lines = @buffer.split(CRLF)
|
90
|
+
@buffer = lines.pop
|
91
|
+
end
|
76
92
|
|
77
|
-
|
93
|
+
extract_json(lines).each {|line| callback(line)}
|
94
|
+
end
|
78
95
|
end
|
79
96
|
|
80
97
|
def unbind
|
@@ -82,5 +99,10 @@ module Hosebird
|
|
82
99
|
reconnect HOST, PORT
|
83
100
|
post_init
|
84
101
|
end
|
102
|
+
|
103
|
+
def unchunk(data)
|
104
|
+
data.gsub!(DECHUNKER, '')
|
105
|
+
data
|
106
|
+
end
|
85
107
|
end
|
86
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benburkert-hosebird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Burkert
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
version: "0"
|
64
64
|
version:
|
65
65
|
requirements:
|
66
|
-
- aikidoka
|
66
|
+
- flyingmachine-aikidoka
|
67
67
|
- eventmachine
|
68
68
|
- extlib
|
69
69
|
- json
|